public IActionResult Upsert(int?id) { ToDoList.Models.Employee EmployeeController = new ToDoList.Models.Employee(); if (id == null) //create { return(View(EmployeeController)); } EmployeeController = _unitOfWork.Employee.Get(id.GetValueOrDefault()); //edit if (EmployeeController == null) { return(NotFound()); } return(View(EmployeeController)); }
public IActionResult Upsert(ToDoList.Models.Employee EmployeeController) //ne radi update id je uvijek 0 { if (ModelState.IsValid) { if (EmployeeController.EmployeeId == 0) { _unitOfWork.Employee.Add(EmployeeController); } else { _unitOfWork.Employee.Update(EmployeeController); } _unitOfWork.Save(); return(RedirectToAction(nameof(Index))); } return(View(EmployeeController)); }