public ActionResult Edit(int?id, PlaylistEditTracks newItem) { // Validate the input if (!ModelState.IsValid) { return(RedirectToAction("edit", new { id = newItem.PlaylistId })); } if (id.GetValueOrDefault() != newItem.PlaylistId) { return(RedirectToAction("index")); } // Attempt to do the update var editedItem = m.PlaylistEditTracks(newItem); if (editedItem == null) { return(RedirectToAction("Index", new { id = newItem.PlaylistId })); } else { // Show the details view, which will have the updated data return(RedirectToAction("Details", new { id = newItem.PlaylistId })); } }
public PlaylistWithTracks PlaylistEditTracks(PlaylistEditTracks newItem) { var o = ds.Playlists.Include("Tracks").SingleOrDefault(e => e.PlaylistId == newItem.Id); if (o == null) { // Problem - object was not found, so return return(null); } else { // Update the object with the incoming values // First, clear out the existing collection o.Tracks.Clear(); // Then, go through the incoming items // For each one, add to the fetched object's collection foreach (var item in newItem.TrackIds) { var a = ds.Tracks.Find(item); o.Tracks.Add(a); } // Save changes ds.SaveChanges(); return(mapper.Map <PlaylistWithTracks>(o)); } }
public ActionResult Edit(int?id, PlaylistEditTracks newItem) { try { if (!ModelState.IsValid) { return(RedirectToAction("Edit", new { id = newItem.PlaylistId })); } if (id.GetValueOrDefault() != newItem.PlaylistId) { return(RedirectToAction("Index")); } var o = m.PlaylistEdit(newItem); if (o == null) { return(RedirectToAction("Index")); } else { return(RedirectToAction("Details", new { id = newItem.PlaylistId })); } } catch { return(View()); } }
public ActionResult Edit(int?id, PlaylistEditTracks newItem) { // Validate the input if (!ModelState.IsValid) { // Our "version 1" approach is to display the "edit form" again return(RedirectToAction("edit", new { id = newItem.PlaylistId })); } if (id.GetValueOrDefault() != newItem.PlaylistId) { // This appears to be data tampering, so redirect the user away return(RedirectToAction("index")); } // Attempt to do the upate var editedItem = m.PlaylistEditTracks(newItem); if (editedItem == null) { // There was a problem updating the object // Our "version 1" approach is to display the "edit form" again return(RedirectToAction("edit", new { id = newItem.PlaylistId })); } else { // Show the details view, which will have the updated data return(RedirectToAction("details", new { id = newItem.PlaylistId })); } }
public ActionResult Edit(int?id, PlaylistEditTracks collection) { if (!ModelState.IsValid) { return(RedirectToAction("edit", new { id = collection.PlaylistId })); } if (id.GetValueOrDefault() != collection.PlaylistId) { // This appears to be data tampering, so redirect the user away return(RedirectToAction("index")); } // Attempt to do the update var editedItem = m.PlaylistEdit(collection); if (editedItem == null) { // There was a problem updating the object // Our "version 1" approach is to display the "edit form" again return(RedirectToAction("edit", new { id = collection.PlaylistId })); } else { return(RedirectToAction("Details", new { id = collection.PlaylistId })); } }
public PlaylistWithDetails PlaylistEditTracks(PlaylistEditTracks newItem) { // Playlist edit existing // Attempt to fetch the object var o = ds.Playlists .Include("Tracks") .SingleOrDefault(p => p.PlaylistId == newItem.PlaylistId); if (o == null) { return(null); } else { // Update the object with the incoming values // First, clear out the existing collection o.Tracks.Clear(); // Then, go through the incoming items // For each one, add to the fetched object's collection foreach (var item in newItem.TrackIds) { var a = ds.Tracks.Find(item); o.Tracks.Add(a); } ds.SaveChanges(); return(Mapper.Map <PlaylistWithDetails>(o)); } }
public PlaylistWithDetails PlaylistEditTracks(PlaylistEditTracks newItem) { // Playlist edit existing // Attempt to fetch the object var o = ds.Playlists .Include("Tracks") .SingleOrDefault(p => p.PlaylistId == newItem.PlaylistId); if (o == null) { return null; } else { // Update the object with the incoming values // First, clear out the existing collection o.Tracks.Clear(); // Then, go through the incoming items // For each one, add to the fetched object's collection foreach (var item in newItem.TrackIds) { var a = ds.Tracks.Find(item); o.Tracks.Add(a); } ds.SaveChanges(); return Mapper.Map<PlaylistWithDetails>(o); } }
public PlaylistWithDetails PlaylistEdit(PlaylistEditTracks edit) { // Attempt to fetch the object var o = ds.Playlists.Include("Tracks") .SingleOrDefault(e => e.PlaylistId == edit.PlaylistId); if (o == null) { return(null); } else { o.Tracks.Clear();; foreach (var item in edit.TracksIds) { // Search through the datacontext looking for each Track in plEdit.TrackList var a = ds.Tracks.Find(item); // Add the result o.Tracks.Add(a); } // Save the changes ds.SaveChanges(); return(Mapper.Map <Playlist, PlaylistWithDetails>(o)); } }
public PlaylistWithDetail PlaylistEdit(PlaylistEditTracks newItem) { var o = ds.Playlists.Include("Tracks").SingleOrDefault(i => i.PlaylistId == newItem.PlaylistId); if (o == null) { return(null); } else { o.Tracks.Clear(); foreach (var item in newItem.TrackIds) { var a = ds.Tracks.Find(item); o.Tracks.Add(a); } ds.SaveChanges(); return(Mapper.Map <Playlist, PlaylistWithDetail>(o)); } }
public ActionResult Edit(int?id, PlaylistEditTracks newItem) { if (!ModelState.IsValid) { return(RedirectToAction("edit", new { id = newItem.playlistId })); } if (id.GetValueOrDefault() != newItem.playlistId) { return(RedirectToAction("index")); } var editedItem = m.PlaylistEditTracks(newItem); if (editedItem == null) { return(RedirectToAction("Details", new { id = newItem.playlistId })); } else { return(RedirectToAction("Details", new { id = newItem.playlistId })); } }
public ActionResult Edit(int?id, PlaylistEditTracks newItem) { try { // Check if model state is valid if (!ModelState.IsValid) { return(RedirectToAction("Edit", new { id = newItem.PlaylistId })); } // Check for tampering if (id.GetValueOrDefault() != newItem.PlaylistId) { return(RedirectToAction("Index")); } // Envoke manager, attepmt update var o = m.PlaylistEdit(newItem); if (o == null) { // There was a problem updating the object // Our "version 1" approach is to display the "edit form" again return(RedirectToAction("Index")); } else { // Show the details view, which will have the updated data return(RedirectToAction("Details", new { id = newItem.PlaylistId })); } } catch { return(View()); } }
public ActionResult Edit(int? id, PlaylistEditTracks newItem) { // Validate the input if (!ModelState.IsValid) { // Our "version 1" approach is to display the "edit form" again return RedirectToAction("edit", new { id = newItem.PlaylistId }); } if (id.GetValueOrDefault() != newItem.PlaylistId) { // This appears to be data tampering, so redirect the user away return RedirectToAction("index"); } // Attempt to do the upate var editedItem = m.PlaylistEditTracks(newItem); if (editedItem == null) { // There was a problem updating the object // Our "version 1" approach is to display the "edit form" again return RedirectToAction("edit", new { id = newItem.PlaylistId }); } else { // Show the details view, which will have the updated data return RedirectToAction("details", new { id = newItem.PlaylistId }); } }