/// <summary> /// /// </summary> /// <returns></returns> public List<PendingVacationRequestViewItem> GetPendingRequests() { String currentUserId = User.Identity.GetUserId(); List<String> statesListWithShiftPartner = new List<string> { DBQuery.AGREED, DBQuery.REJECTED_BY_DEPUTY }; List<String> statesListWithoutShiftPartner = new List<string> { DBQuery.SUBMITTED }; DBQuery dbq = new DBQuery(); var DivisionVacationRequestList = new List<PendingVacationRequestViewItem>(); var SortedDivisionVacationRequestList = new List<PendingVacationRequestViewItem>(); var EmployeeList = new List<Employee>(); EmployeeList.AddRange(dbq.SelectEmployeesOfDivision(currentUserId)); if (EmployeeList.Count() > 0) { foreach (Employee e in EmployeeList) { // look for all employees of division but Division Manager self if (!e.getEmployeeID().Equals(currentUserId)) { var vrList = new List<VacationManagement.VacationRequest>(); String requesterName = e.getFullName(); String deputyID = dbq.SelectShiftPartner(e.getEmployeeID()); int remainingVacationDays = dbq.SelectRemainingVacationDays(e.getEmployeeID()); // has shiftpartner if (!deputyID.Equals("null")) { String deputyName = dbq.SelectEmployeeFullName(deputyID); foreach (string s in statesListWithShiftPartner) { vrList.AddRange(dbq.SelectVacationRequestsInState(e.getEmployeeID(), s)); } foreach (VacationManagement.VacationRequest vr in vrList) { DivisionVacationRequestList.Add(new PendingVacationRequestViewItem(vr, requesterName, deputyName, remainingVacationDays)); } } else { String deputyName = "-"; foreach (string s in statesListWithoutShiftPartner) { vrList.AddRange(dbq.SelectVacationRequestsInState(e.getEmployeeID(), s)); } foreach (VacationManagement.VacationRequest vr in vrList) { DivisionVacationRequestList.Add(new PendingVacationRequestViewItem(vr, requesterName, deputyName, remainingVacationDays)); } } } } // Sort all Vacation Requests by Startdate, Ascending SortedDivisionVacationRequestList = DivisionVacationRequestList.OrderBy(c => c.getVacationStartDate()).ToList(); } return SortedDivisionVacationRequestList; }