public void executeDelegation() { foreach (Department dept in DepartmentDAO.ListAllDepartments()) { if (DepartmentDAO.findHeadByDepartment(dept.deptcode) != null) { int headcode = DepartmentDAO.findHeadByDepartment(dept.deptcode).employeecode; if (dept.delegatecode.HasValue && dept.startdate.HasValue && dept.enddate.HasValue) { if (((DateTime)dept.startdate).CompareTo(DateTime.Now) <= 0) { if (((DateTime)dept.enddate).CompareTo(DateTime.Now) >= 0) { DepartmentDAO.executeDelegation(dept.deptcode); } else { retrieveAuthority(DepartmentDAO.findHeadByDepartment(dept.deptcode).employeecode); } } } } } }