public ActionResult SaveArtist(Artist postedArtist) { if (!ModelState.IsValid) { throw new CallbackException("Model binding failed.", 500); } var artistBus = new ArtistBusiness(); // attach to context var artist = artistBus.Attach(postedArtist); if (!artistBus.Validate()) { throw new CallbackException("Please correct the following: " + artistBus.ValidationErrors.ToString()); } if (!artistBus.Save()) { throw new CallbackException("Unable to save artist: " + artistBus.ErrorMessage); } var albumBus = new AlbumBusiness(); var albums = albumBus.GetAlbumsForArtist(artist.Id); return(new JsonNetResult(new ArtistResponse { Artist = artist, Albums = albums })); }
public ActionResult Get(int id = -1) { if (id < 1) { throw new CallbackException("Invalid id passed."); } var artistBus = new ArtistBusiness(); var artist = artistBus.Load(id); if (artist == null) { throw new CallbackException("Invalid id passed."); } var albumBus = new AlbumBusiness(); var albums = albumBus.GetAlbumsForArtist(artist.Id); return(new JsonNetResult(new ArtistResponse { Artist = artist, Albums = albums })); }