public ActionResult Edit(EditLeaveAllocationViewModel model) { try { if (!ModelState.IsValid) { return(View(model)); } var allocation = _mapper.Map <LeaveAllocation>(model); allocation.Employee = _repository.GetEmployeeById(allocation.EmployeeId); allocation.LeaveType = _repository.GetLeaveTypeById(allocation.LeaveTypeId); var Success = _repository.Update(allocation); if (!Success) { ModelState.AddModelError("", "Error While Saving"); return(View(model)); } return(RedirectToAction(nameof(Details), new { id = model.EmployeeId })); } catch { return(View()); } }