示例#1
0
        public async Task <IActionResult> Categories()
        {
            var categories = (await _shopManager.GetAllCategoriesAsync())
                             .Select(x => new
            {
                x.Id,
                x.Name,
                x.Description
            });

            return(Ok(categories));
        }
示例#2
0
        public async Task <ActionResult> Search(
            [FromQuery(Name = "s")] string search,
            [FromQuery(Name = "o")] string sortOrder,
            [FromQuery(Name = "p")] int?page,
            [FromQuery(Name = "c")] int?pageCount,
            [FromQuery(Name = "cat")] int[] categoryIds)

        {
            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(ItemTypeSelector.Enabled, currPage, countPerPage,
                                                          search, sortOrder, categoryIds);

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

            ViewBag.itemCount = result.TotalN;

            //TODO mapper
            var model = new SearchViewModel()
            {
                CurrentSearch    = search,
                CurrentSortOrder = sortOrder,
                Descending       = sortOrder.EndsWith("_desc"),
                CurrentPage      = currPage,
                CountPerPage     = countPerPage,
                ItemCount        = result.TotalN,
                CategoryIds      = categoryIds,
                FilteredItems    = _mapper.Map <IEnumerable <ProductDto> >(result.FilteredData),
                AllCategories    = allCategories
            };

            if (!search.IsNullOrEmpty())
            {
                IEnumerable <Category> filteredCategories = await _shopManager.SearchCategoriesByName(search);

                model.FilteredCategories = _mapper.Map <IEnumerable <CategoryDto> >(filteredCategories);
            }

            return(View(model));
        }
示例#3
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));
        }