public ActionResult Create(AlbumAdd newItem) { try { if (!ModelState.IsValid) { return(View(newItem)); } var addedItem = m.AlbumAdd(newItem); if (addedItem == null) { return(HttpNotFound()); } else { return(RedirectToAction("details", new { id = addedItem.Id })); } } catch { return(View()); } }
public ActionResult AddAlbum(AlbumAdd newItem) { //Validate if (!ModelState.IsValid) { return(View(newItem)); } // Process var addedItem = m.AlbumAdd(newItem); if (addedItem == null) { return(View(newItem)); } else { return(RedirectToAction("details", "album", new { id = addedItem.Id })); } }
public AlbumWithDetail AlbumAdd(AlbumAdd newItem) { var a = ds.Artists.Include("Albums").FirstOrDefault(ar => ar.Id == newItem.ArtistId); if (a == null) { return(null); } else { foreach (var item in newItem.TrackIds) { var b = ds.Tracks.Find(item); ds.Tracks.Add(b); } var addedItem = ds.Albums.Add(mapper.Map <AlbumAdd, Album>(newItem)); addedItem.Artists.Add(a); //addedItem.Tracks.Add(b); ds.SaveChanges(); return((addedItem == null) ? null : mapper.Map <Album, AlbumWithDetail>(addedItem)); } }