Example #1
0
        public ProductListAdminViewModel GetProductsForAdmin(int pageNumber, string productCode)
        {
            var itemsPerPage = Convert.ToInt32(ConfigurationManager.AppSettings["AdminProductsPerPage"]);
            var itemsToSkip  = (pageNumber - 1) * itemsPerPage;

            var productsForAdmin = _iProductRepository.GetProductsForAdmin(itemsPerPage, itemsToSkip, productCode);

            var productListAdminViewModel = new ProductListAdminViewModel
            {
                TotalCount = productsForAdmin.TotalCount,
                Products   = productsForAdmin.Products.Select(x => x.ToListItemModel())
            };

            return(productListAdminViewModel);
        }
Example #2
0
        public IActionResult Index(int page = 1, int category = 0, string productName = null)
        {
            int pageSize = 25;
            var products = _productService.GetByCategory(category).AsQueryable();

            #region search
            if (!string.IsNullOrEmpty(productName))
            {
                products = products.Where(x => x.ProductName.Contains(productName));
            }
            #endregion
            ProductListAdminViewModel model = new ProductListAdminViewModel
            {
                Products         = products.Skip((page - 1) * pageSize).Take(pageSize).ToList(),
                PageCount        = (int)Math.Ceiling(products.Count() / (double)pageSize),
                PageSize         = pageSize,
                CurrentCategory  = category,
                CurrentPage      = page,
                TotalProductSize = products.Count()
            };
            return(View(model));
        }