private LeaveRequest mapLeaveRequestViewModel(EmployeeLeaveRequestViewModel leaveRequestViewModel)
        {
            var emp = db.Employees.Find(leaveRequestViewModel.employeeID);
            var delMan = db.Employees.Find(leaveRequestViewModel.deliveryManagerID);
            var depMan = db.Employees.Find(leaveRequestViewModel.departmentManagerID);
            var lreason = db.LeaveReasons.Find(leaveRequestViewModel.leaveReasonID);

            RequestStatus initStatus = GetRequestStatusByName("Pending");

               // RequestStatus approvedStatus = GetRequestStatusByName("Approved");

            LeaveRequest newLeaveRequst = new LeaveRequest()
            {
                leaveRequestID = leaveRequestViewModel.leaveRequestID,

                employee = emp,
                allDayEvent = leaveRequestViewModel.allDayEvent,
                startTime = leaveRequestViewModel.startTime,
                endTime = leaveRequestViewModel.endTime,
                leaveReason = lreason,
                Description = leaveRequestViewModel.Description,
                deliveryManager = delMan,
                deliveryManagerComment = "",
                departmentManager = depMan,
                departmentManagerComment = "",
                departmentManagerStatus = initStatus,
                deliveryManagerStatus = initStatus

            };

            return newLeaveRequst;
        }
        private bool serverValidation(EmployeeLeaveRequestViewModel employeeLeaveRequestViewModel)
        {
            int empID = getEmployeeIDByName(employeeLeaveRequestViewModel.EmployeeName);
            int delID = getEmployeeIDByName(employeeLeaveRequestViewModel.DeliveryManagerName);
            int depID = getEmployeeIDByName(employeeLeaveRequestViewModel.DepartmentManagerName);
            if (empID == -1 || delID == -1 || depID == -1) {
                return false;
            }

            Employee emp = db.Employees.Find(getEmployeeIDByName(employeeLeaveRequestViewModel.EmployeeName));
            Employee del = db.Employees.Find(getEmployeeIDByName(employeeLeaveRequestViewModel.DeliveryManagerName));
            Employee dep = db.Employees.Find(getEmployeeIDByName(employeeLeaveRequestViewModel.DepartmentManagerName));

            return !(emp == null || del == null || dep == null);
        }
        private LeaveRequestInfo mapViewModelToLeaveRequestInfo(EmployeeLeaveRequestViewModel leaveRequestViewModel)
        {
            var emp = getEmployeeByName(leaveRequestViewModel.EmployeeName);

            LeaveRequestInfo newLeaveRequest = new LeaveRequestInfo()
            {
                LeaveRequestInfoID = leaveRequestViewModel.LeaveRequestID,
                Employee = emp,
                CreateDate = DateTime.Now,
                UpdateDate = DateTime.Now

            };
            return newLeaveRequest;
        }
        private LeaveRequestDescription mapViewModelToLeaveRequestDesc(EmployeeLeaveRequestViewModel leaveRequestViewModel, LeaveRequestInfo newLeaveRequest)
        {
            var delMan = getEmployeeByName(leaveRequestViewModel.DeliveryManagerName);//db.Employees.Find(leaveRequestViewModel.deliveryManagerID);
            var depMan = getEmployeeByName(leaveRequestViewModel.DepartmentManagerName);//db.Employees.Find(leaveRequestViewModel.departmentManagerID);
            var lreason = db.LeaveReasons.Find(leaveRequestViewModel.LeaveReasonID);

            RequestStatus initStatus = GetRequestStatusByName("Pending");

            LeaveRequestDescription lrDescription = new LeaveRequestDescription()
            {

                AllDayEvent = leaveRequestViewModel.AllDayEvent,
                StartTime = leaveRequestViewModel.StartTime,
                EndTime = leaveRequestViewModel.EndTime,
                LeaveReason = lreason,
                Description = leaveRequestViewModel.Description,
                DeliveryManager = delMan,
                DeliveryManagerComment = "",
                DepartmentManager = depMan,
                DepartmentManagerComment = "",
                DepartmentManagerStatus = initStatus,
                DeliveryManagerStatus = initStatus,
                LeaveRequestInfo = newLeaveRequest,
                CreateDate = DateTime.Now,
                UpdateDate = DateTime.Now

            };

            return lrDescription;
        }
        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());
        }