Exemplo n.º 1
0
        public async Task <PaginatedItems <ManufacturerViewModel> > Handle(GetManufacturersListQuery request, CancellationToken cancellationToken)
        {
            var products = GetProductQueryable();

            var manufacturersMapped = _mapper.ProjectTo <ManufacturerViewModel>(products);

            var paginatedProducts = PaginatedItems <ManufacturerViewModel> .Create(request.PageIndex,
                                                                                   request.PageSize, manufacturersMapped);

            await Task.CompletedTask;

            return(paginatedProducts);
        }
        public async Task <PaginatedItems <CategoryViewModel> > Handle(GetCategoriesListQuery request, CancellationToken cancellationToken)
        {
            var categories = _context.Categories.AsQueryable();

            var categoriesMapped = _mapper.ProjectTo <CategoryViewModel>(categories);

            var paginatedCategories =
                PaginatedItems <CategoryViewModel> .Create(request.PageIndex, request.PageSize, categoriesMapped);

            await Task.CompletedTask;

            return(paginatedCategories);
        }
Exemplo n.º 3
0
        public async Task <PaginatedItems <PictureViewModel> > Handle(GetPicturesListQuery request, CancellationToken cancellationToken)
        {
            var pictures = _context.Pictures.AsQueryable();

            var picturesViewModel = _mapper.ProjectTo <PictureViewModel>(pictures);

            var paginatedPictures2 =
                PaginatedItems <PictureViewModel> .Create(request.PageIndex, request.PageSize, picturesViewModel);

            await Task.CompletedTask;

            return(paginatedPictures2);
        }
Exemplo n.º 4
0
        public async Task <PaginatedItems <ProductViewModel> > Handle(GetProductsListQuery request,
                                                                      CancellationToken cancellationToken)
        {
            var products = GetProductQueryable();

            if (request.CategoryId != null)
            {
                products = products.Where(x => x.CategoryId.Equals(request.CategoryId));
            }

            if (request.ManufacturerId != null)
            {
                products = products.Where(x => x.ManufacturerId.Equals(request.ManufacturerId));
            }

            var productsMapped = _mapper.ProjectTo <ProductViewModel>(products);

            var paginatedProducts =
                PaginatedItems <ProductViewModel> .Create(request.PageIndex, request.PageSize, productsMapped);

            await Task.CompletedTask;

            return(paginatedProducts);
        }
        public async Task <PaginatedItems <SmartProductViewModel> > Handle(GetProductsListQuery request,
                                                                           CancellationToken cancellationToken)
        {
            var products = _context.Set <Product>()
                           .Include(x => x.Category)
                           .Include(x => x.Manufacturer)
                           .AsNoTracking()
                           .AsQueryable();

            products = new ProductsQueryBuilder(products)
                       .FilterByPrice(request.Price)
                       .FilterByStockQuantity(request.StockQuantity)
                       .Build();

            var productsMapped = _mapper.ProjectTo <SmartProductViewModel>(products);

            var paginatedProducts =
                PaginatedItems <SmartProductViewModel> .Create(request.PageIndex, request.PageSize,
                                                               productsMapped);

            await Task.CompletedTask;

            return(paginatedProducts);
        }