Beispiel #1
0
        public static SONG AddSongToDB(string name, string artistName, string albumName, List <string> genreNames, int year, int durationSec)
        {
            var context = DJPlaylistContext.GetContext();

            var song = context.SONGS.FirstOrDefault(i => i.NAME == name && i.ARTIST_NAME == artistName && i.ALBUM_NAME == albumName && i.YEAR == year);

            if (song == null)
            {
                song = new SONG(name, artistName, albumName, year, durationSec);
                context.SONGS.Add(song);
                context.SaveChanges();
            }

            foreach (var genreName in genreNames)
            {
                var genre = context.GENRES.FirstOrDefault(i => i.DESCRIPTION == genreName);
                if (genre == null)
                {
                    genre = new GENRE(genreName);
                    context.GENRES.Add(genre);
                    context.SaveChanges();
                }
                var songGenre = context.SONG_GENRES.FirstOrDefault(i => i.SONG_ID == song.ID && i.GENRE_ID == genre.ID);
                if (songGenre == null)
                {
                    songGenre = new SONG_GENRE(song, genre);
                    context.SONG_GENRES.Add(songGenre);
                    context.SaveChanges();
                }
            }

            return(song);
        }
Beispiel #2
0
 public PLAYLIST_SONG(PLAYLIST playlist, SONG song, int order, bool allowDuplicates = true)
 {
     if (!allowDuplicates && playlist.PLAYLIST_SONGS.Any(i => i.SONG_ID == SONG_ID))
     {
         throw new Exception("Playlist doesn't allows duplicate songs");
     }
     if (playlist.PLAYLIST_SONGS.Any(i => i.ORDER == order))
     {
         playlist.EmptyPosition(order);
     }
     PLAYLIST_ID = playlist.ID;
     SONG_ID     = song.ID;
     ORDER       = order;
 }
Beispiel #3
0
 public SONG_GENRE(SONG song, GENRE genre)
 {
     SONG_ID  = song.ID;
     GENRE_ID = genre.ID;
 }
Beispiel #4
0
 public SONG_PLAY(SONG song, USER user)
 {
     SONG_ID     = song.ID;
     USER_ID     = user.ID;
     DATE_PLAYED = DateTime.Now;
 }