using System; using System.Collections.Generic; using System.Linq; using MySystem.MainModels; namespace MySystem { public class UserStoreChangeDbconn { public readonly static UserStoreChangeDbconn Instance = new UserStoreChangeDbconn(); #region 获取单个字段 public UserStoreChange Get(int Id) { string key = "UserStoreChange:" + Id; if (RedisDbconn.Instance.Exists(key)) { UserStoreChange obj = RedisDbconn.Instance.Get(key); if (obj != null) { return obj; } } WebCMSEntities db = new WebCMSEntities(); UserStoreChange orderPro = db.UserStoreChange.FirstOrDefault(m => m.Id == Id); if (orderPro != null) { RedisDbconn.Instance.Set(key, orderPro); RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(1800, 5400)); } return orderPro; } #endregion #region 获取列表 public List GetList(int UserId, int BrandId, int pageNum = 1, int pageSize = 10) { string key = "UserStoreChangeList:" + UserId + ":" + BrandId; List list = new List(); // if (RedisDbconn.Instance.Exists(key)) // { // list = RedisDbconn.Instance.GetList(key, pageNum, pageSize); // if (list.Count > 0) // { // return list; // } // } WebCMSEntities db = new WebCMSEntities(); IQueryable mysqllist = db.UserStoreChange.Where(m => m.UserId == UserId && m.BrandId == BrandId).OrderByDescending(m => m.Id); if (pageNum == 1) { mysqllist = mysqllist.Take(pageSize); } else { int skipNum = pageSize * (pageNum - 1); mysqllist = mysqllist.Skip(skipNum).Take(pageSize); } List result = mysqllist.ToList(); db.Dispose(); return result; // if (mysqllist.Count > 0) // { // List newlist = new List(); // foreach (UserStoreChange sub in mysqllist) // { // newlist.Add(sub); // } // RedisDbconn.Instance.Clear(key); // foreach (UserStoreChange sub in newlist) // { // RedisDbconn.Instance.AddRightList(key, sub); // } // RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(1800, 5400)); // } // db.Dispose(); // return list; } #endregion } }