public bool AddComment() { using (ModelPostEntities ctx = new ModelPostEntities()) { bool bResult = false; if (this == null || this.PostPostId1 == 0) { return(bResult); } if (this.CommentId == 0) { ctx.Entry <Comment>(this).State = EntityState.Added; Post p = ctx.Posts.Find(this.PostPostId1); ctx.Entry <Post>(p).State = EntityState.Unchanged; ctx.SaveChanges(); bResult = true; } return(bResult); } }
public bool AddPost() { using (var context = new ModelPostEntities()) { var bResult = false; if (this.PostId == 0) { var it = context.Entry <Post>(this).State = EntityState.Added; context.SaveChanges(); bResult = true; } return(bResult); } }