public ProgramBase EditProgram(ProgramBase newItem) { var fetchedObject = ds.Program.Find(newItem.Id); if (fetchedObject == null) { return null; } else { ds.Entry(fetchedObject).CurrentValues.SetValues(newItem); ds.SaveChanges(); // Prepare and return the object return Mapper.Map<ProgramBase>(fetchedObject); } }
public ActionResult Edit(int id, ProgramBase newItem) { if (ModelState.IsValid & id == newItem.Id) { // Attempt to update the item ProgramBase editedItem = m.EditProgram(newItem); if (editedItem == null) { // There was a problem updating the object return View(newItem); } else { //item was edited TempData["statusMessage"] = "Edits have been saved."; return RedirectToAction("details", new { id = editedItem.Id }); } } else { // Return the object so the user can edit it correctly return View(newItem); } }