Exemple #1
0
 public Comment UpdateComment(Comment newComment)
 {
     using (ModelPostCommentContainer ctx = new ModelPostCommentContainer())
     {
         Comment oldComment = ctx.Comments.Find(newComment.CommentId);
         if (newComment.Text != null)
         {
             oldComment.Text = newComment.Text;
         }
         if ((oldComment.PostPostId != newComment.PostPostId) && (newComment.PostPostId != 0))
         {
             oldComment.PostPostId = newComment.PostPostId;
         }
         ctx.SaveChanges();
         return(oldComment);
     }
 }
Exemple #2
0
 public bool AddComment()
 {
     using (ModelPostCommentContainer context = new ModelPostCommentContainer())
     {
         if (this == null || this.PostPostId == 0)
         {
             return(false);
         }
         if (this.CommentId == 0)
         {
             context.Entry <Comment>(this).State = EntityState.Added;
             Post p = context.Posts.Find(this.PostPostId);
             context.Entry <Post>(p).State = EntityState.Unchanged;
             context.SaveChanges();
             return(true);
         }
         return(false);
     }
 }