public ActionResult Edit(int?id, TrackEdit newItem) { // Validate the input if (!ModelState.IsValid) { // Our "version 1" approach is to display the "edit form" again return(RedirectToAction("edit", new { id = newItem.Id })); } if (id.GetValueOrDefault() != newItem.Id) { // This appears to be data tampering, so redirect the user away return(RedirectToAction("index")); } // Attempt to do the update var editedItem = m.TrackEdit(newItem); editedItem.AudioUpload = newItem.AudioUpload; if (editedItem == null) { return(View(newItem)); } else { return(RedirectToAction("../Track/Details", new { id = editedItem.Id })); } }
public TrackWithDetail TrackEdit(TrackEdit newItem) { var addedItem = ds.Tracks.SingleOrDefault(x => x.Id == newItem.Id); byte[] audioBytes = new byte[newItem.AudioUpload.ContentLength]; newItem.AudioUpload.InputStream.Read(audioBytes, 0, newItem.AudioUpload.ContentLength); addedItem.Audio = audioBytes; addedItem.AudioContentType = newItem.AudioUpload.ContentType; if (addedItem == null) { return(null); } else { ds.SaveChanges(); return(mapper.Map <Track, TrackWithDetail>(addedItem)); } }