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);
            }
        }
Example #2
0
        public BlogHomeViewModel LoadBlogHome(string date = "")
        {
            var homeModel = new BlogHomeViewModel();
            var model = new BlogListModel(_context);
            homeModel.MaxBlogCount = model.GetBlogSettings().MaxBlogsOnHomepageBeforeLoad;
            homeModel.SkipBlogs = homeModel.MaxBlogCount;

            homeModel.BlogTitle = model.GetBlogSettings().BlogTitle;

            homeModel.FeaturedBlog = _context.Blogs.FirstOrDefault(x => x.IsFeatured);

            homeModel.CurrentMonth = "";

            homeModel.AllBlogs = _context.Blogs.Where(x => x.IsActive).ToList();

            homeModel.BlogRoll = homeModel.AllBlogs.Where(x => x.IsActive)
                        .OrderByDescending(x => x.Date)
                        .Take(homeModel.MaxBlogCount)
                        .ToList();

            homeModel.BlogCats = new BlogsCategoriesViewModel("");

            if (!String.IsNullOrEmpty(date))
            {
                var startDate = Convert.ToDateTime(date);

                homeModel.CurrentMonth = startDate.ToString("MM/yyyy");

                homeModel.BlogRoll =
                    _context.Blogs.Where(
                        x => x.IsActive
                             && (x.Date.Month == startDate.Month)
                             && (x.Date.Year == startDate.Year)
                        )
                           .OrderByDescending(x => x.Date)
                           .Take(homeModel.MaxBlogCount)
                           .ToList();
            }

            return homeModel;
        }