public static MemberModel Get(int id, string mobilePhone) { using (var pointContext = new PointContexts()) { return(pointContext.Members.FirstOrDefault(m => m.Id == id && m.MobilePhone == mobilePhone && m.Status == MemberStatus.Normal)); } }
public static OrderModel Get(string orderNo) { using (var pointContext = new PointContexts()) { return(pointContext.Orders.FirstOrDefault(m => m.OrderNo == orderNo)); } }
public static bool?Exists(string mobilePhone) { using (var context = new PointContexts()) { return(context.Members.Any(m => m.MobilePhone == mobilePhone)); } }
public static NewsModel Get(int id) { using (var context = new PointContexts()) { return(context.News.FirstOrDefault(m => m.Id == id)); } }
public static bool?Exists(string keyName, int id = 0) { using (var context = new PointContexts()) { return(context.SysConfigs.Any(m => id == 0 && m.KeyName == keyName || m.Id != id && m.KeyName == keyName)); } }
public static ShopCouponCardModel Get(int id) { using (var pointContext = new PointContexts()) { return(pointContext.ShopCouponCards.FirstOrDefault(m => m.Id == id)); } }
public static SysConfigModel GetDictionaryConfig(string keyName) { using (var context = new PointContexts()) { return(context.SysConfigs.FirstOrDefault(m => m.KeyName == keyName && m.IsActive)); } }
public static void GetList(QueryBase <MemberFundingModel> entity) { using (var context = new PointContexts()) { entity.DataList = context.MemberFundings.Where(m => m.UserId == entity.UserId).OrderBy(m => m.Id).Skip(entity.PageSize * (entity.PageIndex - 1)).Take(entity.PageSize).ToList(); } }
public static List <NewsModel> GetList(List <int> ids) { using (var context = new PointContexts()) { return(context.News.Where(m => ids.Contains(m.Id)).ToList()); } }
public static bool Exists(int newsId, int userId) { using (var context = new PointContexts()) { return(context.QuestionFeedbacks.Any(m => m.NewsId == newsId && m.UserId == userId)); } }
public static MemberModel Get(string mobilePhone, string encryptedPwd) { using (var pointContext = new PointContexts()) { return(pointContext.Members.FirstOrDefault(m => m.MobilePhone == mobilePhone && m.EncryptedPwd == encryptedPwd && m.Status == MemberStatus.Normal)); } }
public static List <QuestionModel> GetList(int newsId) { using (var context = new PointContexts()) { return(context.Questions.Where(m => m.NewsId == newsId).ToList()); } }
public static int Count(int userId, int newId) { using (var context = new PointContexts()) { var query = context.Favorites.Count(m => m.UserId == userId && m.NewsId == newId); return(query); } }
public static void GetShopList(ShopRequest entity) { using (var context = new PointContexts()) { var query = context.Shops.Where(m => m.Category == entity.Category); entity.DataList = query.Skip(entity.PageSize * (entity.PageIndex - 1)).Take(entity.PageSize).ToList(); } }
public static bool Add(SysConfigModel entity) { using (var context = new PointContexts()) { context.SysConfigs.Add(entity); return(context.SaveChanges() >= 1); } }
public static bool Update(SysConfigModel entity) { const string sqlQuery = @"UPDATE [dbo].[DictionaryConfig] SET GroupName={0},KeyName={1},Value={2},Description={3},Expand={4},TypeId={5},OwnerName={6},LastOpUserId={7},UpdateTime={8} WHERE Id={9}"; using (var context = new PointContexts()) { return(context.Database.ExecuteSqlCommand(sqlQuery, entity.GroupName, entity.KeyName, entity.Value, entity.Description, entity.Expand, entity.TypeId, entity.OwnerName, entity.LastOpUserId, entity.UpdateTime, entity.Id) > 0); } }
public static bool DeleteEntity(T entity) { using (var pointContext = new PointContexts()) { pointContext.Set <T>().Attach(entity); pointContext.Entry <T>(entity).State = EntityState.Deleted; return(pointContext.SaveChanges() > 0); } }
public static List <MemberFeedModel> GetMemberFeedList(int memberId, int pageIndex, int pageSize = 10) { const string sqlQuery = @"SELECT * FROM [dbo].[MemberFeed] WITH(NOLOCK) WHERE UserId = {0}"; using (var context = new PointContexts()) { var query = context.Database.SqlQuery <MemberFeedModel>(sqlQuery, memberId); return(query.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList()); } }
public static void GetHomeFeedList(QueryBase <NewsModel> entity) { const string sqlQuery = @"SELECT A.* FROM [dbo].[News] AS A WITH(NOLOCK) JOIN [dbo].[HomeFeed] AS B WITH(NOLOCK) ON A.Id = B.NewsId WHERE B.UserId = {0} "; using (var context = new PointContexts()) { var query = context.Database.SqlQuery <NewsModel>(sqlQuery, entity.UserId); entity.DataList = query.Skip(entity.PageSize * (entity.PageIndex - 1)).Take(entity.PageSize).ToList(); } }
protected static T AddEntity(T entity) { using (var pointContext = new PointContexts()) { pointContext.Entry(entity).State = EntityState.Added; //下面的写法统一 pointContext.SaveChanges(); return(entity); } }
public static MemberModel Get(int id) { if (id <= 0) { return(null); } using (var pointContext = new PointContexts()) { return(pointContext.Members.FirstOrDefault(m => m.Id == id && m.Status == MemberStatus.Normal)); } }
protected static bool UpdateEntity(T entity) { //EF4.0的写法 //Db.CreateObjectSet<T>().Addach(entity); //Db.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified); //EF5.0的写法 using (var pointContext = new PointContexts()) { pointContext.Set <T>().Attach(entity); pointContext.Entry <T>(entity).State = EntityState.Modified; return(pointContext.SaveChanges() > 0); } }
public static SmsModel Get(string mobilePhone, byte smsType, int smsCode) { using (var context = new PointContexts()) { return(context.Sms.OrderByDescending(m => m.Id).FirstOrDefault ( m => m.MobilePhone == mobilePhone && m.SmsType == smsType && m.SmsCode == smsCode )); } }
public static List <SysConfigModel> GetList(int typeId, string search) { string sqlQuery = @"SELECT * FROM [dbo].[DictionaryConfig] WITH(NOLOCK) WHERE IsActive=1 "; if (typeId >= 0) { sqlQuery += string.Format(" AND TypeId = {0}", typeId); } if (!string.IsNullOrEmpty(search)) { sqlQuery += String.Format(" AND ( GroupName LIKE '%{0}%' OR KeyName LIKE '%{0}%' OR [Value] LIKE '%{0}%' OR [Description] LIKE '%{0}%' OR OwnerName LIKE '%{0}%')", search); } sqlQuery += " ORDER BY ID DESC"; using (var context = new PointContexts()) { return(context.Database.SqlQuery <SysConfigModel>(sqlQuery, typeId).ToList()); } }