public ActionResult Edit(int?id, EmployeeEditContactInfo newItem) { //Validate the input if (!ModelState.IsValid) { //"Version1" approach is to display the "edit form" again return(RedirectToAction("edit", new { id = newItem.EmployeeId })); } if (id.GetValueOrDefault() != newItem.EmployeeId) { //this appears to be data tampering, so redirect the user away return(RedirectToAction("index")); } //Attempt to do the update var editedItem = m.EmployeeEditContactInfo(newItem); if (editedItem == null) { //There was a problem updating the object //Our "version1" approach is to display the "edit form" again return(RedirectToAction("edit", new { id = newItem.EmployeeId })); } else { //Show the details view, which will show the updated data return(RedirectToAction("details", new { id = newItem.EmployeeId })); } }
public EmployeeBase EmployeeEditContactInfo(EmployeeEditContactInfo newEmployee) { //fetch data to display for GET var e = ds.Employees.Find(newEmployee.EmployeeId); //Check if fetching was successful if (e == null) { return(null); } else { //Replace the current data with new data ds.Entry(e).CurrentValues.SetValues(newEmployee); ds.SaveChanges(); //return the employeeBase using mapper return(mapper.Map <Employee, EmployeeBase>(e)); } }