public async Task <IActionResult> EmployeeRequests(int?period) { var currentEmployee = await _UnitOfWork.Employees.GetEmployeeAsync(User); if (currentEmployee == null) { ModelState.AddModelError("", _ControllerLocalizer["Your account not belongs to employees"]); return(Forbid()); } int currentPeriod = period == null ? DateTime.Now.Year : (int)period; var requests = (await _UnitOfWork.LeaveRequest.WhereAsync(filter: q => q.RequestingEmployeeId.Equals(currentEmployee.Id), order: o => o.OrderByDescending(el => el.RequestedDate).ThenBy(el => el.StartDate), includes: new System.Linq.Expressions.Expression <Func <LeaveRequest, object> >[] { x => x.RequestingEmployee, x => x.LeaveType, x => x.ApprouvedBy })).ToList(); Task <List <LeaveRequestDefaultViewModel> > mappingRequestsTask = Task.Run(() => _Mapper.Map <List <LeaveRequestDefaultViewModel> >(requests)); var leaveSolds = GetLeaveSolds(requests, currentEmployee); Task.WaitAll(mappingRequestsTask, leaveSolds); EmployeeLeaveRequestsViewModel viewModel = new EmployeeLeaveRequestsViewModel() { LeaveRequests = mappingRequestsTask.Result, LeaveAllocations = leaveSolds.Result }; return(View("EmployeeLeaveRequests", viewModel)); }
public ActionResult UserLeaveRequests() { var user = _userManager.GetUserAsync(User).Result; var employeeId = user.Id; var userAllocations = _leaveAllocationRepo.GetLeaveAllocationsByEmployee(employeeId); var userRequests = _leaveRequestRepo.GetLeaveRequestsByEmployee(employeeId); var userAllocationModel = _mapper.Map <List <LeaveAllocationViewModel> >(userAllocations); var userRequestModel = _mapper.Map <List <LeaveRequestViewModel> >(userRequests); var model = new EmployeeLeaveRequestsViewModel { LeaveAllocations = userAllocationModel, LeaveRequests = userRequestModel }; return(View(model)); }