Ejemplo n.º 1
0
 private IQueryable <Product> Filter(IQueryable <Product> products, GetProductsQuery request)
 {
     return(products.Where(p =>
                           (request.Id == null || request.Id == p.Id) &&
                           (string.IsNullOrEmpty(request.Name) || EF.Functions.ILike(p.Name, $"%{request.Name}%")) &&
                           (request.ProductType == null || request.ProductType == p.ProductType) &&
                           (request.DeliveryDate == null || request.DeliveryDate.From == null ||
                            request.DeliveryDate.From.Value <= p.DeliveryDate) &&
                           (request.DeliveryDate == null || request.DeliveryDate.To == null ||
                            p.DeliveryDate <= request.DeliveryDate.To.Value) &&
                           (request.MaterialName == null ||
                            p.Materials.Any(m => EF.Functions.ILike(m.Name, $"%{request.MaterialName}%")))));
 }
Ejemplo n.º 2
0
        public async Task <TotalList <ProductVm> > Handle(GetProductsQuery request, CancellationToken cancellationToken)
        {
            var query = _context.Products.AsQueryable();

            query = Filter(query, request);
            var total = await query.CountAsync(cancellationToken);

            query = Sort(query, request.Sorts());
            query = SkipTake(query, request);

            var products = await query
                           .ProjectTo <ProductVm>(_mapper.ConfigurationProvider)
                           .ToListAsync(cancellationToken);

            return(new TotalList <ProductVm>(products, total));
        }
Ejemplo n.º 3
0
 public async Task <List <ProductDto> > Handle(GetProductsQuery request, CancellationToken cancellationToken)
 {
     return(await context.Products.Where(p => string.IsNullOrEmpty(request.Name)?true : p.Name.Contains(request.Name)).ProjectTo <ProductDto>(mapper.ConfigurationProvider).ToListAsync());
 }