public ActionResult EditComment(Comment editComment) { var post = db.Posts.Find(editComment.PostId); if (ModelState.IsValid && Request.IsAuthenticated) { db.Comments.Attach(editComment); editComment.AuthorId = User.Identity.GetUserId(); editComment.Updated = System.DateTimeOffset.Now; db.Entry(editComment).Property(p => p.Body).IsModified = true; db.Entry(editComment).Property(p => p.AuthorId).IsModified = true; db.Entry(editComment).Property(p => p.Updated).IsModified = true; db.SaveChanges(); } return RedirectToAction("Details", new { slug = post.Slug }); }
public ActionResult CreateComment(Comment comment, string slug) { if (ModelState.IsValid) { comment.Created = System.DateTimeOffset.Now; comment.AuthorId = User.Identity.GetUserId(); db.Comments.Add(comment); db.SaveChanges(); } return RedirectToAction("Details", new { slug = slug }); }
public ActionResult DeleteComment(Comment comment) { Comment DeleteComment = db.Comments.Find(comment.Id); db.Comments.Remove(DeleteComment); db.SaveChanges(); var post = db.Posts.Find(comment.PostId); return RedirectToAction("Details", new { slug = post.Slug }); }