コード例 #1
0
        public async Task <ActionResult> MyLeaves(int id)
        {
            var employee = await _userManager.GetUserAsync(User);

            var employeeVM = _mapper.Map <EmployeeVM>(employee);

            try
            {
                var leaveRequests = await _leaveRequestRepo.FindByEmployeeId(employee.Id);

                var leaveRequestsVM = _mapper.Map <List <LeaveRequestVM> >(leaveRequests);

                var leaveAllocations = await _leaveAllocRepo.FindByEmployeeId(employee.Id);

                var leaveAllocationsVM = _mapper.Map <List <LeaveAllocationVM> >(leaveAllocations);
                var model = new EmployeeLeaveRequestsVM
                {
                    RequestingEmployee   = employeeVM,
                    RequestingEmployeeId = employee.Id,
                    LeaveRequests        = leaveRequestsVM,
                    LeaveAllocations     = leaveAllocationsVM
                };
                return(View(model));
            }
            catch {
                var model = new EmployeeLeaveRequestsVM
                {
                    RequestingEmployee   = employeeVM,
                    RequestingEmployeeId = employee.Id,
                    LeaveRequests        = null,
                    LeaveAllocations     = null
                };
                return(View(model));
            }
        }