public void Add(Comment model) { dbContext.Comments.Add(model); var post = dbContext.Posts.Find(model.PostId); post.Comments.Add(model); dbContext.SaveChanges(); }
public static bool AddPost(Post post) { using (PostCommentContainer ctx = new PostCommentContainer()) { bool bResult = false; if (post.Id == 0) { var it = ctx.Entry <Post>(post).State = EntityState.Added; ctx.SaveChanges(); bResult = true; } return(bResult); } }
public static Post UpdatePost(Post newPost) { using (PostCommentContainer ctx = new PostCommentContainer()) { // Ce e in bd. PK nu poate fi modificata Post oldPost = ctx.PostSet.Find(newPost.Id); 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); } }
public static Comment UpdateComment(Comment newComment) { using (PostCommentContainer ctx = new PostCommentContainer()) { Comment oldComment = ctx.CommentSet.Find(newComment.Id); if (newComment.Text != null) { oldComment.Text = newComment.Text; } if ((oldComment.PostId != newComment.PostId) && (newComment.PostId != 0)) { oldComment.PostId = newComment.PostId; } ctx.SaveChanges(); return(oldComment); } }
// Comment table public static bool AddComment(Comment comment) { using (PostCommentContainer ctx = new PostCommentContainer()) { bool bResult = false; if (comment == null || comment.PostId == 0) { return(bResult); } if (comment.Id == 0) { ctx.Entry <Comment>(comment).State = EntityState.Added; Post p = ctx.PostSet.Find(comment.PostId); ctx.Entry <Post>(p).State = EntityState.Unchanged; ctx.SaveChanges(); bResult = true; } return(bResult); } }
public void Add(Comment model) { dbContext.Comments.Add(model); dbContext.SaveChanges(); }
public void Add(Post model) { dbContext.Posts.Add(model); dbContext.SaveChanges(); }