public bool EmployeeDelete(Account account, AccountPerson employee)
        {
            if (account == null)
            {
                throw new ArgumentNullException(nameof(account));
            }
            if (employee == null)
            {
                throw new ArgumentNullException(nameof(employee));
            }

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

                EntityPersonData ep_data = new EntityPersonData()
                {
                    EntityKey = account.AccountKey,
                    EntityTypeKey = 3, // Account
                    PersonKey = employee.PersonKey,
                    PersonTypeKey = employee.PersonTypeData.PersonTypeKey,
                    EntityPersonSeq = 1 // default; not used
                };

                _entity_person_repo.DeleteByObject(ep_data);
                _person_repo.Delete(person);

                return true;
            }));
        }
        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;
            }));
        }
Пример #3
0
        public List <PersonType> GetTypes()
        {
            return(ExecuteFaultHandledOperation(() =>
            {
                List <PersonType> person_types = _cache.Get(CacheKeys.PersonTypes) as List <PersonType>;
                if (person_types == null)
                {
                    Log.Debug("PersonTypeRepository GetAll called");
                    person_types = new List <PersonType>();
                    var person_type_data = _repo_prod_type.GetAll();

                    foreach (var account_type in person_type_data)
                    {
                        person_types.Add(_prod_es.Map(account_type));
                    }

                    _cache.Set(CacheKeys.PersonTypes, person_types);
                    Log.Debug("PersonTypeRepository GetAll complete");
                }
                return person_types;
            }));
        }
Пример #4
0
        public List <Employee> GetEmployeesByCompany(Company company)
        {
            if (company == null)
            {
                throw new ArgumentNullException(nameof(company));
            }

            return(ExecuteFaultHandledOperation(() =>
            {
                var employees = new List <Employee>();
                var comp = new CompanyData()
                {
                    CompanyKey = company.CompanyKey
                };

                var emps_data = _entity_person_repo.GetAll(comp);

                foreach (EntityPersonData emp_data in emps_data)
                {
                    Employee employee = _pers_es.Map(emp_data);
                    employee.PersonAttributes = _entity_attrib_be.GetAttributeByEntity(employee.PersonKey, QIQOEntityType.Person);
                    employee.Addresses = _address_be.GetAddressesByEntityID(employee.PersonKey, QIQOEntityType.Person);

                    //employee.Companies = compHelper.GetCompaniesByEmployee(employee); // CAUSES Stack Overflow - of sorts HERE

                    PersonData ent_per = _person_repo.GetByID(employee.PersonKey);

                    //GetEmployeeSupervisor(employee);
                    _pers_es.InitPersonData(employee, ent_per);

                    //Log.Info("Employee: {0}; Role: {1}; Type: {2}; EntityPersonKey {3}", employee.PersonLastName,
                    //    employee.RoleInCompany, employee.CompanyRoleType, employee.EntityPersonKey);

                    employees.Add(employee);
                }
                return employees;
            }));
        }