public ActionResult Edit(DetailsLeaveTypeVM model) { try { if (!ModelState.IsValid) { return(View(model)); } var leaveType = _mapper.Map <LeaveType>(model); //This tells the system to map the received data into the LeaveType database model var isSuccess = _repo.Update(leaveType); if (!isSuccess) { ModelState.AddModelError("", "Update was not successful"); return(View(model)); } return(RedirectToAction(nameof(Index))); } catch (Exception ex) { ModelState.AddModelError("", $"Exception: {ex.Message}"); return(View()); } }
public ActionResult Edit(int id, DetailsLeaveTypeVM model) { try { if (!ModelState.IsValid) { return(View(model)); } var _lt = _mapper.Map <DetailsLeaveTypeVM, LeaveType>(model); var success = _repo.Update(_lt); if (!success) { ModelState.AddModelError("", "Something went wrong"); return(View(model)); } return(RedirectToAction(nameof(Index))); } catch (Exception e) { return(View()); } }
public ActionResult Edit(DetailsLeaveTypeVM detailsLeaveTypeVM) { try { // TODO: Add insert logic here if (!ModelState.IsValid) { return(View(detailsLeaveTypeVM)); } var leaveType = _mapper.Map <LeaveType>(detailsLeaveTypeVM); leaveType.DateCreated = DateTime.Now; var isSuccess = _repo.Update(leaveType); if (!isSuccess) { ModelState.AddModelError("", "something went wrong.... "); return(View(detailsLeaveTypeVM)); } return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public ActionResult Delete(string id, DetailsLeaveTypeVM detailsLeaveTypeVM) { try { // TODO: Add delete logic here var leaveType = _repo.FindById(id); if (leaveType == null) { return(NotFound()); } var isSuccess = _repo.Delete(leaveType); if (!isSuccess) { ModelState.AddModelError("", "something went wrong.... "); return(View(detailsLeaveTypeVM)); } return(RedirectToAction(nameof(Index))); } catch { return(View()); } }