Exemple #1
0
        public ActionResult AllPosts(int id)
        {
            _ops = new BlogOperations();
            var vM       = new AllPostsVM();
            var allPosts = _ops.GetAllBlogPosts().BlogPosts.Where(p => p.Status == PageStatus.Approved).OrderByDescending(p => p.TimeCreated).ToList();

            vM.PostCount   = allPosts.Count;
            vM.CurrentPage = id;
            vM.TotalPages  = (int)Math.Ceiling((double)vM.PostCount / (double)5);

            if (id < vM.TotalPages)
            {
                for (int i = 5 * (id - 1); i < 5 * id; i++)
                {
                    vM.BlogPosts.Add(allPosts[i]);
                }
            }
            else if (id == vM.TotalPages)
            {
                for (int i = 5 * (id - 1); i < vM.PostCount; i++)
                {
                    vM.BlogPosts.Add(allPosts[i]);
                }
            }

            vM.Categories = _ops.GetAllCategories().Categories;

            return(View("AllPosts", vM));
        }
Exemple #2
0
        public ActionResult SearchPosts()
        {
            _ops = new BlogOperations();
            var vM = new AllPostsVM();

            vM.BlogPosts =
                _ops.GetAllBlogPosts()
                .BlogPosts.Where(p => p.Status == PageStatus.Approved)
                .OrderBy(p => p.BlogPostTitle)
                .ToList();
            vM.Categories = _ops.GetAllCategories().Categories;

            return(View("SearchPosts", vM));
        }