private async Task UpdateProduct(Product product, ProcessProductRequested notification) { product.Update( name: notification.Name, price: notification.Price, stock: notification.Stock ); var error = ValidateProduct(product); if (string.IsNullOrWhiteSpace(error)) { await _productRepository.Update(product); _logger.LogInformation($"Product UPDATED: {product.StoreId} | {product.Code} | {product.ProcessedAt}"); } await _importRepository.MarkProductAsProcessed(notification.ImportId, notification.ProductCode, error); }
// Implementations public async Task Handle(ProcessProductRequested notification) { var product = await _productRepository.GetProduct(notification.StoreId, notification.ProductCode); if (product is null) { await CreateProduct(notification); } else { await UpdateProduct(product, notification); } // se for o último produto a ser atualizado, notifica finalização da importação if (await IsLastProductImported(notification.ImportId)) { await RaiseEventImportCompleted(notification.ImportId); } }