// 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 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); } }