public ActionResult Index(string title, string date) { // Blog Listing Homepage if (String.IsNullOrEmpty(title)) { var model = new BlogHomeViewModel(date); return View("~/Views/Home/Blog.cshtml", model); } // Individual Blog else { var model = new BlogSingleHomeViewModel(title); return View("~/Views/Home/BlogSingle.cshtml", model); } }
public BlogSingleHomeViewModel LoadSingleBlog(String title) { var model = new BlogSingleHomeViewModel { TheBlog = _context.Blogs.FirstOrDefault(x => x.PermaLink == title) }; // If no go then try title as a final back up if (model.TheBlog == null) { title = title.Replace(ContentGlobals.BLOGDELIMMETER, " "); model.TheBlog = _context.Blogs.FirstOrDefault(x => x.Title == title); if (model.TheBlog == null) { return model; } // Go ahead and set the permalink for future reference if (String.IsNullOrEmpty(model.TheBlog.PermaLink)) { model.TheBlog.PermaLink = ContentUtils.GetFormattedUrl(model.TheBlog.Title); _context.SaveChanges(); } } model.RelatedPosts = new BlogRelatedViewModel(model.TheBlog.Title); model.TheBlogUser = _context.BlogUsers.FirstOrDefault(x => x.UserId == model.TheBlog.AuthorId); model.BlogAuthorModel = new BlogAuthorViewModel(model.TheBlog.BlogAuthor.Username); model.ShowFacebookLikeButton = _settingsUtils.ShowFbLikeButton(); model.ShowFacebookComments = _settingsUtils.ShowFbComments(); model.BlogAbsoluteUrl = HttpContext.Current.Request.Url.AbsoluteUri; model.UseDisqusComments = _settingsUtils.UseDisqusComments(); if (model.UseDisqusComments) { model.DisqusShortName = _settingsUtils.DisqusShortName(); } model.Categories = GetActiveBlogCategories(); return model; }