public bool AddComment()
 {
     using (ModelPostCommentContainer ctx = new ModelPostCommentContainer())
     {
         bool bResult = false;
         if (this == null || this.PostPostId == 0)
         {
             return(bResult);
         }
         if (this.CommentId == 0)
         {
             ctx.Entry <Comment>(this).State = EntityState.Added;
             Post p = ctx.Posts.Find(this.PostPostId);
             ctx.Entry <Post>(p).State = EntityState.Unchanged;
             ctx.SaveChanges();
             bResult = true;
         }
         return(bResult);
     }
 }
Beispiel #2
0
        public bool AddCommentById(int postId, Comment comment)
        {
            using (ModelPostCommentContainer ctx = new ModelPostCommentContainer())
            {
                if (comment == null || postId == 0 || comment.Id != 0)
                {
                    return(false);
                }

                comment.PostPostId = postId;

                ctx.Entry(comment).State = EntityState.Added;

                Post p = ctx.Posts.Find(postId);
                ctx.Entry(p).State = EntityState.Unchanged;
                ctx.SaveChanges();

                return(true);
            }
        }
Beispiel #3
0
 public bool AddPost()
 {
     using (var ctx = new ModelPostCommentContainer())
     {
         if (PostId == Guid.Empty)
         {
             return(false);
         }
         ctx.Entry(this).State = EntityState.Added;
         ctx.SaveChanges();
         return(true);
     }
 }
Beispiel #4
0
        public Post AddPost()
        {
            using (ModelPostCommentContainer ctx = new ModelPostCommentContainer())
            {
                if (PostId == 0)
                {
                    ctx.Entry <Post>(this).State = EntityState.Added;
                    ctx.SaveChanges();
                }

                return(this);
            }
        }
Beispiel #5
0
 public bool AddPost()
 {
     using (ModelPostCommentContainer context = new ModelPostCommentContainer())
     {
         if (this.PostId == 0)
         {
             var it = context.Entry <Post>(this).State = EntityState.Added;
             context.SaveChanges();
             return(true);
         }
         return(false);
     }
 }
Beispiel #6
0
 public bool AddPost()
 {
     using (ModelPostCommentContainer ctx = new ModelPostCommentContainer())
     {
         bool bResult = false;
         if (this.PostId == 0)
         {
             var it = ctx.Entry <Post>(this).State = EntityState.Added;
             ctx.SaveChanges();
             bResult = true;
         }
         return(bResult);
     }
 }