Example #1
0
        public Comment UpdateComment(Comment newComment)
        {
            using (ModelPostCommentContainer ctx = new ModelPostCommentContainer())
            {
                Comment oldComment = ctx.Comments.Find(newComment.Id);

                // 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);
            }
        }
Example #2
0
 public void DeleteComment(Comment comm)
 {
     context.Comments.Remove(comm);
     foreach (var post in context.Posts.Where(p => p.Comments.Any(c => c.CommentId == comm.CommentId)).ToList())
     {
         post.Comments.Remove(comm);
     }
     context.SaveChanges();
 }
Example #3
0
 public void DeleteComment()
 {
     using (var ctx = new ModelPostCommentContainer())
     {
         ctx.Comments.Remove(this);
         ctx.SaveChanges();
     }
 }
Example #4
0
 public int DeletePost(int id)
 {
     using (ModelPostCommentContainer context = new ModelPostCommentContainer())
     {
         Post post = context.Posts.Find(id);
         context.Posts.Remove(post);
         context.SaveChanges();
         return(id);
     }
 }
Example #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);
     }
 }
Example #6
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);
     }
 }
Example #7
0
        public Post AddPost()
        {
            using (ModelPostCommentContainer ctx = new ModelPostCommentContainer())
            {
                if (PostId == 0)
                {
                    ctx.Entry <Post>(this).State = EntityState.Added;
                    ctx.SaveChanges();
                }

                return(this);
            }
        }
Example #8
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);
     }
 }
Example #9
0
 public Post UpdatePost(Post newPost)
 {
     using (ModelPostCommentContainer ctx = new ModelPostCommentContainer())
     {
         Post oldPost = ctx.Posts.Find(newPost.PostId);
         if (oldPost == null) // nu exista in bd
         {
             return(null);
         }
         oldPost.Description = newPost.Description;
         oldPost.Domain      = newPost.Domain;
         oldPost.Date        = newPost.Date;
         ctx.SaveChanges();
         return(oldPost);
     }
 }
Example #10
0
 public Comment UpdateComment(Comment newComment)
 {
     using (var 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);
     }
 }
Example #11
0
 public bool AddComment()
 {
     using (var ctx = new ModelPostCommentContainer())
     {
         if (PostPostId == Guid.Empty)
         {
             return(false);
         }
         if (CommentId == Guid.Empty)
         {
             return(false);
         }
         ctx.Entry(this).State = EntityState.Added;
         var p = ctx.Posts.Find(this.PostPostId);
         ctx.Entry(p).State = EntityState.Unchanged;
         ctx.SaveChanges();
         return(true);
     }
 }
Example #12
0
        public Comment UpdateOldCommentWithNewOne(Comment oldComment, Comment newComment)
        {
            using (ModelPostCommentContainer ctx = new ModelPostCommentContainer())
            {
                if (newComment.Text != null)
                {
                    oldComment.Text = newComment.Text;
                }

                if ((oldComment.PostPostId != newComment.PostPostId) && (newComment.PostPostId != 0))
                {
                    oldComment.PostPostId = newComment.PostPostId;
                }

                ctx.SaveChanges();

                return(oldComment);
            }
        }
Example #13
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);
     }
 }
Example #14
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);
     }
 }
Example #15
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);
            }
        }
Example #16
0
        public Comment UpdateComment(Comment newComment)
        {
            using (ModelPostCommentContainer context = new ModelPostCommentContainer())
            {
                Comment comment = context.Comments.Find(newComment.CommentId);

                if (newComment.Text != null)
                {
                    comment.Text = newComment.Text;
                }

                if ((comment.PostPostId != newComment.PostPostId) &&
                    (newComment.PostPostId != 0))
                {
                    comment.PostPostId = newComment.PostPostId;
                }
                context.SaveChanges();
                return(comment);
            }
        }
Example #17
0
 public Comment SubmitComment(Comment comment)
 {
     context.Comments.Add(comment);
     context.SaveChanges();
     return(comment);
 }