public int OrderSave(Order order_header)
        {
            if (order_header == null)
            {
                throw new ArgumentNullException(nameof(order_header));
            }

            return(ExecuteFaultHandledOperation(() =>
            {
                int order_header_key;
                var order_data = _order_se.Map(order_header);

                order_data.OrderItemCount = order_header.OrderItems.Sum(item => item.OrderItemQuantity);
                order_data.OrderValueSum = order_header.OrderItems.Sum(item => item.OrderItemLineSum);
                //order_data.OrderShipDate = order_header.OrderItems.Min(item => item.OrderItemShipDate).GetValueOrDefault();
                order_header_key = _order_header_repo.Save(order_data);

                Log.Info($"Order Item start [{order_header.OrderItems.Count}] items to process");
                foreach (var order_item in order_header.OrderItems)
                {
                    var order_item_data = _order_item_se.Map(order_item);
                    //Log.Info($"Order Item converted [{order_item_data.ProductName}] sucessfully!");
                    order_item_data.OrderKey = order_header_key;
                    order_item_data.OrderItemKey = order_item.OrderItemKey;

                    int order_item_key = _order_item_repo.Save(order_item_data);
                    Log.Info($"Order Item [{order_item_key}] saved to the database sucessfully!");
                }

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

                    int comment_key = _comment_be.CommentSave(comment);
                    Log.Info($"Order Comment [{comment_key}] saved to the database sucessfully!");
                }
                return order_header_key;
            }));
        }
Example #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;
            }));
        }
Example #3
0
        public int AccountSave(Account account)
        {
            if (account == null)
            {
                throw new ArgumentNullException(nameof(account));
            }

            return(ExecuteFaultHandledOperation(() =>
            {
                var acct = _acct_es.Map(account);

                int account_key = _acct_repo.Insert(acct);

                if (account.Addresses != null)
                {
                    Log.Info($"Account addresses to be saved -> {account.Addresses.Count}");
                    foreach (Address address in account.Addresses)
                    {
                        try
                        {
                            address.EntityKey = account_key;
                            address.EntityType = QIQOEntityType.Account;
                            int addr_key = _address_be.AddressSave(address);
                        }
                        catch (Exception ex)
                        {
                            Log.Error("Error saving account address data to the database");
                            Log.Error($"{ex.Source}:{ex.Message}");
                            throw ex;
                        }
                    }
                }

                if (account.AccountAttributes != null)
                {
                    Log.Info($"Account attributes to be saved -> {account.AccountAttributes.Count}");
                    foreach (EntityAttribute attribute in account.AccountAttributes)
                    {
                        try
                        {
                            attribute.EntityKey = account_key;
                            attribute.EntityType = QIQOEntityType.Account;
                            int attr_key = _entity_attribute_be.EntityAttributeUpdate(attribute);
                        }
                        catch (Exception ex)
                        {
                            Log.Error("Error saving account attribute data to the database");
                            Log.Error($"{ex.Source}:{ex.Message}");
                            throw ex;
                        }
                    }
                }

                if (account.FeeSchedules != null)
                {
                    Log.Info("Account fee schedules to be saved -> {0}", account.FeeSchedules.Count);
                    foreach (FeeSchedule fee_schedule in account.FeeSchedules)
                    {
                        try
                        {
                            fee_schedule.AccountKey = account_key;
                            int fee_key = _fee_schedule_be.FeeScheduleSave(fee_schedule);
                        }
                        catch (Exception ex)
                        {
                            Log.Error("Error saving account fee schedules data to the database");
                            Log.Error($"{ex.Source}:{ex.Message}");
                            throw ex;
                        }
                    }
                }

                if (account.Employees != null)
                {
                    Log.Info($"Account employee(s) to be saved -> {account.Employees.Count}");
                    foreach (AccountPerson employee in account.Employees)
                    {
                        try
                        {
                            account.AccountKey = account_key;
                            int emp_key = _account_employee_be.EmployeeSave(account, employee, "Account Employee", "No comment");
                        }
                        catch (Exception ex)
                        {
                            Log.Error("Error saving account employee data to the database");
                            Log.Error($"{ex.Source}:{ex.Message}");
                            throw ex;
                        }
                    }
                }

                if (account.Contacts != null)
                {
                    Log.Info($"Account contact(s) to be saved -> {account.Contacts.Count}");
                    foreach (Contact contact in account.Contacts)
                    {
                        try
                        {
                            contact.EntityKey = account_key;
                            int emp_key = _contact_be.ContactSave(contact);
                        }
                        catch (Exception ex)
                        {
                            Log.Error("Error saving account contact data to the database");
                            Log.Error($"{ex.Source}:{ex.Message}");
                            throw ex;
                        }
                    }
                }

                if (account.Comments != null)
                {
                    Log.Info($"Account Comment(s) start [{account.Comments.Count}] items to process");
                    foreach (var comment in account.Comments)
                    {
                        comment.EntityKey = account_key;
                        comment.EntityTypeKey = (int)QIQOEntityType.Account;

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

                return account_key;
            }));
        }