Exemple #1
0
        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
            }));
        }