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 static PLAYLIST CreatePlaylist(int userID, string name, bool isPublic = false) { var context = DJPlaylistContext.GetContext(); var user = context.USERS.FirstOrDefault(i => i.ID == userID); if (user == null) { throw new Exception("User not found"); } if (context.PLAYLISTS.Any(i => i.NAME == name && i.USER_ID == userID)) { throw new Exception("There is already a playlist with this name"); } var playlist = new PLAYLIST(name, userID, isPublic); context.PLAYLISTS.Add(playlist); context.SaveChanges(); var userPlaylist = new USER_PLAYLIST(user, playlist); context.USER_PLAYLISTS.Add(userPlaylist); context.SaveChanges(); return(playlist); }
public USER_PLAYLIST(USER user, PLAYLIST playlist) { USER_ID = user.ID; PLAYLIST_ID = playlist.ID; DATE_CREATED = DateTime.Now; }