public async Task <File> Handle(ExportProductQuery query)
        {
            List <DomainCore.Models.Product> products = await _readOnlyProductRepository.GetProductsAsync();

            byte[] fileBytes = _productExportService.Export(products);

            return(new File {
                Bytes = fileBytes, Name = $"Products_{DateTime.UtcNow}.xls"
            });
        }
Beispiel #2
0
        public async Task <GetProductsResponse> Handle(GetProductsQuery query)
        {
            List <DomainCore.Models.Product> products = await _readOnlyProductRepository.GetProductsAsync(query.SearchTerm);

            var response = new GetProductsResponse()
            {
                Products = new List <ViewProduct>()
            };

            foreach (var product in products)
            {
                var responseProduct = _mapper.Map <Contract.ViewProduct>(product);
                if (product.ImageThumbnail != null)
                {
                    responseProduct.Photo = _mapper.Map <ImageFile>(product.ImageThumbnail);
                }
                response.Products.Add(responseProduct);
            }

            return(response);
        }