public async Task <ProductsFileVm> Handle(GetProductsFileQuery request, CancellationToken cancellationToken) { var records = await _context.Products .ProjectTo <ProductFileRecord>(_mapper.ConfigurationProvider) .ToListAsync(cancellationToken); var fileContent = _fileBuilder.BuildProductsFile(records); return(new ProductsFileVm { Content = fileContent, FileName = $"{_dateTime.Now:yyyy-MM-dd}-Products.csv" }); }
public async Task <ExportCategorysVm> Handle(ExportCategorysQuery request, CancellationToken cancellationToken) { var vm = new ExportCategorysVm(); var records = await _context.Products .Where(t => t.CategoryId == request.CategoryId) .ProjectTo <ProductRecord>(_mapper.ConfigurationProvider) .ToListAsync(cancellationToken); vm.Content = _fileBuilder.BuildProductsFile(records); vm.ContentType = "text/csv"; vm.FileName = "Products.csv"; return(await Task.FromResult(vm)); }