public bool CheckUserEmail(string email) { using (MVCBlogContext Context = new MVCBlogContext()) { return(Context.UserInfo.Any(x => x.Email == email)); } }
public Pagination <T> Query(int index, int pagecount, Expression <Func <T, bool> > query) { using (MVCBlogContext Context = new MVCBlogContext()) { var ids = query != null?Context.Set <T>().Where(query).OrderByDescending(x => x.Id).Select(x => x.Id).ToPagedList(index, pagecount) : Context.Set <T>().OrderByDescending(x => x.Id).Select(x => x.Id).ToPagedList(index, pagecount); if (ids != null && ids.Count > 0) { Pagination <T> pagination = new Pagination <T>() { Items = GetByIds(ids), TotalItemCount = ids.TotalItemCount, PageCount = ids.PageCount, PageNumber = ids.PageNumber, PageSize = ids.PageSize }; return(pagination); } else { return(new Pagination <T>() { Items = null, TotalItemCount = 0, PageCount = 0, PageNumber = index, PageSize = pagecount }); } } }
public UserInfo GetUserInfo(string email) { using (MVCBlogContext Context = new MVCBlogContext()) { return(Context.UserInfo.Single(x => x.Email == email)); } }
public async Task <List <PostInfo> > GetRecentPostAsync(int count) { using (MVCBlogContext Context = new MVCBlogContext()) { Func <List <int> > GetIds = () => { return(Context.PostInfo.OrderByDescending(x => x.Id).Take(count).Select(x => x.Id).ToList()); }; //var res = Context.PostInfo.OrderByDescending(x => x.Id).Take(count).Select(x => x.Id).ToList(); var res = await GetIds.StartAsync <List <int> >(); if (res != null && res.Count > 0) { List <PostInfo> list = new List <PostInfo>(); foreach (var item in res) { string key = RedisKeyHelper.GetPostKey(item); Func <PostInfo> GetDb = () => GetFromDB(item); PostInfo info = RedisHelper.GetEntity <PostInfo>(key, GetDb); list.Add(info); } return(list); } return(new List <PostInfo>()); } }
public IEnumerable <DateTime> GetPostMonthInfos() { using (MVCBlogContext Context = new MVCBlogContext()) { var datetimes = Context.PostInfo.Select(x => x.CreateTime).ToList(); return(datetimes); } }
//private MVCBlogContext Context; //public PostMetaService(MVCBlogContext _context) //{ // this.Context = _context; //} public override void Delete(PostMetasInfo model) { using (MVCBlogContext Context = new MVCBlogContext()) { model.IsDelete = true; Context.SaveChanges(); } }
public override void Update(PostMetasInfo model) { using (MVCBlogContext Context = new MVCBlogContext()) { var entity = Context.PostMetasInfo.Find(model.Id); entity.Name = model.Name; Context.SaveChanges(); } }
public override void Delete(UserInfo model) { using (MVCBlogContext Context = new MVCBlogContext()) { var entity = Context.UserInfo.Find(model.Id); entity.IsDelete = true; Context.SaveChanges(); base.Delete(model); } }
//public override async Task<CategoryInfo> GetByIdAsync(int id) //{ // Func<CategoryInfo> getitem = () => // { // var list = RedisHelper.GetEntity<List<CategoryInfo>>(RedisKeyHelper.GetCategoryKey(id)); // if (list != null) // { // return list.Find(x => x.Id == id); // } // return Context.CategoryInfo.Find(id); // }; // return await Common.TaskExtensions.WithCurrentCulture<CategoryInfo>(getitem); //} public override void Insert(CategoryInfo model, int userid = 0) { using (MVCBlogContext Context = new MVCBlogContext()) { model.CreateUser = Context.UserInfo.Find(userid == 0 ? model.CreateUser.Id : userid); Context.CategoryInfo.Add(model); Context.SaveChanges(); base.Insert(model, userid); } }
//public override IEnumerable<CommentInfo> Query(Expression<Func<CommentInfo, bool>> query = null) //{ // var ids = query != null ? Context.CommentInfo.Where(query).OrderByDescending(x => x.Id).Select(x => x.Id).ToList() : Context.CommentInfo.OrderByDescending(x => x.Id).Select(x => x.Id).ToList(); // if (ids != null && ids.Count > 0) // { // return GetByIds(ids); // } // else // { // return new List<CommentInfo>(); // } //} //public override Pagination<CommentInfo> Query(int index, int pagecount, Expression<Func<CommentInfo, bool>> query = null) //{ // var ids = query != null ? Context.CommentInfo.Where(query).OrderByDescending(x => x.Id).Select(x => x.Id).ToPagedList(index, pagecount) : Context.CommentInfo.OrderByDescending(x => x.Id).Select(x => x.Id).ToPagedList(index, pagecount); // if (ids != null && ids.Count() > 0) // { // Pagination<CommentInfo> pagination = new Pagination<CommentInfo>() // { // Items = GetByIds(ids), // TotalItemCount = ids.TotalItemCount, // PageCount = ids.PageCount, // PageNumber = ids.PageNumber, // PageSize = ids.PageSize // }; // return pagination; // } // else // { // return new Pagination<CommentInfo>() // { // Items = null, // TotalItemCount = 0, // PageCount = 0, // PageNumber = index, // PageSize = pagecount // }; // } //} public override void Update(CommentInfo model) { using (MVCBlogContext Context = new MVCBlogContext()) { var entity = Context.CommentInfo.Find(model.Id); entity.CommentContent = model.CommentContent; Context.SaveChanges(); base.Update(model); } }
public override void Insert(CommentInfo model, int userid = 0) { using (MVCBlogContext Context = new MVCBlogContext()) { model.CommentUser = Context.UserInfo.Find(model.CommentUser.Id); Context.CommentInfo.Add(model); Context.SaveChanges(); base.Insert(model, userid); } }
public async Task <UserInfo> GetUserInfoAsync(string email) { using (MVCBlogContext Context = new MVCBlogContext()) { return(await Common.ThreadHelper.StartAsync <UserInfo>(() => { return Context.UserInfo.Single(x => x.Email == email); })); } }
public override async Task DeleteAsync(CommentInfo model) { using (MVCBlogContext Context = new MVCBlogContext()) { var entity = Context.CommentInfo.Find(model.Id); entity.IsDelete = true; await Context.SaveChangesAsync(); await base.DeleteAsync(model); } }
public override async Task InsertAsync(CategoryInfo model, int userid) { using (MVCBlogContext Context = new MVCBlogContext()) { model.CreateUser = Context.UserInfo.Find(userid == 0 ? model.CreateUser.Id : userid); Context.CategoryInfo.Add(model); await Context.SaveChangesAsync(); await base.InsertAsync(model, userid); } }
public void Update(IEnumerable <PostMetasInfo> infos, int postid) { using (MVCBlogContext Context = new MVCBlogContext()) { if (infos != null && infos.Count() > 0) { var relations = Context.PostMetaRelation.Where(x => x.PostId == postid).ToList(); foreach (PostMetasInfo info in infos) { if (info.Id != 0) { var exists = relations.FirstOrDefault(x => x.PostMetaId == info.Id); if (exists != null) { exists.IsDelete = false; } else { exists = new PostMetaRelation() { PostId = postid, PostMetaId = info.Id }; Context.PostMetaRelation.Add(exists); } Update(info); } else { var add = new PostMetasInfo() { Name = info.Name }; add = Context.PostMetasInfo.Add(add); Context.SaveChanges(); var relation = new PostMetaRelation() { PostId = postid, PostMetaId = add.Id }; Context.PostMetaRelation.Add(relation); } } var ids = infos.Select(s => s.Id); var removes = Context.PostMetaRelation.Where(x => x.PostId == postid && !ids.Contains(x.PostMetaId)).ToList(); foreach (var item in removes) { item.IsDelete = true; } Context.SaveChanges(); } } }
public override async Task InsertAsync(CommentInfo model, int userid = 0) { using (MVCBlogContext Context = new MVCBlogContext()) { model.CommentUser = await Context.UserInfo.FindAsync(userid); Context.CommentInfo.Add(model); await Context.SaveChangesAsync(); await base.InsertAsync(model, userid); } }
public override async Task UpdateAsync(CommentInfo model) { using (MVCBlogContext Context = new MVCBlogContext()) { var entity = await Context.CommentInfo.FindAsync(model.Id); entity.CommentContent = model.CommentContent; await Context.SaveChangesAsync(); await base.UpdateAsync(model); } }
public override void Update(CategoryInfo model) { using (MVCBlogContext Context = new MVCBlogContext()) { var entity = Context.CategoryInfo.Find(model.Id); if (entity != null) { entity.CategoryName = model.CategoryName; entity.IsDelete = model.IsDelete; Context.SaveChanges(); base.Update(model); } } }
//private MVCBlogContext Context; //public PostService(MVCBlogContext _context) //{ // this.Context = _context; //} public override void Delete(PostInfo model) { using (MVCBlogContext Context = new MVCBlogContext()) { if (model != null) { var entity = Context.PostInfo.Find(model.Id); entity.IsDelete = true; entity.PostStatus = PostStatus.除; Context.SaveChanges(); base.Delete(model); } } }
public override async Task UpdateAsync(CategoryInfo model) { using (MVCBlogContext Context = new MVCBlogContext()) { var entity = Context.CategoryInfo.Find(model.Id); if (entity != null) { entity.CategoryName = model.CategoryName; entity.IsDelete = model.IsDelete; await Context.SaveChangesAsync(); await base.UpdateAsync(model); } } }
public override async Task DeleteAsync(PostInfo model) { using (MVCBlogContext Context = new MVCBlogContext()) { if (model != null) { var entity = Context.PostInfo.Find(model.Id); entity.IsDelete = true; entity.PostStatus = PostStatus.除; await Context.SaveChangesAsync(); await base.DeleteAsync(model); } } }
public override void Insert(UserInfo user, int userid = 0) { using (MVCBlogContext Context = new MVCBlogContext()) { user.Password = AesSecret.EncryptStringToAES(user.Password); user.CreateTime = DateTime.Now; user.EditedTime = DateTime.Now; user.UserStatus = UserStatus.正常; user.UserRole = UserRole.读者; user.IsDelete = false; user = Context.UserInfo.Add(user); Context.SaveChanges(); base.Insert(user, userid); } }
public void SetPostMetaInfo(PostInfo info) { using (MVCBlogContext Context = new MVCBlogContext()) { if (info != null) { var metarelations = Context.PostMetaRelation.Where(x => x.PostId == info.Id && !x.IsDelete).ToList(); if (metarelations.Count > 0) { var metaids = metarelations.Select(x => x.PostMetaId); var metas = new PostMetaService().Query(x => metaids.Contains(x.Id) && !x.IsDelete); info.PostMetasInfos = metas; } } } }
public IEnumerable <T> Query(Expression <Func <T, bool> > query) { using (MVCBlogContext Context = new MVCBlogContext()) { var ids = query != null?Context.Set <T>().Where(query).OrderByDescending(x => x.Id).Select(x => x.Id).ToList() : Context.Set <T>().OrderByDescending(x => x.Id).Select(x => x.Id).ToList(); if (ids != null && ids.Count > 0) { return(GetByIds(ids)); } else { return(new List <T>()); } } }
public UserInfo ValidateUser(string email, string password) { using (MVCBlogContext Context = new MVCBlogContext()) { string encryptPassword = AesSecret.EncryptStringToAES(password); var entity = Context.UserInfo.FirstOrDefault(x => x.Email == email && x.Password == encryptPassword); if (entity != null) { entity.LastLoginTime = DateTime.Now; Context.SaveChanges(); entity = Context.UserInfo.Find(entity.Id); return(entity); } return(null); } }
public UserInfo GetUserInfoByUid(string uid, OAuthSystemType systemtype) { using (MVCBlogContext Context = new MVCBlogContext()) { switch (systemtype) { case OAuthSystemType.QQ: return(Context.UserInfo.FirstOrDefault(x => x.QQUid == uid)); case OAuthSystemType.Weibo: return(Context.UserInfo.FirstOrDefault(x => x.WeiBoUid == uid)); default: return(null); } } }
public override void Update(PostInfo model) { using (MVCBlogContext Context = new MVCBlogContext()) { var entity = Context.PostInfo.Find(model.Id); entity.CommentCount = model.CommentCount; entity.Title = model.Title; entity.Content = model.Content; entity.PostStatus = model.PostStatus; entity.PostCommentStatus = model.PostCommentStatus; entity.EditedTime = DateTime.Now; entity.PostCategoryInfo = Context.CategoryInfo.Find(entity.PostCategoryInfo.Id); Context.SaveChanges(); IPostMetaService metaservice = new PostMetaService(); metaservice.Update(model.PostMetasInfos, model.Id); base.Update(model); } }
public override async Task InsertAsync(PostInfo model, int userid) { using (MVCBlogContext Context = new MVCBlogContext()) { model.PostStatus = PostStatus.发布; model.PostType = PostType.文章; model.PostCommentStatus = PostCommentStatus.打开; model.CommentCount = 0; model.CreateTime = DateTime.Now; model.IsDelete = false; model.PostAuthor = Context.UserInfo.Find(userid); model.PostCategoryInfo = Context.CategoryInfo.Find(model.PostCategoryInfo.Id); var entity = Context.PostInfo.Add(model); Context.SaveChanges(); PostMetaService metaservice = new PostMetaService(); metaservice.Insert(model.PostMetasInfos, entity.Id); await base.InsertAsync(model, userid); } }
public async Task <UserInfo> ValidateUserAsync(string email, string password) { using (MVCBlogContext Context = new MVCBlogContext()) { string encryptPassword = AesSecret.EncryptStringToAES(password); Func <UserInfo> finditem = () => Context.UserInfo.FirstOrDefault(x => x.Email == email && x.Password == encryptPassword); var entity = await Common.ThreadHelper.StartAsync <UserInfo>(finditem); if (entity != null) { entity.LastLoginTime = DateTime.Now; await Context.SaveChangesAsync(); entity = await Context.UserInfo.FindAsync(entity.Id); return(entity); } return(null); } }
public void Insert(IEnumerable <PostMetasInfo> infos, int postid) { using (MVCBlogContext Context = new MVCBlogContext()) { //throw new NotImplementedException(); if (infos != null) { foreach (PostMetasInfo info in infos) { if (info.Id != 0) { var relation = Context.PostMetaRelation.FirstOrDefault(x => x.PostId == postid && x.PostMetaId == info.Id); if (relation != null) { relation.IsDelete = false; } else { relation = new PostMetaRelation() { PostId = postid, PostMetaId = info.Id }; Context.PostMetaRelation.Add(relation); } } else { var entity = Context.PostMetasInfo.Add(info); Context.SaveChanges(); var relation = new PostMetaRelation() { PostId = postid, PostMetaId = entity.Id }; Context.PostMetaRelation.Add(relation); } } Context.SaveChanges(); } } }