예제 #1
0
        public async Task <ActionResult> Index(
            [FromQuery(Name = "p")] int?page,
            [FromQuery(Name = "c")] int?pageCount)
        {
            var currPage     = page ?? 1;
            var countPerPage = pageCount == null || pageCount <= 0 ? 15 : pageCount.Value;

            SortPageResult <Product> result =
                await _shopManager.GetSortFilterPageAsync(ItemTypeSelector.Enabled, currPage, countPerPage);

            var recentProductNumber = 4;
            IEnumerable <Product> recentProducts = await _shopManager.GetNewProducts(recentProductNumber);

            var model = new IndexViewModel()
            {
                RecentItems  = _mapper.Map <IEnumerable <ProductDto> >(recentProducts),
                Items        = _mapper.Map <IEnumerable <ProductDto> >(result.FilteredData),
                ItemCount    = result.TotalN,
                CurrentPage  = currPage,
                CountPerPage = countPerPage
            };

            return(View(model));
        }
예제 #2
0
        public async Task <IActionResult> Items(
            [FromQuery(Name = "s")] string search,
            [FromQuery(Name = "st")] ItemTypeSelector types,
            [FromQuery(Name = "o")] string sortOrder,
            [FromQuery(Name = "p")] int?page,
            [FromQuery(Name = "c")] int?pageCount,
            [FromQuery(Name = "cat")] int[] categoryIds,
            [FromQuery(Name = "desc")] int[] descGroupIds)
        {
            if (sortOrder.IsNullOrEmpty())
            {
                sortOrder = nameof(ProductDto.Name);
            }

            var currPage     = page ?? 1;
            var countPerPage = pageCount == null || pageCount <= 0 ? 15 : pageCount.Value;

            SortPageResult <Product> result =
                await _shopManager.GetSortFilterPageAsync(types, currPage, countPerPage, search, sortOrder,
                                                          categoryIds, descGroupIds);

            var allCategories =
                _mapper.Map <IEnumerable <CategoryDto> >(await _shopManager.GetAllCategoriesAsync());

            ViewBag.itemCount = result.TotalN;

            var model = new ItemsViewModel()
            {
                CurrentSearch    = search,
                CurrentSortOrder = sortOrder,
                Descending       = sortOrder.EndsWith("_desc"),
                CurrentPage      = currPage,
                CountPerPage     = countPerPage,
                Types            = (int)types,
                ItemCount        = result.TotalN,
                CategoryIds      = categoryIds,
                DescGroupIds     = descGroupIds,
                Items            = _mapper.Map <IEnumerable <ProductDto> >(result.FilteredData),
                Categories       = allCategories
            };

            return(View(model));
        }