Beispiel #1
0
 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;
             }
         }
     }
 }
Beispiel #2
0
 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);
     }
 }
Beispiel #3
0
        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);
            }
        }