public static void AddOrUpdateArtist(StoreContext db, Song song, Artist artistToAdd)
 {
     if (song.Artist == artistToAdd) //new artist is the same as the original artist
     {
         //do nothing
     }
     else
     {
         song.Artist = artistToAdd;
     }
 }
        public static SelectList GetAllArtists(StoreContext db)
        {
            var query = from a in db.Artist
                        orderby a.Name
                        select a;
            List<Artist> allArtists = query.ToList();

            SelectList list = new SelectList(allArtists, "ArtistID", "Name");

            return list;
        }
        public static List<Genre> GetGenresFromIntList(StoreContext db, List<int> selectedGenres)
        {
            List<Genre> genresToAdd = new List<Genre>();

            foreach (int genreID in selectedGenres)
            {
                genresToAdd.Add(db.Genre.Find(genreID));
            }

            return genresToAdd;
        }
        public static MultiSelectList GetAllGenres(StoreContext context)
        {
            var genres = from g in context.Genre
                         orderby g.Name
                         select g;

            List<Genre> allGenres = genres.ToList();

            MultiSelectList genreList = new MultiSelectList(allGenres, "GenreID", "Name");

            return genreList;
        }
        public static SelectList GetAllArtistsWithAll(StoreContext db)
        {
            var query = from a in db.Artist
                        orderby a.Name
                        select a;
            List<Artist> allArtists = query.ToList();

            allArtists.Insert(0, new Artist { ArtistID = -1, Name = "All Artists" });

            SelectList list = new SelectList(allArtists, "ArtistID", "Name");

            return list;
        }
        public static void AddOrUpdateSongGenre(StoreContext context, Song song, IEnumerable<Genre> songGenres)
        {
            if (songGenres != null)
            {
                //drop existing song genres
                song.Genres.Clear();

                foreach (var songGenre in songGenres)
                {
                    song.Genres.Add(songGenre);
                }
            }
        }
 public static void AddOrUpdateSongGenre(StoreContext context, Song song, List<int> genreIDs)
 {
     List<Genre> genres = GetGenresFromIntList(context, genreIDs);
     AddOrUpdateSongGenre(context, song, genres);
 }
 public static void AddOrUpdateSongGenre(StoreContext context, string songName, string genreName)
 {
     var genre = context.Genre.SingleOrDefault(g => g.Name == genreName);
     var song = context.Song.SingleOrDefault(s => s.Name == songName);
     song.Genres.Add(genre);
 }