Esempio n. 1
0
        public IActionResult AddSong(SongPostIndexModel model)
        {
            if (model == null)
            {
                RedirectToAction("ArtistInfo", new { id = model.Artist.Id });
            }

            var artistModel = model.Artist;
            var songModel   = model.Song;

            //add the song - populate an Song instance with values from the form
            var newSong = new Song
            {
                Name     = songModel.Name,
                Duration = songModel.Duration,
            };

            _song.Add(newSong);

            //insert association record for AlbumId, ArtistId, SongId
            if (model.Album.Id != 0)
            {
                _albumSong.Add(model.Album.Id, artistModel.Id, model.Song.TrackNumber, newSong.Id);
            }
            else
            {
                //song is not associated to an album
                _albumSong.Add(0, artistModel.Id, model.Song.TrackNumber, newSong.Id);
            }

            return(RedirectToAction("Index", "SongPost",
                                    new { albumId = model.Album.Id, artistId = model.Artist.Id }));
        }
        public IActionResult AddAlbum(AlbumPostIndexModel model)
        {
            if (model == null)
            {
                RedirectToAction("ArtistInfo", new { id = model.Artist.Id });
            }

            var artistModel = model.Artist;
            var albumModel  = model.Album;

            //add the album - populate an Album instance with values from the form
            var album = new Album
            {
                Id         = albumModel.Id,
                Name       = albumModel.Name,
                YrReleased = albumModel.YrReleased
            };

            _album.Add(album);

            _albumSong.Add(album.Id, artistModel.Id, 0, 0);

            return(RedirectToAction("Index", "AlbumMod",
                                    new { artistId = artistModel.Id, albumId = album.Id }));
        }