public TagSingleViewModel LoadBlogsByTag(String tag) { var model = new TagSingleViewModel { TheTag = tag, BlogRoll = _context.Blogs.Where(x => x.Tags.Any(tg => tg.BlogTagName == tag) && x.IsActive).OrderByDescending(x => x.Date).ToList() }; model.UserNameToDisplayName = UserUtils.GetUsernamesForBlogs(model.BlogRoll, _context); model.Categories = new List <BlogsCategoriesViewModel.BlogCatExtraData>(); var cats = _context.BlogCategories.Where(x => x.IsActive).ToList(); foreach (var cat in cats) { int count = _context.Blogs.Count(x => x.Category.CategoryId == cat.CategoryId); model.Categories.Add(new BlogsCategoriesViewModel.BlogCatExtraData() { TheCategory = cat, BlogCount = count }); } return(model); }
/// <summary> /// If no title or category, could be just listing page. /// If no title, but category is set, probably a category listing page /// If title and category are set, individual blog. /// </summary> /// <param name="title"></param> /// <param name="category"></param> /// <param name="date"></param> /// <returns>View</returns> public ActionResult Index(string title, string category, string date) { // Blog Listing Homepage if (String.IsNullOrEmpty(title) && String.IsNullOrEmpty(category)) { var model = new BlogHomeViewModel(date); return(View("~/Views/Home/Blog.cshtml", model)); } // Category if (String.IsNullOrEmpty(title)) { // Category var cats = Context.BlogCategories.ToList().Select(x => ContentUtils.GetFormattedUrl(x.CategoryName)); if (cats.Contains(category)) { var model = new CategorySingleViewModel(category, Server); return(View("~/Views/Blog/CategoriesSingle.cshtml", model)); } // Not a blog category or tags page HttpContext.Response.StatusCode = 404; return(View("~/Views/Home/Error404.cshtml")); } // Tag if (category == "tags" && !string.IsNullOrEmpty(title)) { var model = new TagSingleViewModel(title); return(View("~/Views/Blog/TagSingle.cshtml", model)); } // Blog User if (category == "user" && !string.IsNullOrEmpty(title)) { var model = new BlogsByUserViewModel(title); return(View("~/Views/Blog/BlogsByUser.cshtml", model)); } // Category is set and we are trying to view an individual blog var blog = Context.Blogs.FirstOrDefault(x => x.PermaLink == title); if (blog != null) { var theModel = new BlogSingleHomeViewModel(title); return(View("~/Views/Home/BlogSingle.cshtml", theModel)); } // Not a blog category or a blog HttpContext.Response.StatusCode = 404; return(View("~/Views/Home/Error404.cshtml")); }
public ActionResult Tags(string tag) { // Don't index blog tag pages ViewBag.Robots = "NOINDEX, NOFOLLOW"; // Blog Listing Homepage if (String.IsNullOrEmpty(tag)) { tag = ""; } var model = new TagSingleViewModel(tag); return(View("~/Views/Blog/TagSingle.cshtml", model)); }