Пример #1
0
        public ActionResult BlogByCategoryID(int CategoryID, int Page)
        {
            var ops    = new FITlosophiOperations();
            var blogVM = new BlogViewModel();
            var posts  = ops.GetAllPostsByCategory(CategoryID);

            blogVM.Categories = ops.GetAllCategories();
            blogVM.TotalPosts = posts.Count();
            blogVM.Posts      = posts.Skip((4 * Page) - 4).Take(10).ToList();
            blogVM.Page       = Page;

            // Calculate the total number of pages
            blogVM.TotalNumberOfPages = blogVM.TotalPosts / 4;
            if ((blogVM.TotalPosts % 4) > 0)
            {
                blogVM.TotalNumberOfPages++;
            }

            //Create paging url based on controller action
            if (Page < blogVM.TotalNumberOfPages)
            {
                blogVM.OlderUrl = "/Home/BlogByCategoryID?CategoryID=" + CategoryID + "&Page=" + (Page + 1);
            }

            if (Page > 1)
            {
                blogVM.NewUrl = "/Home/BlogByCategoryID?CategoryID=" + CategoryID + "&Page=" + (Page - 1);
            }

            return(View("Index", blogVM));
        }
        public List <Post> GetAllPostsByCategory(int categoryID)
        {
            var read = new FITlosophiOperations();

            return(read.GetAllPostsByCategory(categoryID));
        }