public ActionResult Delete(int id, EmployeeHistoryVM model) { try { // TODO: Adding delete logic here var empHistory = _repo.FindById(id); if (empHistory == null) { return(NotFound()); } var isSuccess = _repo.Delete(empHistory); if (!isSuccess) { return(View(model)); } return(RedirectToAction(nameof(Index))); } catch { return(View(model)); } }
public ActionResult Create(EmployeeHistoryVM model) { try { // TODO: Adding insert logic here if (!ModelState.IsValid) { return(View(model)); } var empHistory = _mapper.Map <EmployeeHistory>(model); var isSuccess = _repo.Create(empHistory); if (!isSuccess) { ModelState.AddModelError("", "There is a fault somewhere..."); return(View(model)); } return(RedirectToAction(nameof(Index))); } catch { ModelState.AddModelError("", "There is a fault somewhere..."); return(View(model)); } }
public ActionResult Edit(EmployeeHistoryVM model) { try { // TODO: Adding update logic here if (!ModelState.IsValid) // Validating the data { return(View(model)); } var empHistory = _mapper.Map <EmployeeHistory>(model); // Mapping from ViewModel to Data class and storing in variable var isSuccess = _repo.Update(empHistory); if (!isSuccess) { ModelState.AddModelError("", "There is a fault somewhere..."); return(View(model)); } return(RedirectToAction(nameof(Index))); } catch { ModelState.AddModelError("", "There is a fault somewhere..."); return(View(model)); } }