コード例 #1
0
        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"
            });
        }
コード例 #2
0
            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));
            }