Пример #1
0
        public IEnumerable <Product> Search(string keyword, int page, int pageSize, AppValue.SortProduct sort, out int totalRow)
        {
            var query = _productRepository.GetMulti(x => x.Status && x.Name.Contains(keyword));

            switch (sort)
            {
            case AppValue.SortProduct.New:
                query = query.OrderByDescending(x => x.ViewCount);
                break;

            case AppValue.SortProduct.Discount:
                query = query.OrderByDescending(x => x.Promotion.HasValue);
                break;

            case AppValue.SortProduct.Price:
                query = query.OrderBy(x => x.Price);
                break;

            default:
                query = query.OrderByDescending(x => x.CreatedDate);
                break;
            }

            totalRow = query.Count();

            return(query.Skip((page - 1) * pageSize).Take(pageSize));
        }
Пример #2
0
        public ActionResult Search(string keyword, int page = 1, AppValue.SortProduct sort = AppValue.SortProduct.New)
        {
            int pageSize  = int.Parse(ConfigHelperUtility.GetByKey(Constant.AppSetting_PageSize));
            int totalRow  = 0;
            var product   = _productService.Search(keyword, page, pageSize, sort, out totalRow);
            var productVM = Mapper.Map <List <ProductViewModel> >(product);
            int totalPage = (totalRow % pageSize == 0) ? (totalRow / pageSize) : (totalRow / pageSize) + 1;

            ViewBag.Keyword = keyword;
            var paginationSet = new PaginationSet <ProductViewModel>()
            {
                Items      = productVM,
                MaxPage    = int.Parse(ConfigHelperUtility.GetByKey(Constant.AppSetting_MaxPage)),
                Page       = page,
                TotalCount = totalRow,
                TotalPages = totalPage
            };

            return(View(paginationSet));
        }
Пример #3
0
        public ActionResult Category(int id, int page = 1, AppValue.SortProduct sort = AppValue.SortProduct.New)
        {
            int pageSize  = int.Parse(ConfigHelperUtility.GetByKey(Constant.AppSetting_PageSize));
            int totalRow  = 0;
            var product   = _productService.GetListProductByCategoryIdPaging(id, page, pageSize, sort, out totalRow);
            var productVM = Mapper.Map <List <ProductViewModel> >(product);
            int totalPage = (totalRow % pageSize == 0) ? (totalRow / pageSize) : (totalRow / pageSize) + 1;

            var category = _productCategoryService.GetById(id);

            ViewBag.Category = Mapper.Map <ProductCategoryViewModel>(category);
            var paginationSet = new PaginationSet <ProductViewModel>()
            {
                Items      = productVM,
                MaxPage    = int.Parse(ConfigHelperUtility.GetByKey(Constant.AppSetting_MaxPage)),
                Page       = page,
                TotalCount = totalRow,
                TotalPages = totalPage
            };

            return(View(paginationSet));
        }
Пример #4
0
        public IEnumerable <Product> GetListProductByCategoryIdPaging(int categoryId, int page, int pageSize, AppValue.SortProduct sort, out int totalRow)
        {
            var query = _productRepository.GetMulti(x => x.Status && x.CategoryID == categoryId);

            switch (sort)
            {
            case AppValue.SortProduct.New:
                query = query.OrderByDescending(x => x.ViewCount);
                break;

            case AppValue.SortProduct.Discount:
                query = query.OrderByDescending(x => x.Promotion.HasValue);
                break;

            case AppValue.SortProduct.Price:
                query = query.OrderBy(x => x.Price);
                break;

            default:
                query = query.OrderByDescending(x => x.CreatedDate);
                break;
            }

            totalRow = query.Count();

            return(query.Skip((page - 1) * pageSize).Take(pageSize));
        }