public ActionResult Edit(int?id, TrackEdit newItem) { newItem.Clerk = HttpContext.User.Identity.Name; if (!ModelState.IsValid) { return(RedirectToAction("Edit", new { id = newItem.Id })); } if (id.GetValueOrDefault() != newItem.Id) { return(RedirectToAction("Index")); } // Process the input var addedItem = m.TrackEdit(newItem); addedItem.AudioUpload = newItem.AudioUpload; if (addedItem == null) { return(View(newItem)); } else { return(RedirectToAction("../Track/Details", new { id = addedItem.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.Entry(addedItem).CurrentValues.SetValues(newItem); ds.SaveChanges(); return(Mapper.Map <Track, TrackWithDetail>(addedItem)); } }