예제 #1
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;
            }));
        }
예제 #2
0
        public int CreateFeeSchedule(FeeSchedule fee_schedule)
        {
            IFeeScheduleBusinessEngine fee_schedule_be = _business_engine_factory.GetBusinessEngine <IFeeScheduleBusinessEngine>();

            return(fee_schedule_be.FeeScheduleSave(fee_schedule));
        }