public ActionResult RejectRequest(int id) { try { var request = _repo.FindById(id.ToString()); var allocation = _leaveAllocationRepo.GetLeaveAllocationsByEmployeeIdandLeaveType(request.RequestingEmployeeId, request.LeaveTypeId, DateTime.Now.Year).FirstOrDefault(); var numberOfDays = (int)(request.EndDate.Date - request.StartDate.Date).TotalDays; var approver = _userManager.GetUserAsync(User).Result; request.Approved = false; request.ApprovedBy = approver; request.ApprovedById = approver.Id; request.DateActioned = DateTime.UtcNow; allocation.NumberofDays += numberOfDays; var op1 = _repo.Update(_mapper.Map <LeaveRequest>(request)); var op2 = _leaveAllocationRepo.Update(allocation); if (!op1 || !op2) { var errormodel = GetCreateLeaveRequestVM(); ModelState.AddModelError("", "Error during save."); } return(RedirectToAction(nameof(Index))); } catch { ModelState.AddModelError("", "An error occured."); return(RedirectToAction(nameof(Index))); } }