public async Task <ActionResult> Edit(EditLeaveAllocationViewModel model) { try { if (!ModelState.IsValid) { return(View(model)); } var record = await _leaveallocationrepo.FindById(model.Id); record.NumberOfDays = model.NumberOfDays; var isSuccess = await _leaveallocationrepo.Update(record); if (!isSuccess) { ModelState.AddModelError("", "Error while saving"); return(View(model)); } return(RedirectToAction(nameof(Details), new { id = model.EmployeeId })); } catch { return(View(model)); } }
public ActionResult Edit(EditLeaveAllocationViewModel model) { try { if (!ModelState.IsValid) { return(View(model)); } var record = _leaveallocationrepo.FindById(model.Id); // var allocation = _mapper.Map<LeaveAllocation>(model); record.NumberOfDays = model.NumberOfDays; var success = _leaveallocationrepo.Update(record); if (!success) { ModelState.AddModelError("", "Error while Saving"); return(View(model)); } return(RedirectToAction(nameof(Details), new { id = model.EmployeeId })); } catch { return(View()); } }
public ActionResult Edit(EditLeaveAllocationViewModel model) { try { if (!ModelState.IsValid) { return(View(model)); } var record = _leaveallocationrepo.FindById(model.Id); record.NumberOfDays = model.NumberOfDays; var isSuccess = _leaveallocationrepo.Update(record); if (!isSuccess) { ModelState.AddModelError("", "Something Went Wrong..."); return(View(model)); } return(RedirectToAction(nameof(Details), new { id = model.EmployeeId })); } catch { return(View(model)); } }
public async Task <ActionResult> Edit(EditLeaveAllocationViewModel model) { try { if (!ModelState.IsValid) { return(View(model)); } /* find the original of the record we would * like to mutate. * Set the value of the field. */ var record = await _allocationrepo.FindById(model.Id); record.NumberOfDays = model.NumberOfDays; var isSuccess = await _allocationrepo.Update(record); if (!isSuccess) { ModelState.AddModelError("", "Error editing a leave allocation."); return(View(model)); } return(RedirectToAction(nameof(Details), new { id = model.EmployeeId })); } catch { return(View(model)); } }
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()); } }
public async Task <ActionResult> Edit(int id, EditLeaveAllocationViewModel model) { try { if (ModelState.IsValid) { //var record =await _leaveAllocation.FindById(model.Id); List <string> includes = new List <string> { "Employee", "LeaveType" }; var record = await _unitOfWork.LeaveAllocations.Find(q => q.Id == model.Id, includes); record.NumberOfDays = model.NumberOfDays; //if (!await _leaveAllocation.Update(record)) _unitOfWork.LeaveAllocations.Update(record); await _unitOfWork.Save(); return(RedirectToAction(nameof(Details), new { id = model.EmployeeId })); } else { return(View(model)); } } catch { return(View(model)); } }
// GET: LeaveAllocationController/Edit/5 public async Task <ActionResult> Edit(int Id) { LeaveAllocation leaveAllocation = await _leaveallocationrepo.FindById(Id); EditLeaveAllocationViewModel model = _mapper .Map <EditLeaveAllocationViewModel>(leaveAllocation); return(View(model)); }
public async Task <ActionResult> Edit(EditLeaveAllocationViewModel model) { try { if (!ModelState.IsValid) { return(View(model)); } var record = await _unitOfWork.LeaveAllocations.Find(q => q.Id == model.Id); record.NumberOfDays = model.NumberOfDays; _unitOfWork.LeaveAllocations.Update(record); await _unitOfWork.Save(); return(RedirectToAction(nameof(Details), new { id = model.EmployeeId })); } catch { return(View(model)); } }
public async Task <ActionResult> Edit(EditLeaveAllocationViewModel model) { try { if (!ModelState.IsValid) { return(View(model)); } //had to use this method, because mapping was causing an error var leaveAllocation = await _unitOfWork.LeaveAllocations.Find(allocation => allocation.Id == model.Id); leaveAllocation.NumberOfDays = model.NumberOfDays; _unitOfWork.LeaveAllocations.Update(leaveAllocation); await _unitOfWork.Save(); return(RedirectToAction(nameof(Details), new { id = model.EmployeeId })); } catch { ModelState.AddModelError("", "Error While Saving"); return(View(model)); } }