/// <summary> /// Method to REMOVE Department /// </summary> /// <param name="department">Department to Remove</param> public void RemoveDepartment(Department department) { Department parent = DepartmentsDb.Find(x => x.DepartmentName == department.ParentDepartment); if (parent != null) { parent.innerDepartments.Remove(department); } else { company.Clear(); } if (department.DepartmentName != DepartmentsDb.Find(x => x is Company).DepartmentName) { RemoveChildren(department); DepartmentsDb.Remove(department); } else { DepartmentsDb.Clear(); } EmployeesDB = EmployeesDB.Where(x => x.Department != department.DepartmentName).ToList(); }
/// <summary> /// Method to REMOVE Department and MOVE all it's Employees to another /// </summary> /// <param name="departmentToRemove">Department to REMOVE</param> /// <param name="departmentToAddEmployees">Department in witch MOVE</param> public void RemoveDepartment(Department departmentToRemove, Department departmentToAddEmployees) { Department parent = DepartmentsDb.Find(x => x.DepartmentName == departmentToRemove.ParentDepartment); if (parent != null) { parent.innerDepartments.Remove(departmentToRemove); } else { company.Clear(); } foreach (Employee e in EmployeesDB) { if (e.Department == departmentToRemove.DepartmentName) { e.Department = departmentToAddEmployees.DepartmentName; } } MoveChildren(departmentToRemove, departmentToAddEmployees); RemoveChildren(departmentToRemove); DepartmentsDb.Remove(departmentToRemove); }
/// <summary> /// Method to ADD Department /// </summary> /// <param name="Name">New Department Name</param> /// <param name="ParentName">New Department Parent</param> public void AddDepartment(string Name, string ParentName) { Department department = new Department(Name, ParentName); DepartmentsDb.Add(department); Department parent = DepartmentsDb.Find(x => x.DepartmentName == ParentName); parent.innerDepartments.Add(department); }