UserStoreChangeDbconn.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MySystem.MainModels;
  5. namespace MySystem
  6. {
  7. public class UserStoreChangeDbconn
  8. {
  9. public readonly static UserStoreChangeDbconn Instance = new UserStoreChangeDbconn();
  10. #region 获取单个字段
  11. public UserStoreChange Get(int Id)
  12. {
  13. string key = "UserStoreChange:" + Id;
  14. if (RedisDbconn.Instance.Exists(key))
  15. {
  16. UserStoreChange obj = RedisDbconn.Instance.Get<UserStoreChange>(key);
  17. if (obj != null)
  18. {
  19. return obj;
  20. }
  21. }
  22. WebCMSEntities db = new WebCMSEntities();
  23. UserStoreChange orderPro = db.UserStoreChange.FirstOrDefault(m => m.Id == Id);
  24. if (orderPro != null)
  25. {
  26. RedisDbconn.Instance.Set(key, orderPro);
  27. RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(1800, 5400));
  28. }
  29. return orderPro;
  30. }
  31. #endregion
  32. #region 获取列表
  33. public List<UserStoreChange> GetList(int UserId, int BrandId, int pageNum = 1, int pageSize = 10)
  34. {
  35. string key = "UserStoreChangeList:" + UserId + ":" + BrandId;
  36. List<UserStoreChange> list = new List<UserStoreChange>();
  37. // if (RedisDbconn.Instance.Exists(key))
  38. // {
  39. // list = RedisDbconn.Instance.GetList<UserStoreChange>(key, pageNum, pageSize);
  40. // if (list.Count > 0)
  41. // {
  42. // return list;
  43. // }
  44. // }
  45. WebCMSEntities db = new WebCMSEntities();
  46. IQueryable<UserStoreChange> mysqllist = db.UserStoreChange.Where(m => m.UserId == UserId && m.BrandId == BrandId).OrderByDescending(m => m.Id);
  47. if (pageNum == 1)
  48. {
  49. mysqllist = mysqllist.Take(pageSize);
  50. }
  51. else
  52. {
  53. int skipNum = pageSize * (pageNum - 1);
  54. mysqllist = mysqllist.Skip(skipNum).Take(pageSize);
  55. }
  56. List<UserStoreChange> result = mysqllist.ToList();
  57. db.Dispose();
  58. return result;
  59. // if (mysqllist.Count > 0)
  60. // {
  61. // List<UserStoreChange> newlist = new List<UserStoreChange>();
  62. // foreach (UserStoreChange sub in mysqllist)
  63. // {
  64. // newlist.Add(sub);
  65. // }
  66. // RedisDbconn.Instance.Clear(key);
  67. // foreach (UserStoreChange sub in newlist)
  68. // {
  69. // RedisDbconn.Instance.AddRightList(key, sub);
  70. // }
  71. // RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(1800, 5400));
  72. // }
  73. // db.Dispose();
  74. // return list;
  75. }
  76. #endregion
  77. }
  78. }