public ActionResult Edit(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } var comment = this.Data.Comments.Find(id); if (comment == null) { return this.HttpNotFound(); } var model = new EditPostCommentInputModel { Id = comment.Id, BlogPostId = comment.PostId, UserId = comment.UserId, Content = comment.Content, CreatedOn = comment.CreatedOn }; return this.View(model); }
public ActionResult Edit(EditPostCommentInputModel commentInputModel) { if (this.ModelState.IsValid) { var comment = this.Data.Comments.Find(commentInputModel.Id); comment.Id = commentInputModel.Id; comment.PostId = commentInputModel.BlogPostId; comment.Content = commentInputModel.Content; comment.CreatedOn = commentInputModel.CreatedOn; comment.UserId = commentInputModel.UserId; comment.ModifiedOn = DateTime.Now; /*this.Data.PostComments.Update(postComment); this.Data.SaveChanges();*/ this.Data.Comments.Update(comment); this.Data.SaveChanges(); return this.RedirectToAction("Index"); } return this.View(commentInputModel); }