AdvertismentDbconn.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MySystem.Models;
  5. namespace MySystem
  6. {
  7. public class AdvertismentDbconn
  8. {
  9. public readonly static AdvertismentDbconn Instance = new AdvertismentDbconn();
  10. #region 获取列表
  11. public List<Advertisment> GetList(string ColId)
  12. {
  13. string key = "AdvertismentList:" + ColId;
  14. List<Advertisment> list = new List<Advertisment>();
  15. if (RedisDbconn.Instance.Exists(key))
  16. {
  17. list = RedisDbconn.Instance.GetList<Advertisment>(key);
  18. if (list.Count > 0)
  19. {
  20. return list;
  21. }
  22. }
  23. List<Advertisment> newlist = new List<Advertisment>();
  24. WebCMSEntities db = new WebCMSEntities();
  25. var mysqllist = db.Advertisment.Where(m => m.ColId == ColId).OrderByDescending(m => m.Sort).OrderByDescending(m => m.Id).ToList();
  26. if (mysqllist.Count > 0)
  27. {
  28. foreach (var sub in mysqllist)
  29. {
  30. newlist.Add(sub);
  31. }
  32. RedisDbconn.Instance.Clear(key);
  33. foreach (Advertisment sub in newlist)
  34. {
  35. RedisDbconn.Instance.AddRightList(key, sub);
  36. }
  37. }
  38. db.Dispose();
  39. return newlist;
  40. }
  41. #endregion
  42. }
  43. }