示例#1
0
        public async Task <ProductsImportResult> Handle(CreateProductsImport request)
        {
            // salva planilha no storage

            var fileId        = Guid.NewGuid();
            var fileExtension = Path.GetExtension(request.FileName);
            var fileNewName   = $"{fileId}{fileExtension}";
            var result        = await _fileService.Upload(fileNewName, request.Data);

            // registra importação no banco de dados

            var import = new Import(result.FilePath);

            await _importRepository.Create(import);

            // Envia mensagem para o tópico

            var importCreated = new ImportCreated
            {
                Id                 = import.Id,
                CreatedAt          = import.CreatedAt,
                SpreadsheetFileUrl = import.SpreadsheetFileUrl
            };

            await SendEvent(importCreated);

            return(new ProductsImportResult
            {
                ImportId = import.Id,
                FilePath = result.FilePath
            });
        }