private decimal Pay(
            IOrganizationalUnit unit,
            decimal paid,
            int depth)
        {
            foreach (var dep in unit.SubUnits)
            {
                paid += this.Pay(dep, 0, depth + 1);
            }

            foreach (var emp in unit.Employees)
            {
                decimal percents = (15 - depth) * 0.01m;
                paid += emp.RecieveSalary(percents, this.ceo.Salary);
            }

            this.output.Insert(0,
                               string.Format("{0}{1} ({2:f2})\n",
                                             new String(' ', depth * 4),
                                             unit.Name,
                                             paid
                                             )
                               );

            return(paid);
        }
        private decimal Pay(
            IOrganizationalUnit unit, 
            decimal paid, 
            int depth)
        {
            foreach (var dep in unit.SubUnits)
            {
                paid += this.Pay(dep, 0, depth + 1);
            }

            foreach (var emp in unit.Employees)
            {
                decimal percents = (15 - depth) * 0.01m;
                paid += emp.RecieveSalary(percents, this.ceo.Salary);
            }

            this.output.Insert(0,
                    string.Format("{0}{1} ({2:f2})\n",
                        new String(' ', depth * 4),
                        unit.Name,
                        paid
                        )
                    );

            return paid;
        }
Exemple #3
0
        public override string Execute()
        {
            var company = this.db.Companies.Cast <Company>().FirstOrDefault(c => c.Name == this.companyName);

            if (company == null)
            {
                throw new ArgumentException(
                          string.Format("Company {0} does not exist", this.companyName));
            }

            foreach (var e in company.AllEmployees)
            {
                if (e.FirstName == this.firstName && e.LastName == this.lastName)
                {
                    if (e.InUnit is Company)
                    {
                        throw new ArgumentException(
                                  string.Format(
                                      "Employee {0} {1} already exists in {2} (no department)",
                                      this.firstName,
                                      this.lastName,
                                      this.companyName
                                      ));
                    }
                    throw new ArgumentException(
                              string.Format(
                                  "Employee {0} {1} already exists in {2} (in department {3})",
                                  this.firstName,
                                  this.lastName,
                                  this.companyName,
                                  e.InUnit.Name
                                  ));
                }
            }

            IOrganizationalUnit inUnit = company;

            if (this.departmentName != null)
            {
                foreach (var d in company.AllDepartments)
                {
                    if (d.Name == this.departmentName)
                    {
                        inUnit = d;
                        break;
                    }
                }
            }

            var employee = EmployeeFactory.Create(
                this.firstName,
                this.lastName,
                this.position,
                inUnit
                );

            company.AllEmployees.Add(employee);
            inUnit.AddEmployee(employee);
            return("");
        }
 public Employee(
     string firstName, 
     string lastName, 
     IOrganizationalUnit inUnit,
     decimal salaryFactor)
 {
     this.FirstName = firstName;
     this.LastName = lastName;
     this.InUnit = inUnit;
     this.SalaryFactor = salaryFactor;
 }
Exemple #5
0
 public Employee(
     string firstName,
     string lastName,
     IOrganizationalUnit inUnit,
     decimal salaryFactor)
 {
     this.FirstName    = firstName;
     this.LastName     = lastName;
     this.InUnit       = inUnit;
     this.SalaryFactor = salaryFactor;
 }
 private void PrintHierarchy(IOrganizationalUnit unit, int depth)
 {
     Console.WriteLine("{0}({1})", new String(' ', depth * 4), unit.Name);
     foreach (IEmployee employee in unit.Employees)
     {
         Console.WriteLine("{0}{1} {2} ({3:f2})", new String(' ', depth * 4), employee.FirstName, employee.LastName, employee.TotalPaid);
     }
     foreach (IOrganizationalUnit subUnit in unit.SubUnits)
     {
         this.PrintHierarchy(subUnit, depth + 1);
     }
 }
 private void PrintHierarchy(IOrganizationalUnit unit, int depth)
 {
     Console.WriteLine("{0}({1})", new String(' ', depth * 4), unit.Name);
     foreach (IEmployee employee in unit.Employees)
     {
         Console.WriteLine("{0}{1} {2} ({3:f2})", new String(' ', depth * 4), employee.FirstName, employee.LastName, employee.TotalPaid);
     }
     foreach (IOrganizationalUnit subUnit in unit.SubUnits)
     {
         this.PrintHierarchy(subUnit, depth + 1);
     }
 }
        public override string Execute()
        {
            IOrganizationalUnit company = this.db.Companies.FirstOrDefault(c => c.Name == this.companyName);

            if (company == null)
            {
                throw new ArgumentException(
                          string.Format("Company {0} does not exist", this.companyName));
            }
            ceo = (CEO)company.Head;
            PrintHierarchy(company, 0);
            return("");
        }
 public static IEmployee Create(string firstName, string lastName, string position, IOrganizationalUnit inUnit, decimal salary = 0)
 {
     switch (position)
     {
         case "CEO":
             return new CEO(firstName, lastName, inUnit, salary);
         case "Manager":
             return new Manager(firstName, lastName, inUnit);
         case "Regular":
             return new Regular(firstName, lastName, inUnit);
         case "Salesman":
             return new Salesman(firstName, lastName, inUnit);
         case "CleaningLady":
             return new CleaningLady(firstName, lastName, inUnit);
         case "ChiefTelephoneOfficer":
             return new ChiefTelephoneOfficer(firstName, lastName, inUnit);
         case "Accountant":
             return new Accountant(firstName, lastName, inUnit);
         default:
             throw new NotSupportedException("Invalid position supplied");
     }
 }
 public CEO(string firstName, string lastName, IOrganizationalUnit inUnit, decimal salary)
     : base(firstName, lastName, inUnit, SalaryFactorDefault)
 {
     this.Salary = salary;
 }
 public CleaningLady(string firstName, string lastName, IOrganizationalUnit inUnit)
     : base(firstName, lastName, inUnit, SalaryFactorDefault)
 {
 }
Exemple #12
0
        public static IEmployee Create(string firstName, string lastName, string position, IOrganizationalUnit inUnit,
                                       decimal salary = 0)
        {
            switch (position)
            {
            case "CEO":
                return(new CEO(firstName, lastName, inUnit, salary));

            case "Manager":
                return(new Manager(firstName, lastName, inUnit));

            case "Regular":
                return(new Regular(firstName, lastName, inUnit));

            case "Salesman":
                return(new Salesman(firstName, lastName, inUnit));

            case "CleaningLady":
                return(new CleaningLady(firstName, lastName, inUnit));

            case "ChiefTelephoneOfficer":
                return(new ChiefTelephoneOfficer(firstName, lastName, inUnit));

            case "Accountant":
                return(new Accountant(firstName, lastName, inUnit));

            default:
                throw new NotSupportedException("Invalid position supplied");
            }
        }
 public CEO(string firstName, string lastName, IOrganizationalUnit inUnit, decimal salary)
     : base(firstName, lastName, inUnit, SalaryFactorDefault)
 {
     this.Salary = salary;
 }
Exemple #14
0
 public void AddCompany(IOrganizationalUnit company)
 {
     this.companies.Add(company);
 }
 public bool IsInOrganizationalUnit(IOrganizationalUnit orgUnit)
 {
     return PermissionEvaluator.Instance.IsInGroup(this._userId, orgUnit.Id);
 }
 public void AddCompany(IOrganizationalUnit company)
 {
     this.companies.Add(company);
 }
Exemple #17
0
 public bool IsInOrganizationalUnit(IOrganizationalUnit orgUnit)
 {
     throw new InvalidOperationException("The SYSTEM user is not a member of any organizational unit.");
 }
Exemple #18
0
 public bool IsInOrganizationalUnit(IOrganizationalUnit orgUnit)
 {
     return(Security.IsInGroup(orgUnit.Id));
 }
Exemple #19
0
 public void AddSubUnit(IOrganizationalUnit unit)
 {
     this.subUnits.Add(unit);
 }
Exemple #20
0
 public bool IsInOrganizationalUnit(IOrganizationalUnit orgUnit)
 {
     return Security.IsInGroup(orgUnit.Id);
 }
Exemple #21
0
 public void SetPermission(IOrganizationalUnit orgUnit, bool isInheritable, PermissionType permissionType, PermissionValue permissionValue)
 {
     if (orgUnit == null)
         throw new ArgumentNullException("orgUnit");
     SetPermission(orgUnit as ISecurityMember, isInheritable, permissionType, permissionValue);
 }
 public void AddSubUnit(IOrganizationalUnit unit)
 {
     this.subUnits.Add(unit);
 }
Exemple #23
0
 public bool IsInOrganizationalUnit(IOrganizationalUnit orgUnit)
 {
     return(SecurityHandler.IsInGroup(this.Id, orgUnit.Id));
 }
Exemple #24
0
 public void Add(IOrganizationalUnit organizationalUnit) => this.organizationalUnits.Add(organizationalUnit);
 public ChiefTelephoneOfficer(string firstName, string lastName, IOrganizationalUnit inUnit)
     : base(firstName, lastName, inUnit, SalaryFactorDefault)
 {
 }
Exemple #26
0
 public bool IsInOrganizationalUnit(IOrganizationalUnit orgUnit)
 {
     throw new NotImplementedException();
 }
Exemple #27
0
 public Salesman(string firstName, string lastName, IOrganizationalUnit inUnit)
     : base(firstName, lastName, inUnit, SalaryFactorDefault)
 {
 }
 public Accountant(string firstName, string lastName, IOrganizationalUnit inUnit)
     : base(firstName, lastName, inUnit, SalaryFactorDefault)
 {
 }
        public override string Execute()
        {
            Company company = null;

            foreach (Company c
                     in this.db.Companies)
            {
                if (c.Name == this.companyName)
                {
                    company = c;
                    break;
                }
            }

            if (company == null)
            {
                throw new ArgumentException(
                          string.Format("Company {0} does not exist", this.companyName));
            }


            IEmployee           manager        = null;
            IOrganizationalUnit mainDepartment = null;

            if (this.mainDepartmentName == null)
            {
                foreach (var employee in company.Employees)
                {
                    if (employee.FirstName == this.managerFirstName && employee.LastName == this.managerLastName)
                    {
                        manager = employee;
                        break;
                    }
                }

                if (manager == null)
                {
                    throw new ArgumentException(
                              string.Format(
                                  "There is no employee called {0} {1} in company {2}",
                                  this.managerFirstName,
                                  this.managerLastName,
                                  this.companyName
                                  ));
                }
            }
            else
            {
                foreach (var d in company.AllDepartments)
                {
                    if (d.Name == this.mainDepartmentName)
                    {
                        mainDepartment = d;
                        break;
                    }
                }

                if (mainDepartment == null)
                {
                    throw new ArgumentException(
                              string.Format(
                                  "There is no department {0} in {1}",
                                  this.mainDepartmentName,
                                  this.companyName
                                  ));
                }

                foreach (var employee in mainDepartment.Employees)
                {
                    if (employee.FirstName == this.managerFirstName && employee.LastName == this.managerLastName)
                    {
                        manager = employee;
                        break;
                    }
                }

                if (manager == null)
                {
                    throw new ArgumentException(
                              string.Format(
                                  "There is no employee called {0} {1} in department {2}",
                                  this.managerFirstName,
                                  this.managerLastName,
                                  this.mainDepartmentName
                                  ));
                }
            }

            if (!(manager is Manager))
            {
                var realPosition = manager.GetType().Name;
                throw new TypeLoadException(
                          string.Format(
                              "{0} {1} is not a manager (real position: {2})",
                              this.managerFirstName,
                              this.managerLastName,
                              realPosition));
            }

            foreach (var d in company.SubUnits)
            {
                if (d.Name == this.departmentName)
                {
                    throw new ArgumentException(
                              string.Format(
                                  "Department {0} already exists in {1}",
                                  this.departmentName,
                                  this.companyName
                                  )
                              );
                }
            }


            IOrganizationalUnit department = new Department(this.departmentName);

            department.Head = manager;
            //manager.InUnit = department;
            //department.AddEmployee(manager);
            if (this.mainDepartmentName != null)
            {
                mainDepartment.AddSubUnit(department);
                //mainDepartment.RemoveEmployee(manager);
            }
            else
            {
                company.AddSubUnit(department);
                //company.RemoveEmployee(manager);
            }
            company.AllDepartments.Add(department);
            return("");
        }
Exemple #30
0
 public bool IsInOrganizationalUnit(IOrganizationalUnit orgUnit)
 {
     throw new InvalidOperationException("The STARTUP user is not a member of any organizational unit.");
 }
 public ChiefTelephoneOfficer(string firstName, string lastName, IOrganizationalUnit inUnit)
     : base(firstName, lastName, inUnit, SalaryFactorDefault)
 {
 }