public static ArrayList GetSongsInPlaylist(string playlistName) { using (LiteDatabase db = new LiteDatabase(DATABASE_LOCATION)) { ArrayList list = new ArrayList(); if (!String.IsNullOrEmpty(playlistName)) { var playlistTable = db.GetCollection <Objects.Playlist>(PLAYLIST_TABLE); var playlistSongTable = db.GetCollection <Objects.PlaylistSong>(PLAYLIST_SONG_TABLE); var record = db.GetCollection <Objects.Record>(MEDIA_TABLE); Objects.Playlist playlist = playlistTable.FindById(playlistName.GetHashCode().ToString()); ArrayList playlistSongs = new ArrayList(); foreach (Objects.PlaylistSong ps in playlistSongTable.Find(x => x.playlistId.Equals(playlist.id))) { playlistSongs.Add(ps); } foreach (Objects.PlaylistSong ps in playlistSongs) { list.Add(record.FindById(ps.mediaId)); } } return(list); } }
public static void AddPlaylist(string name) { using (LiteDatabase db = new LiteDatabase(DATABASE_LOCATION)) { var collection = db.GetCollection <Objects.Playlist>(PLAYLIST_TABLE); Objects.Playlist playlist = new Objects.Playlist(name.GetHashCode().ToString(), name); collection.Upsert(playlist); } }
public static void RemoveRecordFromPlaylist(string playlistName, string songName) { using (LiteDatabase db = new LiteDatabase(DATABASE_LOCATION)) { var playlistTable = db.GetCollection <Objects.Playlist>(PLAYLIST_TABLE); var playlistSongTable = db.GetCollection <Objects.PlaylistSong>(PLAYLIST_SONG_TABLE); var recordTable = db.GetCollection <Objects.Record>(MEDIA_TABLE); Objects.Playlist playlist = playlistTable.FindOne(x => x.id.Equals(playlistName.GetHashCode().ToString())); Objects.Record record = recordTable.FindOne(x => x.id.Equals(songName.GetHashCode().ToString())); playlistSongTable.Delete(x => x.playlistId.Equals(playlist.id) && x.mediaId.Equals(record.id)); } }
public static void SetRecordToPlaylist(string playlistName, ArrayList records) { using (LiteDatabase db = new LiteDatabase(DATABASE_LOCATION)) { var playlistTable = db.GetCollection <Objects.Playlist>(PLAYLIST_TABLE); var playlistSongTable = db.GetCollection <Objects.PlaylistSong>(PLAYLIST_SONG_TABLE); var recordTable = db.GetCollection <Objects.Record>(MEDIA_TABLE); foreach (string recordName in records) { Objects.Playlist playlist = playlistTable.FindById(playlistName.GetHashCode().ToString()); Objects.Record record = recordTable.FindById(recordName.GetHashCode().ToString()); Objects.PlaylistSong playlistSong = new Objects.PlaylistSong(playlist.id + record.id, record.id, playlist.id); playlistSongTable.Upsert(playlistSong); } } }