コード例 #1
0
        // Protected Methods
        protected override CommandHandler <ImportInvoiceCommand> GetCommandHandler()
        {
            return(async command =>
            {
                var invoiceToImport = await _invoiceFactory.CreateAsync(command);

                var importedProductsCollection = new List <DomainModels.Product>();

                // Get all products and product codes
                var productCollection = invoiceToImport.InvoiceItemCollection.Select(invoiceItem => invoiceItem?.Product).Where(q => q != null);
                var productCodeCollection = productCollection.Select(q => q.Code).Where(q => q != null).Distinct();

                // Import customer
                invoiceToImport.SetCustomer(await _customerDomainService.ImportCustomerAsync(
                                                TenantInfoValueObject.TenantCode,
                                                command.RequestUser,
                                                invoiceToImport.Customer));

                // Import all products
                foreach (var productCode in productCodeCollection)
                {
                    importedProductsCollection.Add(await _productDomainService.ImportProductAsync(
                                                       TenantInfoValueObject.TenantCode,
                                                       command.RequestUser,
                                                       productCollection.FirstOrDefault(q => q?.Code == productCode))
                                                   );
                }

                // Update invoice items products
                foreach (var invoiceItem in invoiceToImport.InvoiceItemCollection)
                {
                    invoiceItem.SetProduct(importedProductsCollection.FirstOrDefault(q =>
                                                                                     q.Code == invoiceItem.Product.Code)
                                           );
                }

                // Import invoice
                await _invoiceDomainService.ImportInvoiceAsync(
                    TenantInfoValueObject.TenantCode,
                    command.RequestUser,
                    invoiceToImport);

                // Check errors
                var sucess = !InMemoryDefaultDomainNotificationHandler.DomainNotificationsCollection.Any();

                return await Task.FromResult(sucess);
            });
        }
コード例 #2
0
 private async Task <Customer> ImportCustomerAsync(Customer customer)
 {
     return(await _customerDomainService.ImportCustomerAsync(customer));
 }