Пример #1
0
        /// <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"));
        }
Пример #2
0
        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);
        }