コード例 #1
0
        public async Task <IEnumerable <CategoryViewModel> > GetCategoriesAsync(CategorySearchParams searchParams)
        {
            var specification = new CategoryFilterSpecification(searchParams);

            return(await _categoryRepository.ListAsync <CategoryViewModel>(specification,
                                                                           CategoryHelpers.GetCategoryMapperConfiguration()));
        }
コード例 #2
0
        public async Task <IEnumerable <Category> > GetPostCategoriesAsync(Post post)
        {
            var categoryIds = await GetCategoryIdsInPostAsync(post);

            var filter = new CategoryFilterSpecification(categoryIds);

            return(await categoryRepository.ListAsync(filter));
        }
コード例 #3
0
        public async Task <CategoryIndexViewModel> GetCaregoryItems(int pageIndex, int itemsPage, int?typeId)
        {
            _logger.LogInformation("GetCatalogItems called.");

            var filterSpecification = new CategoryFilterSpecification(typeId);
            var root = _itemRepository.List(filterSpecification);

            var totalItems = root.Count();

            var itemsOnPage = root
                              .Skip(itemsPage * pageIndex)
                              .Take(itemsPage)
                              .ToList();

            itemsOnPage.ForEach(x =>
            {
                x.PictureUri = _uriComposer.ComposePicUri(x.PictureUri);
            });

            var vm = new CategoryIndexViewModel()
            {
                CatalogItems = itemsOnPage.Select(i => new CategoryItemViewModel()
                {
                    Id         = i.Id,
                    Name       = i.Name,
                    PictureUri = i.PictureUri,
                    Price      = i.Price
                }),
                Types = await GetTypes(),
                TypesFilterApplied = typeId ?? 0,
                PaginationInfo     = new PaginationInfoViewModel()
                {
                    ActualPage   = pageIndex,
                    ItemsPerPage = itemsOnPage.Count,
                    TotalItems   = totalItems,
                    TotalPages   = int.Parse(Math.Ceiling(((decimal)totalItems / itemsPage)).ToString())
                }
            };

            vm.PaginationInfo.Next     = (vm.PaginationInfo.ActualPage == vm.PaginationInfo.TotalPages - 1) ? "is-disabled" : "";
            vm.PaginationInfo.Previous = (vm.PaginationInfo.ActualPage == 0) ? "is-disabled" : "";

            return(vm);
        }
コード例 #4
0
        public Category GetCategoryByCode(string code)
        {
            var filter = new CategoryFilterSpecification(code);

            return(categoryRepository.GetSingleBySpec(filter));
        }
コード例 #5
0
        public async Task <int> GetCategoriesCountAsync(CategorySearchParams searchParams)
        {
            var specification = new CategoryFilterSpecification(searchParams);

            return(await _categoryRepository.GetTotalCountAsync(specification));
        }