public TrackBase TrackAdd(TrackAdd newItem) { var addedItem = ds.Tracks.Add(Mapper.Map <Track>(newItem)); ds.SaveChanges(); return((addedItem == null) ? null : Mapper.Map <TrackBase>(addedItem)); }
public TrackWithDetails TrackAdd(TrackAdd newItem) { // Attention 18 - Manager method to add a new track for an album // Validate the associated item var a = ds.Albums.Include("Artists") .SingleOrDefault(al => al.Id == newItem.AlbumId); if (a == null) { return(null); } else { // Attempt to add the new item var addedItem = ds.Tracks.Add(mapper.Map <Track>(newItem)); // Set the association addedItem.Albums.Add(a); // Set the clerk user name addedItem.Clerk = User.Name; byte[] photoBytes = new byte[newItem.AudioUpload.ContentLength]; newItem.AudioUpload.InputStream.Read(photoBytes, 0, newItem.AudioUpload.ContentLength); addedItem.Audio = photoBytes; addedItem.AudioContentType = newItem.AudioUpload.ContentType; ds.SaveChanges(); return((addedItem == null) ? null : mapper.Map <TrackWithDetails>(addedItem)); } }
public ActionResult Create(TrackAdd newItem) { if (!ModelState.IsValid) { return(View(newItem)); } // Process the input var addedItem = m.TrackAdd(newItem); if (addedItem == null) { return(View(newItem)); } else { return(RedirectToAction("Details", new { id = addedItem.Id })); } }
public ActionResult Create(TrackAdd newItem) { newItem.Clerk = HttpContext.User.Identity.Name; ModelState.Clear(); if (!ModelState.IsValid) { return(View(newItem)); } var addedItem = m.TrackAdd(newItem); if (addedItem == null) { return(View(newItem)); } else { return(RedirectToAction("details", new { id = addedItem.Id })); } }
public ActionResult AddTrack(int?id, TrackAdd newItem) { // Validate the input if (!ModelState.IsValid & id.GetValueOrDefault() == newItem.AlbumId) { return(RedirectToAction("details", "albums", new { id = id })); } // Process the input var addedItem = m.TrackAdd(newItem); if (addedItem == null) { return(RedirectToAction("details", "albums", new { id = id })); } else { // Attention 19 - Must redirect to the tracks controller return(RedirectToAction("details", "tracks", new { id = addedItem.Id })); } }