Пример #1
0
 // 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);
 }
Пример #2
0
        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 });
        }