public ActionResult Index() { List<String> roles =(List<String>)Session["roles"]; List<EmployeeLeaveRequestViewModel> requestViewModelList = new List<EmployeeLeaveRequestViewModel>(); Dictionary<LeaveRequestInfo, LeaveRequestDescription> leaveRequests = new Dictionary<LeaveRequestInfo, LeaveRequestDescription>(); if (roles == null) { return RedirectToAction("Index", "Login"); } foreach (string role in roles) { if (role.Equals("Super User")) { leaveRequests = getAllLeaveRequests(db); } } if (leaveRequests.Count == 0) { leaveRequests = getLRForCurrentUser(); } foreach (KeyValuePair<LeaveRequestInfo,LeaveRequestDescription> pair in leaveRequests) { LeaveRequestInfo reqInfo = pair.Key; LeaveRequestDescription reqDesc = pair.Value; EmployeeLeaveRequestViewModel viewModel = new EmployeeLeaveRequestViewModel() { AllDayEvent = reqDesc.AllDayEvent, DeliveryManager = reqDesc.DeliveryManager, DeliveryManagerStatus = reqDesc.DeliveryManagerStatus, DepartmentManager = reqDesc.DepartmentManager, DepartmentManagerStatus = reqDesc.DepartmentManagerStatus, Description = reqDesc.Description, Employee = reqInfo.Employee, EndTime = reqDesc.EndTime, LeaveReason = reqDesc.LeaveReason, LeaveRequestID = reqInfo.LeaveRequestInfoID, StartTime = reqDesc.StartTime, DepartmentManagerComment = reqDesc.DepartmentManagerComment, DeliveryManagerComment = reqDesc.DeliveryManagerComment }; requestViewModelList.Add(viewModel); } return View(requestViewModelList.AsQueryable()); }
// GET: EmployeeLeaveRequestViewModels public ActionResult Index() { //var employeeLeaveRequestViewModels = db.LeaveRequests.Include(e => e.leaveReason).Include(e => e.deliveryManagerStatus).Include(e => e.departmentManagerStatus); List<String> roles =(List<String>)Session["roles"]; List<EmployeeLeaveRequestViewModel> requestViewModelList = new List<EmployeeLeaveRequestViewModel>(); List<LeaveRequest> leaveRequests = new List<LeaveRequest>(); foreach (string role in roles) { if (role.Equals("Super User")) { leaveRequests = db.LeaveRequests.ToList(); } } if (leaveRequests.Count == 0) { leaveRequests = getLRForCurrentUser(); } foreach (LeaveRequest req in leaveRequests) { EmployeeLeaveRequestViewModel viewModel = new EmployeeLeaveRequestViewModel() { allDayEvent = req.allDayEvent, deliveryManager = req.deliveryManager, deliveryManagerStatus = req.deliveryManagerStatus, departmentManager = req.departmentManager, departmentManagerStatus = req.departmentManagerStatus, Description = req.Description, employee = req.employee, endTime = req.endTime, leaveReason = req.leaveReason, leaveRequestID = req.leaveRequestID, startTime = req.startTime, departmentManagerComment = req.departmentManagerComment, deliveryManagerComment = req.deliveryManagerComment }; requestViewModelList.Add(viewModel); } return View(requestViewModelList.AsQueryable()); }