예제 #1
0
        public async Task <ActionResult> MyLeave()
        {
            var employee = await _userManager.GetUserAsync(User);


            var leaveRequests = (await _leaveRequestRepo.FindAll())
                                .Where(q => q.RequestingEmployeeId == employee.Id);
            var leaveAllocations = (await _leaveAllocationRepo.FindAll())
                                   .Where(q => q.EmployeeId == employee.Id);

            var leaveAllocationsIds = (await _leaveAllocationRepo.FindAll())
                                      .Where(q => q.EmployeeId == employee.Id.ToString())
                                      .Select(q => q.LeaveTypeId);
            var leaveTypeInfo = (await _leaveTypeRepo.FindAll())
                                .Where(q => leaveAllocationsIds.Contains(q.Id));



            var leaveRequestsVM    = _mapper.Map <List <LeaveRequestVM> >(leaveRequests);
            var leaveAllocationsVM = _mapper.Map <List <LeaveAllocationVM> >(leaveAllocations);
            var leaveTypeInfoVM    = _mapper.Map <List <LeaveTypeVM> >(leaveTypeInfo);



            var model = new EmployeeLeaveRequestViewVM
            {
                LeaveRequests    = leaveRequestsVM,
                LeaveAllocations = leaveAllocationsVM,
                LeaveTypesInfo   = leaveTypeInfoVM
            };

            return(View(model));
        }
        public ActionResult Details(string id)
        {
            var employee       = _mapper.Map <EmployeeVM>(_userManager.FindByIdAsync(id).Result);
            var leaveAllocated = _mapper.Map <List <LeaveAllocationVM> >(_leaveAllocationRepo.FindAll().Where(x => x.EmployeeId == id && x.Period == DateTime.Now.Year));
            var model          = new ViewAllocationVM
            {
                Employee        = employee,
                EmployeeId      = employee.Id,
                LeaveAllocation = leaveAllocated
            };

            //Bind the View with ViewAllocationVM
            //EmployeeId, EmployeeName, LeaveAllocationVMList
            return(View(model));
        }
예제 #3
0
        // GET: LeaveTypesController/Delete/5
        public async Task <ActionResult> Delete(int id)
        {
            if (!await _repo.isExists(id))
            {
                return(NotFound());
            }

            var leavetype = await _repo.FindById(id);

            if (leavetype == null)
            {
                return(NotFound());
            }

            var isSuccess = await _repo.Delete(leavetype);

            if (!isSuccess)
            {
                return(BadRequest());
            }

            var allocation = await _AlloRepo.FindAll();

            if (allocation != null)
            {
                var AlloToDetete = allocation.ToList().Where(Q => Q.LeaveTypeId == id);

                foreach (var item in AlloToDetete)
                {
                    await _AlloRepo.Delete(item);
                }
            }


            var request = await _requestRepo.FindAll();

            if (allocation != null)
            {
                var requestToDetete = request.ToList().Where(Q => Q.LeaveTypeId == id);

                foreach (var item in requestToDetete)
                {
                    await _requestRepo.Delete(item);
                }
            }

            return(RedirectToAction(nameof(Index)));
        }