private decimal PaySalariesToDepartment(Department department, StringBuilder output, int departmentLevel)
        {
            decimal totalMoneyPerDepartment = 0m;
            foreach (var employee in department.Employees)
            {
                this.database.TotalSalaries[employee] += employee.Salary;
                totalMoneyPerDepartment += employee.Salary;
            }

            foreach (var subDepartment in department.SubDepartment)
            {
                totalMoneyPerDepartment += PaySalariesToDepartment(subDepartment, output, departmentLevel + 1);
            }

            output.AppendFormat("{0}{1} ({2:F2})", new string(' ', 4 * departmentLevel), department.Name, totalMoneyPerDepartment).AppendLine();
            return totalMoneyPerDepartment;
        }
        private string ExecuteCreateDepartmentInCompanyCommand(ICommand command, Company company)
        {
            string managerFirstName = command.Parameters[2];
            string managerLastName = command.Parameters[3];
            var manager = company.Employees.FirstOrDefault(e => e.FirstName == managerFirstName && e.LastName == managerLastName);
            if (manager == null)
            {
                return string.Format($"There is no employee called {managerFirstName} {managerLastName} in company {company.Name}");
            }

            try
            {
                CheckEmployeeIsManager(manager);
            }
            catch (ArgumentException ex)
            {
                return ex.Message;
            }

            string departmentName = command.Parameters[1];
            if (company.Departments.Any(d => d.Name == departmentName))
            {
                return string.Format($"Department {departmentName} already exists in company {company.Name}");
            }

            var department = new Department(departmentName, manager as Manager);
            company.Departments.Add(department);

            return null;
        }
        private string ExecuteCreateSubDepartmentCommand(ICommand command, Company company)
        {
            string mainDepartmentName = command.Parameters[4];
            var mainDepartment = company.Departments.FirstOrDefault(d => d.Name == mainDepartmentName);
            if (mainDepartment == null)
            {
                return string.Format($"There is no department {mainDepartmentName} in {company.Name}");
            }
            string managerFirstName = command.Parameters[2];
            string managerLastName = command.Parameters[3];
            var manager = mainDepartment.Employees.FirstOrDefault(e => e.FirstName == managerFirstName && e.LastName == managerLastName);
            if (manager == null)
            {
                return string.Format($"There is no employee called {managerFirstName} {managerLastName} in department {mainDepartment.Name}");
            }

            if (!(manager is Manager))
            {
                string position = manager.GetType().Name;
                string realPosition = position[0].ToString();
                for (int i = 1; i < position.Length; i++)
                {
                    if (realPosition[i].ToString().ToUpper() == realPosition[i].ToString())
                    {
                        realPosition += " " + position[i];
                    }
                    else
                    {
                        realPosition += position[i];
                    }
                }

                return string.Format($"{managerFirstName} {managerLastName} is not a manager (real position: {position})");
            }

            string departmentName = command.Parameters[1];

            if (mainDepartment.SubDepartment.Any(sd => sd.Name == departmentName))
            {
                return string.Format($"Department {departmentName} already exists in {mainDepartment.Name}");
            }

            if (company.Departments.Any(d => d.Name == departmentName))
            {
                return string.Format($"Department {departmentName} already exists in {company.Name}");
            }

            var department = new Department(departmentName, manager as Manager);
            mainDepartment.SubDepartment.Add(department);

            return null;
        }
 public Manager(string firstName, string lastName, Department department)
     : base(firstName, lastName, department)
 {
     this.SubordinateEmployees = new List<IEmployee>();
 }
        private void DisplayDepartment(Department department, StringBuilder output, int departmentLevel)
        {
            output.AppendFormat("{0}({1})", new string(' ', 4 * departmentLevel), department.Name).AppendLine();
            foreach (var employee in department.Employees)
            {
                output.AppendFormat("{0}{1} {2} ({3:F2})", new string(' ', 4 * departmentLevel), employee.FirstName, employee.LastName, this.database.TotalSalaries[employee]).AppendLine();
            }

            foreach (var subDepartment in department.SubDepartment)
            {
                DisplayDepartment(subDepartment, output, departmentLevel + 1);
            }
        }
 protected Accountant(string firstName, string lastName, Department department)
     : base(firstName, lastName, department)
 {
 }
 public CleaningLady(string firstName, string lastName, Department department)
     : base(firstName, lastName, department)
 {
 }
        private string ExecuteCreateSubDepartmentCommand(ICommand command, Company company)
        {
            string mainDepartmentName = command.Parameters[4];
            var mainDepartment = GetDepartment(company, mainDepartmentName);

            if (mainDepartment == null)
            {
                return string.Format($"There is no department {mainDepartmentName} in {company.Name}");
            }

            string managerFirstName = command.Parameters[2];
            string managerLastName = command.Parameters[3];
            var manager = GetEmployeeByName(mainDepartment, managerFirstName, managerLastName);
            if (manager == null)
            {
                return string.Format($"There is no employee called {managerFirstName} {managerLastName} in department {mainDepartment.Name}");
            }

            try
            {
                CheckEmployeeIsManager(manager);
            }
            catch (ArgumentException ex)
            {
                return ex.Message;
            }

            string departmentName = command.Parameters[1];

            if (mainDepartment.SubDepartments.Any(sd => sd.Name == departmentName))
            {
                return string.Format($"Department {departmentName} already exists in {mainDepartment.Name}");
            }

            if (company.Departments.Any(d => departmentName == d.Name))
            {
                return string.Format($"Department {departmentName} already exists in {company.Name}");
            }

            var department = new Department(departmentName, manager as Manager);
            mainDepartment.SubDepartments.Add(department);
            return null;
        }
 public Employee(string firstName, string lastName, Department department)
     : base(firstName, lastName)
 {
     this.Department = department;
 }
 public Manager(string firstName, string lastName, Department department)
     : base(firstName, lastName, department)
 {
     this.SubordinateEmployees = new List <IEmployee>();
 }
 private string ExecuteCreateSubDepartmentInCompanyComand(ICommand command, Company company)
 {
     var mainDepartment = company.Departments.FirstOrDefault(d => d.Name == command.Parameters[4]);
     if (mainDepartment == null)
     {
         return String.Format("There is no department {0} in company {1}", command.Parameters[4], company.Name);
     }
     var manager = GetEmployeeByName(mainDepartment, command.Parameters[2], command.Parameters[3]);
     if (manager == null)
     {
         return String.Format("There is no employee called {0} {1} in department {3}", command.Parameters[2], command.Parameters[3], mainDepartment.Name);
     }
     try
     {
         CheckEmployeeIsManager(manager);
     }
     catch (ArgumentException ex)
     {
         return ex.Message;
     }
     if (mainDepartment.SubDepartments.Any(sd => sd.Name == command.Parameters[1]))
     {
         return String.Format("Departament {0} already exists in {2}", command.Parameters[1], mainDepartment.Name);
     }
     // if (mainDepartment.Employees.Where(e => e is Manager).Cast<Manager>().Any(m => company.Departments.Select(d => d.Manager).Contains(m)))
     if (company.Departments.Any(d => command.Parameters[1] == d.Name))
     {
         return String.Format("Departament {0} already exists in {2}", command.Parameters[1], company.Name);
     }
     var department = new Department(command.Parameters[1], manager as Manager);
     mainDepartment.SubDepartments.Add(department);
     //            company.Departments.Add(department);
     return null;
 }
        private string ExecuteCreateDepartmentInCompanyComand(ICommand command, Company company)
        {
            var manager = GetEmployeeByName(company, command.Parameters[2], command.Parameters[3]);
            if (manager == null)
            {
                return string.Format("There is no employee called {0} {1} in {3}", command.Parameters[2], command.Parameters[3], company.Name);
            }
            try
            {
                CheckEmployeeIsManager(manager);
            }
            catch (ArgumentException ex)
            {
                return ex.Message;
            }

            if (company.Departments.Any(d => d.Name == command.Parameters[1]))
            {
                return String.Format("Departament {0} already exists in {2}", command.Parameters[1], company.Name);
            }
            var department = new Department(command.Parameters[1], manager as Manager);
            company.Departments.Add(department);
            return null;
        }
 public Salesman(string firstName, string lastName, Department department)
     : base(firstName, lastName, department)
 {
 }
 public Regular(string firstName, string lastName, Department department)
     : base(firstName, lastName, department)
 {
 }