Exemplo n.º 1
0
        public ActionResult Comment(int id, [Bind(Include = "name,email,content")] Comment comment)
        {
            var post = db.Posts.Find(id);

            if (post == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (ModelState.IsValid)
            {
                comment.post_id    = id;
                comment.created_at = DateTime.Now;
                comment.updated_at = DateTime.Now;
                db.Comments.Add(comment);
                db.SaveChanges();
                return(RedirectToAction("Details", new { id = comment.post_id }));
            }

            PostsDetailsViewModel viewModel = new PostsDetailsViewModel();

            viewModel.post    = post;
            viewModel.comment = comment;
            return(View("Details", viewModel));
        }
Exemplo n.º 2
0
        // GET: Posts/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Post post = db.Posts.Find(id);

            if (post == null)
            {
                return(HttpNotFound());
            }

            PostsDetailsViewModel viewModel = new PostsDetailsViewModel();

            viewModel.post    = post;
            viewModel.comment = new Comment();
            return(View(viewModel));
        }