// GET: Blog public ActionResult Post(int id) { PostViewModel pVM = new PostViewModel(); pVM.Post = db.Posts.Find(id); pVM.NewComment = new Comment(); ViewBag.Title = pVM.Post.Title; return View(pVM); }
public ActionResult CreateComment(int postId, PostViewModel pVM) { if (!ModelState.IsValid) { TempData["message"] = string.Format("Nie udało się dodać komentarza, uzupełnij pola!"); return RedirectToAction("Post", new { id = postId }); } pVM.NewComment.CreateTime = DateTime.Now; pVM.NewComment.PostId = postId; db.Comments.Add(pVM.NewComment); db.SaveChanges(); TempData["message"] = string.Format("Dodano komentarz!"); return RedirectToAction("Post", new { id = postId }); }