public IActionResult DisplayPost(int blogId) { BlogDb db = new BlogDb(); BlogPost blogpost = db.GetPostToDisplay(blogId); if (blogpost.BlogText == null) { return(Redirect("/home/index")); //if either '0', or an id that doesn't exist was sent it, redirects } DisplayPostViewModel vm = new DisplayPostViewModel(); vm.BlogPost = blogpost; vm.CommenterName = Request.Cookies["commenterName"]; return(View(vm)); }
public IActionResult BlogPost(string link) { try { var post = _blogService.GetBlogPostByLink(link); if (post != null) { var model = new DisplayPostViewModel() { BlogPost = post, PostCategoryName = _blogService.GetBlogPostCategoryById(post.PostCategoryId).Name, RecentPosts = _blogService.GetBlogPosts(mostRecentCount: 3).ToList(), Categories = _blogService.GetBlogPostCategories(includePosts: true).OrderByDescending(b => b.Posts.Count).Take(5).ToList() }; return(View(model)); } } catch (Exception ex) { _logService.InsertLog(LogLevel.Error, "Unable to load blog post. " + ex.Message, ex.ToString()); } return(RedirectToAction("index", "home")); }