Esempio n. 1
0
        public InvoiceDomain Save(InvoiceDomain domain)
        {
            var entity = InvoiceEntity.FromDomain(domain);

            entity.ItemsRefs = domain.Items.Select(item => _itemRepository.Save(item))
                               .Select(item => item.Id.Value)
                               .ToList();

            entity.PaymentsRefs = domain.Payments.Select(payment => _paymentRepository.Save(payment))
                                  .Select(payment => payment.Id.Value)
                                  .ToList();

            entity.SupplierRef = _supplierRepository.Save(domain.Supplier).Id.Value;
            entity.ReceiverRef = _receiverRepository.Save(domain.Receiver).Id.Value;

            var command = new InvoiceSaveCommand(_dataSource, entity);

            entity = command.Execute();

            return(PrepareAggregate(entity));
        }
Esempio n. 2
0
        public int InvoiceSave(Invoice invoice)
        {
            if (invoice == null)
            {
                throw new ArgumentNullException(nameof(invoice));
            }

            return(ExecuteFaultHandledOperation(() =>
            {
                var inv_data = _invoice_se.Map(invoice);

                inv_data.InvoiceItemCount = invoice.InvoiceItems.Sum(item => item.InvoiceItemQuantity);
                inv_data.InvoiceValueSum = invoice.InvoiceItems.Sum(item => item.InvoiceItemLineSum);
                int invoice_key = _invoice_repo.Insert(inv_data);

                Log.Info($"Invoice Item start [{invoice.InvoiceItems.Count}] items to process");
                foreach (var inv_item in invoice.InvoiceItems)
                {
                    var inv_item_data = _invoice_item_se.Map(inv_item);
                    //Log.Info($"Order Item converted [{order_item_data.ProductName}] sucessfully!");
                    inv_item_data.InvoiceKey = invoice_key;
                    inv_item_data.InvoiceItemKey = inv_item.InvoiceItemKey;

                    int invoice_item_key = _invoice_item_repo.Save(inv_item_data);
                    Log.Info($"Order Item [{invoice_item_key}] saved to the database sucessfully!");
                }

                Log.Info($"Invoice Comments start [{invoice.Comments.Count}] items to process");
                foreach (var comment in invoice.Comments)
                {
                    comment.EntityKey = invoice_key;
                    comment.EntityTypeKey = (int)QIQOEntityType.Invoice;

                    int comment_key = _comment_be.CommentSave(comment);
                    Log.Info($"Invoice Comment [{comment_key}] saved to the database sucessfully!");
                }

                return invoice_key;
            }));
        }