public int CompanySave(Company company)
        {
            if (company == null)
            {
                throw new ArgumentNullException(nameof(company));
            }

            return(ExecuteFaultHandledOperation(() =>
            {
                var company_data = _comp_es.Map(company);
                int company_key = _company_repo.Insert(company_data);

                if (company.CompanyAttributes != null)
                {
                    Log.Info($"Company attributes to be saved -> {company.CompanyAttributes.Count}");
                    foreach (EntityAttribute attribute in company.CompanyAttributes)
                    {
                        attribute.EntityKey = company_key;
                        attribute.EntityType = QIQOEntityType.Company;
                        int attr_key = _entity_attrib_be.EntityAttributeUpdate(attribute);
                    }
                }

                if (company.Employees != null)
                {
                    Log.Info($"Company employees to be saved -> {company.Employees.Count}");
                    foreach (Employee employee in company.Employees)
                    {
                        int emp_key = _person_respository.Insert(_pers_es.Map(employee));
                        int ep_key = AddEmployee(company, employee, employee.RoleInCompany, employee.Comment);
                    }
                }

                if (company.GLAccounts != null)
                {
                    Log.Info($"Company chart of accounts to be saved -> {company.GLAccounts.Count}");
                    foreach (ChartOfAccount coa in company.GLAccounts)
                    {
                        int coa_key = _coa_be.ChartOfAccountSave(coa);
                    }
                }

                if (company.CompanyAddresses != null)
                {
                    Log.Info($"Company addresses to be saved -> {company.CompanyAddresses.Count}");
                    foreach (Address addr in company.CompanyAddresses)
                    {
                        int address_key = _address_be.AddressSave(addr);
                    }
                }

                return company_key;
            }));
        }
Ejemplo n.º 2
0
        public int EmployeeSave(Employee employee)
        {
            if (employee == null)
            {
                throw new ArgumentNullException(nameof(employee));
            }

            int person_key;

            return(ExecuteFaultHandledOperation(() =>
            {
                var person = _pers_es.Map(employee);
                person.PersonKey = employee.PersonKey;

                person_key = _person_repo.Insert(person);
                Log.Info($"Employee [{person_key}] saved to the database sucessfully!");

                if (employee.Addresses != null)
                {
                    Log.Info($"Employee addresses to be saved -> {employee.Addresses.Count}");
                    foreach (Address address in employee.Addresses)
                    {
                        address.EntityKey = person_key;
                        address.EntityType = QIQOEntityType.Person;
                        int addr_key = _address_be.AddressSave(address);
                    }
                }

                if (employee.PersonAttributes != null)
                {
                    Log.Info($"Employee attributes to be saved -> {employee.PersonAttributes.Count}");
                    foreach (EntityAttribute attribute in employee.PersonAttributes)
                    {
                        attribute.EntityKey = person_key;
                        attribute.EntityType = QIQOEntityType.Person;
                        int attr_key = _entity_attrib_be.EntityAttributeUpdate(attribute);
                    }
                }

                SaveEmployeeSupervisor(employee);
                return person_key;
            }));
        }
Ejemplo n.º 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;
            }));
        }
        public int CreateAddress(Address address)
        {
            IAddressBusinessEngine address_be = _business_engine_factory.GetBusinessEngine <IAddressBusinessEngine>();

            return(address_be.AddressSave(address));
        }