MachineApplyDbconn.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. WebCMSEntities db = new WebCMSEntities();
  14. MachineApply apply = db.MachineApply.FirstOrDefault(m => m.Id == Id);
  15. if (apply != null)
  16. {
  17. }
  18. return apply;
  19. }
  20. #endregion
  21. #region 获取列表
  22. public List<int> GetList(int UserId, int pageNum = 1, int pageSize = 10)
  23. {
  24. // string key = "MachineApplyList:" + UserId;
  25. // List<int> list = new List<int>();
  26. // if (RedisDbconn.Instance.Exists(key))
  27. // {
  28. // list = RedisDbconn.Instance.GetList<int>(key, pageNum, pageSize);
  29. // if (list.Count > 0)
  30. // {
  31. // return list;
  32. // }
  33. // }
  34. List<int> newlist = new List<int>();
  35. WebCMSEntities db = new WebCMSEntities();
  36. var mysqllist = db.MachineApply.Select(m => new { m.Id, m.UserId }).Where(m => m.UserId == UserId).OrderByDescending(m => m.Id).ToList();
  37. if (mysqllist.Count > 0)
  38. {
  39. // RedisDbconn.Instance.Clear(key);
  40. foreach (var sub in mysqllist)
  41. {
  42. newlist.Add(sub.Id);
  43. // RedisDbconn.Instance.AddRightList(key, sub.Id);
  44. }
  45. // RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(1800, 5400));
  46. }
  47. db.Dispose();
  48. return newlist;
  49. }
  50. #endregion
  51. }
  52. }