Ejemplo n.º 1
0
        public async Task <bool> ImportInvoiceFromCSV(ImportInvoiceFromCSVFileViewModel viewModel)
        {
            /* Validate */
            if (await ValidateAsync(viewModel, _importInvoiceFromCSVFileViewModelIsValidToImportValidation) == false)
            {
                return(await Task.FromResult(false));
            }

            /* Process */
            var result = true;

            var importInvoiceCommandCollection = await _importInvoiceCommandAdapter.AdapteeAsync(
                viewModel,
                new List <ImportInvoiceCommand>());

            foreach (var importInvoiceCommand in importInvoiceCommandCollection)
            {
                if (!(await Bus.SendCommandAsync(importInvoiceCommand)))
                {
                    result = false;
                }
            }

            return(await Task.FromResult(result));
        }
Ejemplo n.º 2
0
        public async Task ImportInvoiceFromCSV_Success()
        {
            await RunWithTelemetry(async() =>
            {
                var importInvoiceAppService = Bootstrapper.GetService <IImportInvoiceAppService>();

                var importInvoiceFromCSVFileViewModel = new ImportInvoiceFromCSVFileViewModel();
                for (int invoiceIndex = 1; invoiceIndex <= 10; invoiceIndex++)
                {
                    var invoiceCode = invoiceIndex.ToString();
                    var invoiceDate = DateTime.UtcNow.AddDays(invoiceIndex).ToString("yyyy-MM-dd");

                    var customerGovernamentalDocumentNumber = invoiceIndex.ToString();
                    var customerName = $"Customer {customerGovernamentalDocumentNumber}";

                    var productCode = invoiceIndex.ToString();
                    var productName = $"Product {productCode}";

                    for (int lineIndex = 1; lineIndex <= 3; lineIndex++)
                    {
                        importInvoiceFromCSVFileViewModel.FileLineCollection.Add(new FileLineViewModel
                        {
                            InvoiceCode = invoiceCode,
                            InvoiceDate = invoiceDate,
                            CustomerGovernamentalDocumentNumber = customerGovernamentalDocumentNumber,
                            CustomerName         = customerName,
                            ProductCode          = productCode,
                            ProductName          = productName,
                            InvoiceItemQuantity  = "1",
                            InvoiceItemSequence  = lineIndex.ToString(),
                            InvoiceItemUnitPrice = "1.00"
                        });
                    }
                }

                await importInvoiceAppService.ImportInvoiceFromCSV(importInvoiceFromCSVFileViewModel);

                return(true);
            },
                                   1000);
        }
Ejemplo n.º 3
0
        public async Task <List <ImportInvoiceCommand> > AdapteeAsync(ImportInvoiceFromCSVFileViewModel source, List <ImportInvoiceCommand> to)
        {
            var invoiceCodeCollection = source.FileLineCollection?.Select(q => q.InvoiceCode).Where(q => !string.IsNullOrEmpty(q)).Distinct();

            foreach (var invoiceCode in invoiceCodeCollection)
            {
                var invoiceLinesCollection = source.FileLineCollection.Where(q => q.InvoiceCode == invoiceCode);
                var firstLine = invoiceLinesCollection.FirstOrDefault();

                var importInvoiceCommand = new ImportInvoiceCommand
                {
                    Code     = invoiceCode,
                    Customer = new Customer
                    {
                        GovernamentalDocumentNumber = firstLine.CustomerGovernamentalDocumentNumber,
                        Name = firstLine.CustomerName
                    },
                    Date        = DateTime.Parse(firstLine.InvoiceDate),
                    RequestUser = _tenantInfoValueObject.TenantCode,

                    InvoiceItemCollection = new List <InvoiceItem>()
                };

                foreach (var invoiceLine in invoiceLinesCollection)
                {
                    importInvoiceCommand.InvoiceItemCollection.Add(new InvoiceItem
                    {
                        Product = new Product {
                            Code = invoiceLine.ProductCode, Name = invoiceLine.ProductName
                        },
                        Sequence  = int.Parse(invoiceLine.InvoiceItemSequence),
                        Quantity  = double.Parse(invoiceLine.InvoiceItemQuantity),
                        UnitPrice = double.Parse(invoiceLine.InvoiceItemUnitPrice)
                    });
                }

                to.Add(importInvoiceCommand);
            }

            return(await Task.FromResult(to));
        }