Example #1
0
 public ActionResult Details(int year, int month, int day, string path)
 {
     // Grab blog post from db
     BlogPost blogPost = BlogPostRepo.GetByPath(year, month, day, path);
     // The url is canonical because path is a UK in the database and we
     // use year, month, and day in the query
     BlogPostDetailModel blogPostDetailModel = new BlogPostDetailModel()
                                                   {
                                                       BlogPost = blogPost,
                                                       RelatedBlogPosts =
                                                           _blogPostRepo.GetListOfRelatedBlogPosts(
                                                               blogPost,
                                                               NUMBER_OF_RELATED_POSTS),
                                                       NewComment = new Comment()
                                                   };
     return View(blogPostDetailModel);
 }
Example #2
0
 public ActionResult Details(int year, int month, int day, string path,[Bind(Exclude="CommentID")] Comment comment)
 {
     // grab blogPost from context
     BlogPost blogPost = BlogPostRepo.GetByPath(year, month, day, path);
     // Create new blogPostDetailModel
     BlogPostDetailModel blogPostDetailModel;
     // grab related posts
     var relatedBlogPosts = BlogPostRepo.GetListOfRelatedBlogPosts(blogPost, NUMBER_OF_RELATED_POSTS);
     // check validation
     if (!ModelState.IsValid)
     {
         blogPostDetailModel = new BlogPostDetailModel
                                   {
                                       BlogPost = blogPost,
                                       NewComment = comment,
                                       RelatedBlogPosts = relatedBlogPosts
                                   };
         return View(blogPostDetailModel);
     }
     // if model is valid then add comment
     BlogPostRepo.AddCommentToBlogPost(blogPost, comment);
     // BlogPostRepo.SubmitChanges();
     return RedirectToAction("Details", blogPost.GetBlogDetails());
 }