Beispiel #1
0
        public async Task <ActionResult> CancelRequest(int id)
        {
            try
            {
                var leaveRequest = await _leaveRequestRepo.FindById(id);

                var allocation = await _allocationsRepo.GetLeaveAllocationsByEmployeeAndType(leaveRequest.RequestingEmployeeId, leaveRequest.LeaveTypeId);

                var user   = _userManager.GetUserAsync(User).Result;
                var userId = user.Id;

                int daysRequested = (int)(leaveRequest.EndDate - leaveRequest.StartDate).TotalDays;
                allocation.NumberOfDays += daysRequested;

                leaveRequest.Cancelled           = true;
                leaveRequest.CancellationStaffId = userId;

                await _leaveRequestRepo.Update(leaveRequest);

                await _allocationsRepo.Update(allocation);

                return(RedirectToAction("MyLeave"));
            }
            catch (Exception)
            {
                return(RedirectToAction("MyLeave"));
            }
        }
        // GET: LeaveRequestController1/Details/5
        public ActionResult Details(int id)
        {
            var leaveRequest = _leaveRequestRepository.FindById(id);
            var model        = _mapper.Map <LeaveRequestViewModel>(leaveRequest);

            return(View(model));
        }
        public async Task <ActionResult> ApproveRequest(int id)
        {
            try
            {
                var user = await _userManager.GetUserAsync(User);

                var leaveRequests = await _leaveRequestRepository.FindById(id);

                var allocation = await _leaveAllocationRepository.GetLeaveAllocationByEmployeeAndType(
                    leaveRequests.RequestingEmployeeId, leaveRequests.LeaveTypeId);

                int dateRequested = (int)(leaveRequests.EndDate - leaveRequests.StartDate).TotalDays;

                allocation.NumberOfDays -= dateRequested;

                leaveRequests.Approved     = true;
                leaveRequests.ApprovedById = _userManager.GetUserAsync(User).Result.Id;
                leaveRequests.DateActioned = DateTime.Now;

                await _leaveRequestRepository.Update(leaveRequests);

                await _leaveAllocationRepository.Update(allocation);

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception)
            {
                return(RedirectToAction(nameof(Index), "Home"));
            }
        }
Beispiel #4
0
        // GET: LeaveRequestController/Details/5
        public async Task <ActionResult> Details(int id)
        {
            var leaveRequest = await _leaveRequestRepo.FindById(id);

            var model = _mapper.Map <LeaveRequestVM>(leaveRequest);

            return(View(model));
        }
        // GET: LeaveRequestController/Details/5
        public async Task <ActionResult> Details(int id)
        {
            var obj = await _leaveRequestRepo.FindById(id);

            var objvm = _mapper.Map <LeaveRequestVm>(obj);

            return(View(objvm));
        }
Beispiel #6
0
        public async Task <ActionResult> CancelRequest(int id)
        {
            var leaveDeatails = await _leaveRequestrepo.FindById(id);

            leaveDeatails.Cancelled = true;
            await _leaveRequestrepo.Update(leaveDeatails);

            /*if (leaveDeatails.Approved == true)
             * {
             *  var totalDays = (leaveDeatails.endDate.Date - leaveDeatails.startDate.Date).Days;
             *  var leavetypeId = leaveDeatails.LeaveTypeId;
             *  var empid = leaveDeatails.requestEmployeeid;
             *
             *  var leaveAllocationData = _leavaAllocRepo.getLeaveAllocationDetailonLeaveTypeId(empid, leavetypeId);
             *  leaveAllocationData.NumberOfDays += totalDays;
             *  _leavaAllocRepo.Update(leaveAllocationData);
             *
             * }*/

            return(RedirectToAction("MyLeave"));
        }
        public async Task <ActionResult> ApproveRequest(int id)
        {
            try
            {
                var user         = _userManager.GetUserAsync(User).Result;
                var leaveRequest = await _leaveRequestRepo.FindById(id);

                var employeeid  = leaveRequest.RequestingEmployeeId;
                var leaveTypeId = leaveRequest.LeaveTypeId;
                //var leaveAllocation =await _leaveAllocationrepo.GetLeaveAllocationsByEmployeeAndType(employeeid, leaveTypeId);
                var period          = DateTime.Now.Year;
                var leaveAllocation = await _unitOfWork.LeaveAllocations.Find(q => q.EmployeeId == employeeid && q.Period == period && q.LeaveTypeId == leaveTypeId);

                int daysRequested = (int)(leaveRequest.EndDate - leaveRequest.StartDate).TotalDays;
                leaveAllocation.NumberOfDays = leaveAllocation.NumberOfDays - daysRequested;


                leaveRequest.Approved     = true;
                leaveRequest.ApprovedById = user.Id;
                leaveRequest.DateActioned = DateTime.Now;

                //await _leaveRequestRepo.Update(leaveRequest);
                //await _leaveAllocationrepo.Update(leaveAllocation);

                _unitOfWork.LeaveRequests.Update(leaveRequest);
                _unitOfWork.LeaveAllocations.Update(leaveAllocation);
                await _unitOfWork.Save();


                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception)
            {
                return(RedirectToAction(nameof(Index)));
            }
        }
        // GET: LeaveRequest/Details/5
        public ActionResult Details(int id)
        {
            var model = _mapper.Map <LeaveRequestVM>(_requestRepo.FindById(id));

            return(View(model));
        }
Beispiel #9
0
        // GET: LeaveRequestsController/Details/5
        public ActionResult Details(int id)
        {
            var model = _mapper.Map <LeaveRequestViewModel>(_repo.FindById(id.ToString()));

            return(View(model));
        }