//   public IActionResult GetByCategoryId(int id)
        public IActionResult GetByCategoryId(int id, int page = 1, int pageSize = 3)
        {
            var productList = _unitOfWork.ProductRepository.GetByCategoryId(id);

            X.PagedList.PagedList <Product> model = new X.PagedList.PagedList <Product>(productList.Where(x => x.CategoryID == id), page, pageSize);
            return(View(model));
        }
Пример #2
0
        /// <summary>
        /// Creates a <see cref="PagedList{TSource}" /> from an <see cref="IQueryable{TSource}" /> by enumerating.
        /// </summary>
        /// <typeparam name="TSource"> The type of the elements of <paramref name="source" />.</typeparam>
        /// <param name="source"> An <see cref="IQueryable{TSource}" /> to create a list from.</param>
        /// <param name="paging">Paging information</param>
        /// <returns>The input sequence typed as <see cref="IPagedList{TSource}" />.</returns>
        public static IPagedList <TSource> AsPagedList <TSource>(this IQueryable <TSource> source, IPageInfo paging)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (paging == null)
            {
                throw new ArgumentNullException(nameof(paging));
            }

            var pagedList = new X.PagedList.PagedList <TSource>(source, paging.NumberOfSelectedPage, paging.PageSize);

            return(new PagedList <TSource>(pagedList, pagedList.PageNumber, pagedList.PageSize, pagedList.TotalItemCount));
        }
Пример #3
0
        public IActionResult Index(int id, int page = 1, int pageSize = 3)
        {
            Category category = new Category();

            using (ECommerceContext eCommerceContext = new ECommerceContext())
            {
                category = eCommerceContext.Categories.SingleOrDefault(a => a.Id == id);
            }

            List <Product> products = new List <Product>();

            //using (ECommerceContext eCommerceContext = new ECommerceContext())
            //{
            //    products = eCommerceContext.Products.Where(x => x.CategoryId == id).ToList();
            //}
            ECommerceContext eCommerceContext2 = new ECommerceContext();

            //PagedList<Product> model = new PagedList<Product>(eCommerceContext2.Products.Where(x => x.CategoryId == id), page,pageSize);
            X.PagedList.PagedList <Product> model = new X.PagedList.PagedList <Product>(eCommerceContext2.Products.Where(x => x.CategoryId == id), page, pageSize);

            ViewData["Title"]      = category.Name;
            ViewData["CategoryId"] = category.Id;
            return(View("Index", model));
        }
Пример #4
0
 public IActionResult UserList(int id, int page = 1, int pageSize = 2)
 {
     X.PagedList.PagedList <User> result = new X.PagedList.PagedList <User>(_unitOfWork.UserRepository.List(), page, pageSize);
     return(View(result));
 }