MachineApplyDbconn.cs 2.4 KB

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