protected void SetMetaTagsAndTheme(Blog blog) { StoreFrontConfiguration config = CurrentStoreFrontConfigOrThrow; _metaDescriptionOverride = blog.MetaDescriptionOrSystemDefault(config); _metaKeywordsOverride = blog.MetaKeywordsOrSystemDefault(config); ViewData.Theme(blog.ThemeOrSystemDefault(config)); }
protected ActionResult ViewBlog(Blog blog, bool blogEntryUrlNameIsAll) { if (blog == null) { throw new ArgumentNullException("blog"); } if (!blogEntryUrlNameIsAll && blog.AutoDisplayLatestEntry) { BlogEntry firstEntry = blog.BlogEntriesForUser(User.IsRegistered()).FirstOrDefault(); if (firstEntry != null) { return RedirectToAction("Index", RouteDataForIndex(blog.UrlName, firstEntry.UrlName)); } } GStoreDb.LogUserActionEvent(HttpContext, RouteData, this, UserActionCategoryEnum.Blog, UserActionActionEnum.Blog_View, blog.UrlName, true, blogId: blog.BlogId); SetMetaTagsAndTheme(blog); return View("ViewBlog", blog); }
protected BlogEntry GetBlogEntry(Blog blog, string blogEntryUrlName) { if (string.IsNullOrWhiteSpace(blogEntryUrlName)) { GStoreDb.LogUserActionEvent(HttpContext, RouteData, this, UserActionCategoryEnum.Blog, UserActionActionEnum.Blog_ViewEntry, "no blog entry name", false, blogId: blog.BlogId); AddUserMessage("Blog Post not found.", "Sorry, the blog post you are looking for cannot be found. Please try another blog post.", UserMessageType.Warning); return null; } BlogEntry blogEntry = blog.BlogEntries.AsQueryable().WhereIsActive().WhereRegisteredAnonymousCheck(User.IsRegistered()).SingleOrDefault(be => be.UrlName.ToLower() == blogEntryUrlName.Trim().ToLower()); if (blogEntry == null) { GStoreDb.LogUserActionEvent(HttpContext, RouteData, this, UserActionCategoryEnum.Blog, UserActionActionEnum.Blog_ViewEntry, "blog entry not found: " + blogEntryUrlName, false); AddUserMessage("Blog Post not found.", "Sorry, the blog post '" + blogEntryUrlName.ToHtml() + "' cannot be found. Please try another blog post.", UserMessageType.Warning); return null; } if (!blog.IsActiveDirect()) { GStoreDb.LogUserActionEvent(HttpContext, RouteData, this, UserActionCategoryEnum.Blog, UserActionActionEnum.Blog_ViewEntry, "blog entry is inactive: " + blogEntryUrlName, false, blogId: blog.BlogId, blogEntryId: blogEntry.BlogEntryId); AddUserMessage("Blog Post Is Not Active.", "Sorry, the blog post '" + blogEntryUrlName.ToHtml() + "' is not active. Please try another blog post.", UserMessageType.Warning); return null; } if (blog.ForAnonymousOnly && !blog.ForRegisteredOnly && User.IsRegistered()) { GStoreDb.LogUserActionEvent(HttpContext, RouteData, this, UserActionCategoryEnum.Blog, UserActionActionEnum.Blog_ViewEntry, "blog entry anonymous only: " + blogEntryUrlName, false, blogId: blog.BlogId, blogEntryId: blogEntry.BlogEntryId); AddUserMessage("Blog Post Unavailable.", "Sorry, the blog post '" + blogEntryUrlName.ToHtml() + "' is for anonymous users only. Please try another blog post.", UserMessageType.Warning); return null; } else if (blogEntry.ForRegisteredOnly && !blogEntry.ForAnonymousOnly && User.IsAnonymous()) { GStoreDb.LogUserActionEvent(HttpContext, RouteData, this, UserActionCategoryEnum.Blog, UserActionActionEnum.Blog_ViewEntry, "blog entry registered only: " + blogEntryUrlName, false, blogId: blog.BlogId, blogEntryId: blogEntry.BlogEntryId); throw new LoginRequiredException(blog.Name, blogEntry.Name); } return blogEntry; }