Пример #1
0
        public async Task <FileDto> GetProductsToExcel(GetAllProductsForExcelInput input)
        {
            var filteredProducts = _productRepository.GetAll()
                                   .WhereIf(!string.IsNullOrWhiteSpace(input.Filter), e => false || e.Description.Contains(input.Filter))
                                   .WhereIf(!string.IsNullOrWhiteSpace(input.DescriptionFilter), e => e.Description.ToLower() == input.DescriptionFilter.ToLower().Trim());

            var query = (from o in filteredProducts
                         select new GetProductForViewDto()
            {
                Product = new ProductDto
                {
                    Description = o.Description,
                    Id = o.Id
                }
            });


            var productListDtos = await query.ToListAsync();

            return(_productsExcelExporter.ExportToFile(productListDtos));
        }
        public async Task <FileDto> GetProductsToExcel(GetAllProductsForExcelInput input)
        {
            var filteredProducts = _productRepository.GetAll()
                                   .Include(e => e.CategoryFk)
                                   .WhereIf(!string.IsNullOrWhiteSpace(input.Filter), e => false || e.Name.Contains(input.Filter) || e.Description.Contains(input.Filter) || e.Uom.Contains(input.Filter) || e.Remark.Contains(input.Filter))
                                   .WhereIf(!string.IsNullOrWhiteSpace(input.NameFilter), e => e.Name == input.NameFilter)
                                   .WhereIf(!string.IsNullOrWhiteSpace(input.DescriptionFilter), e => e.Description == input.DescriptionFilter)
                                   .WhereIf(input.MinStockFilter != null, e => e.Stock >= input.MinStockFilter)
                                   .WhereIf(input.MaxStockFilter != null, e => e.Stock <= input.MaxStockFilter)
                                   .WhereIf(!string.IsNullOrWhiteSpace(input.UomFilter), e => e.Uom == input.UomFilter)
                                   .WhereIf(input.IsApprovedFilter > -1, e => (input.IsApprovedFilter == 1 && e.IsApproved) || (input.IsApprovedFilter == 0 && !e.IsApproved))
                                   .WhereIf(input.IsActiveFilter > -1, e => (input.IsActiveFilter == 1 && e.IsActive) || (input.IsActiveFilter == 0 && !e.IsActive))
                                   .WhereIf(!string.IsNullOrWhiteSpace(input.CategoryNameFilter), e => e.CategoryFk != null && e.CategoryFk.Name == input.CategoryNameFilter);

            var query = (from o in filteredProducts
                         join o1 in _lookup_categoryRepository.GetAll() on o.CategoryId equals o1.Id into j1
                         from s1 in j1.DefaultIfEmpty()

                         select new GetProductForViewDto()
            {
                Product = new ProductDto
                {
                    Name = o.Name,
                    Description = o.Description,
                    Stock = o.Stock,
                    Uom = o.Uom,
                    IsApproved = o.IsApproved,
                    IsActive = o.IsActive,
                    Remark = o.Remark,
                    Id = o.Id
                },
                CategoryName = s1 == null ? "" : s1.Name.ToString()
            });


            var productListDtos = await query.ToListAsync();

            return(_productsExcelExporter.ExportToFile(productListDtos));
        }