public static 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); } }
public static 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); } }
}// Comment table public static bool AddComment(Comment comment) { using (ModelPostCommentContainer ctx = new ModelPostCommentContainer()) { bool bResult = false; if (comment == null || comment.PostPostId == 0) { return(bResult); } if (comment.CommentId == 0) { ctx.Entry <Comment>(comment).State = EntityState.Added; Post p = ctx.Posts.Find(comment.PostPostId); ctx.Entry <Post>(p).State = EntityState.Unchanged; ctx.SaveChanges(); bResult = true; } return(bResult); } }
// Comment table public static bool AddComment(Comment comment) { using (var ctx = new ModelPostCommentContainer()) { if (comment == null || comment.PostPostId == Guid.Empty) { return(false); } if (comment.CommentId != Guid.Empty) { return(false); } ctx.Entry <Comment>(comment).State = EntityState.Added; var p = ctx.Posts.Find(comment.PostPostId); ctx.Entry <Post>(p).State = EntityState.Unchanged; ctx.SaveChanges(); return(true); } }
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.PostPostId1) && (newComment.PostPostId != 0)) { oldComment.PostPostId = newComment.PostPostId; } ctx.SaveChanges(); return(oldComment); } }
public ServicePost() { context = new ModelPostCommentContainer(); }
public static int DeletePost(int id) { using (ModelPostCommentContainer ctx = new ModelPostCommentContainer()){ return(ctx.Database.ExecuteSqlCommand("Delete From Post where postid =@p0", id)); } }