public ActionResult Edit(int?id, TrackEdit newItem) { // Validate input if (!ModelState.IsValid) { return(RedirectToAction("edit", new { id = newItem.Id })); } if (id.GetValueOrDefault() != newItem.Id) { return(RedirectToAction("index")); } var editedItem = m.TrackEdit(newItem); if (editedItem == null) { return(RedirectToAction("edit", new { id = newItem.Id })); } else { return(RedirectToAction("details", new { id = newItem.Id })); } }
public TrackWithDetail TrackEdit(TrackEdit newItem) { var o = ds.Tracks.Include("Albums") .SingleOrDefault(v => v.Id == newItem.Id); if (o == null) { return(null); } else { ds.Entry(o).CurrentValues.SetValues(newItem); ds.SaveChanges(); return(Mapper.Map <Track, TrackWithDetail>(o)); } }