Exemplo n.º 1
0
        public BlogsByUserViewModel LoadBlogsByUser(String userName)
        {
            var blogModel = new BlogsByUserViewModel
            {
                BlogUsername = userName.Replace(ContentGlobals.BLOGDELIMMETER, " ")
            };

            // Get User based on authorid
            blogModel.TheBlogUser = _context.BlogUsers.FirstOrDefault(x => x.Username == blogModel.BlogUsername);

            var model = new BlogListModel(_context);

            blogModel.MaxBlogCount = model.GetBlogSettings().MaxBlogsOnHomepageBeforeLoad;
            blogModel.SkipBlogs    = blogModel.MaxBlogCount;
            blogModel.BlogTitle    = model.GetBlogSettings().BlogTitle;

            blogModel.AllBlogs = _context.Blogs.Where(x => x.BlogAuthor.Username == blogModel.BlogUsername && x.IsActive).ToList();

            blogModel.BlogsByUser = blogModel.AllBlogs
                                    .OrderByDescending(blog => blog.Date)
                                    .Take(blogModel.MaxBlogCount)
                                    .ToList();

            // Try permalink first
            blogModel.TheBlog = blogModel.BlogsByUser.FirstOrDefault(x => x.BlogAuthor.Username == blogModel.BlogUsername);

            return(blogModel);
        }
Exemplo n.º 2
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"));
        }
Exemplo n.º 3
0
        public new ActionResult User(string username)
        {
            var model = new BlogsByUserViewModel(username);

            return(View("~/Views/Blog/BlogsByUser.cshtml", model));
        }