コード例 #1
0
        public async Task <ActionResult> ApproveRequest(int id)
        {
            try
            {
                var user    = _userManager.GetUserAsync(User).Result;
                var request = await _leaverequestrepo.FindById(id);

                var employeeId  = request.RequestingEmployeeId;
                var leaveTypeId = request.LeaveTypeId;
                var allocation  = await _leaveallocationrepo.GetLeaveAllocationsByEmployeeAndType(employeeId, leaveTypeId);

                int daysRequested = (int)(request.EndDate - request.StartDate).TotalDays;

                allocation.NumberOfDays -= daysRequested;

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

                await _leaverequestrepo.Update(request);

                await _leaveallocationrepo.Update(allocation);

                return(RedirectToAction(nameof(Index), "LeaveRequest"));
            }
            catch (Exception ex)
            {
                return(RedirectToAction(nameof(Index), "LeaveRequest"));
            }
        }
コード例 #2
0
        public async Task <ActionResult> Edit(EditLeaveAllocationVM model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                var record = await _allocationrepo.FindById(model.Id);

                record.NumberOfDays = model.NumberOfDays;


                var isSuccess = await _allocationrepo.Update(record);

                if (!isSuccess)
                {
                    ModelState.AddModelError("", "Something went wrong");
                    return(View(model));
                }
                return(RedirectToAction(nameof(Details), new { id = model.EmployeeId }));
            }
            catch
            {
                ModelState.AddModelError("", "Something went wrong");
                return(View(model));
            }
        }