public ActionResult AddTrack(AlbumTrackAdd newItem) { if (!ModelState.IsValid) { return(View(newItem)); } var addedItem = m.AlbumTrackAdd(newItem); if (addedItem == null) { return(View(newItem)); } else { return(RedirectToAction("details", "Track", new { id = addedItem.Id })); } }
public TrackBase AlbumTrackAdd(AlbumTrackAdd newItem) { var o = ds.Albums.SingleOrDefault(a => a.Id == newItem.AlbumId); if (o == null) { return(null); } var addedItem = ds.Tracks.Add(mapper.Map <AlbumTrackAdd, Track>(newItem)); addedItem.Clerk = UserAccount.Name; addedItem.Albums.Add(o); byte[] audioBytes = new byte[newItem.AudioUpload.ContentLength]; newItem.AudioUpload.InputStream.Read(audioBytes, 0, newItem.AudioUpload.ContentLength); addedItem.Clip = audioBytes; addedItem.AudioType = newItem.AudioUpload.ContentType; ds.SaveChanges(); return((addedItem == null) ? null : mapper.Map <Track, TrackBase>(addedItem)); }