public ActionResult Category(string blogName, string id, int page = 1) { if (blogName == null) { return(HttpNotFound()); } var blog = db.Blogs.FirstOrDefault(b => b.UrlName == blogName); if (blog == null) { return(HttpNotFound()); } var cat = db.PostCategories.FirstOrDefault(c => c.UrlSlug == id && c.BlogId == blog.Id); if (cat == null) { return(HttpNotFound()); } var posts = blog.Posts.Where(p => p.Published && p.Category.Id == cat.Id).OrderBy(p => p.PublishDate).ToPagedList(page, postsPerPage); var layoutSettings = blog.LayoutSettings; var viewModel = new DisplayBlog { Blog = blog, Posts = posts, LayoutSettings = layoutSettings }; ViewBag.Header = cat.Name + " posts"; ViewBag.Action = "/category/" + cat.UrlSlug; return(View("Default/Default", viewModel)); }
public ActionResult Display(string blogName, int page = 1) { var blog = db.Blogs.FirstOrDefault(b => b.UrlName == blogName); if (blog == null) { return(HttpNotFound()); } var posts = blog.Posts.Where(p => p.Published).OrderBy(p => p.PublishDate).ToPagedList(page, postsPerPage); var layoutSettings = blog.LayoutSettings; var viewModel = new DisplayBlog { Blog = blog, Posts = posts, LayoutSettings = layoutSettings }; //var posts = db.Posts.Where(p => p.Blog.Name == blogName && p.Published); _service.IncrementVisitCounter(HttpContext, blog.Id); return(View("Default/Default", viewModel)); }