Exemplo n.º 1
0
        public CategorySingleViewModel LoadBlogsByCategory(String category)
        {
            var catModel = new CategorySingleViewModel();

            category = ContentUtils.GetFormattedUrl(category);


            catModel.AllBlogsInCategory = _context.Blogs.Where(x => x.Category.CategoryNameFormatted == category && x.IsActive)
                                          .OrderByDescending(blog => blog.Date)
                                          .ToList();

            catModel.BlogRoll = catModel.AllBlogsInCategory
                                .Take(catModel.MaxBlogCount)
                                .ToList();


            catModel.TheCategory = _context.BlogCategories.FirstOrDefault(x => x.CategoryNameFormatted == category);
            var model = new BlogListModel(_context);

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

            catModel.BlogsByCat = catModel.AllBlogsInCategory
                                  .Take(catModel.MaxBlogCount)
                                  .ToList();

            return(catModel);
        }
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 ActionResult Categories(string category)
        {
            // Blog Listing Homepage
            if (String.IsNullOrEmpty(category))
            {
                var model = new CategoryHomeViewModel();

                return(View("~/Views/Blog/CategoriesHome.cshtml", model));
            }
            // Individual Blog
            else
            {
                var model = new CategorySingleViewModel(category, Server);

                return(View("~/Views/Blog/CategoriesSingle.cshtml", model));
            }
        }
Exemplo n.º 4
0
 public CategorySinglePage(Category category)
 {
     InitializeComponent();
     _viewModel     = new CategorySingleViewModel(category);
     BindingContext = _viewModel;
 }