示例#1
0
 public bool AddComment(Comment comment)
 {
     using (ModelSelfReference ctx = new ModelSelfReference())
     {
         bool bResult = false;
         if (comment == null || comment.PostPostId == Guid.Empty)
         {
             return(bResult);
         }
         if (comment.CommentId == Guid.Empty)
         {
             ctx.Entry <Comment>(comment).State = EntityState.Added;
             Post p = ctx.Posts.Find(comment.PostPostId);
             ctx.Entry <Post>(p).State = EntityState.Unchanged;
             ctx.SaveChanges();
             bResult = true;
         }
         return(bResult);
     }
 }
示例#2
0
 public bool AddPost(Post post)
 {
     using (ModelSelfReference ctx = new ModelSelfReference())
     {
         bool bResult = false;
         if (post.PostId == Guid.Empty)
         {
             var it = ctx.Entry <Post>(post).State = EntityState.Added;
             ctx.SaveChanges();
             bResult = true;
         }
         return(bResult);
     }
 }