UserAddressDbconn.cs 2.5 KB

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