/// <summary> /// Delete permanently a department. /// </summary> /// <param name="departmentId">Id of the department that you want to delete.</param> public void DeleteDepartment(Guid departmentId) { try { if (GetNumberOfEmployees(departmentId, false) == 0) { EmployeeBusiness EB = new EmployeeBusiness(); List<Employee> listEmployee = EB.GetEmployees(departmentId, true); if (listEmployee.Count > 0) { foreach (Employee item in listEmployee) { EB.DeleteEmployee(item.Employee_Id); } } Department department = DD.GetDepartment(departmentId); int result = DD.DeleteDepartment(department); if (result == -1) { throw new Exception("An error occurred while executing this operation."); } } else { throw new Exception(String.Format("Remaining {0} employees in this department. You could not delete it.", GetNumberOfEmployees(departmentId,false))); } } catch (Exception ex) { throw new Exception(ex.Message); } }
/// <summary> /// Delete permanently a department. /// </summary> /// <param name="departmentId">Id of the department that you want to delete.</param> public void DeleteDepartment(Guid departmentId) { try { if (GetNumberOfEmployees(departmentId, false) == 0) { EmployeeBusiness EB = new EmployeeBusiness(); List <Employee> listEmployee = EB.GetEmployees(departmentId, true); if (listEmployee.Count > 0) { foreach (Employee item in listEmployee) { EB.DeleteEmployee(item.Employee_Id); } } Department department = DD.GetDepartment(departmentId); int result = DD.DeleteDepartment(department); if (result == -1) { throw new Exception("An error occurred while executing this operation."); } } else { throw new Exception(String.Format("Remaining {0} employees in this department. You could not delete it.", GetNumberOfEmployees(departmentId, false))); } } catch (Exception ex) { throw new Exception(ex.Message); } }