Exemplo n.º 1
0
 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);
     }
 }
Exemplo n.º 2
0
 public Comment UpdateComment(Comment newComment)
 {
     using (ModelPostCommentContainer ctx = new ModelPostCommentContainer())
     {
         Comment oldComment = ctx.Comments.Find(newComment.CommentId);
         // Deoarece parametrul este un Comment ar trebui verificata fiecare
         // proprietate din newComment daca are valoare atribuita si
         // daca valoarea este diferita de cea din bd.
         // Acest lucru il fac numai la modificarea asocierii.
         if (newComment.Text != null)
         {
             oldComment.Text = newComment.Text;
         }
         if ((oldComment.PostPostId != newComment.PostPostId) &&
             (newComment.PostPostId != 0))
         {
             oldComment.PostPostId = newComment.PostPostId;
         }
         ctx.SaveChanges();
         return(oldComment);
     }
 }