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); }
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; }
public SONG_GENRE(SONG song, GENRE genre) { SONG_ID = song.ID; GENRE_ID = genre.ID; }
public SONG_PLAY(SONG song, USER user) { SONG_ID = song.ID; USER_ID = user.ID; DATE_PLAYED = DateTime.Now; }