public IActionResult Details(string year, string month, string slug)
        {
            var post = this.postRepository.GetByUrl(year, month, slug);

            if (null != post && post.IsPublished)
            {
                var viewModel = new DetailsPostViewModel(post);
                return(View(viewModel));
            }
            else
            {
                return(NotFound());
            }
        }
        public IActionResult Details(string year, string month, string slug, [Bind("NewComment")] DetailsPostViewModel viewModel)
        {
            var post       = this.postRepository.GetByUrl(year, month, slug);
            var newComment = viewModel.NewComment;

            if (null != post && post.IsPublished && null != newComment)
            {
                if (ModelState.IsValid)
                {
                    post.Comments.Add(newComment);
                    this.postRepository.SaveChanges();
                    return(RedirectToAction("Details", new { year = year, month = month, slug = slug }));
                }
            }
            return(View(viewModel));
        }
Esempio n. 3
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var postDetails = postManager.GetById((int)id);

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

            DetailsPostViewModel detailsPostViewModel = Mapper.Map <DetailsPostViewModel>(postDetails);

            return(View(detailsPostViewModel));
        }