async void RenamePlaylist(object playlist) { var stop = System.Diagnostics.Stopwatch.StartNew(); var dictPl = playlist != null ? (playlist as Dictionary <Playlist, IEnumerable <Mediafile> >).First() : CurrentDictionary.First(); //get the dictionary containing playlist and songs. var selectedPlaylist = dictPl.Key; //get selected playlist var songs = dictPl.Value; //get songs of the playlist var dialog = new InputDialog() { Title = "Rename this playlist", Text = selectedPlaylist.Name, Description = selectedPlaylist.Description }; var Playlists = new Dictionary <Playlist, IEnumerable <Mediafile> >(); if (await dialog.ShowAsync() == ContentDialogResult.Primary) { var pl = new Playlist() { Name = dialog.Text, Description = dialog.Description }; if (songs.Count() > 0) { foreach (var file in songs) { file.Playlists.First(t => t.Name == selectedPlaylist.Name).Name = pl.Name; file.Playlists.First(t => t.Name == pl.Name).Description = pl.Description; LibVM.db.Update(file); //update database saving all songs and changes. } } ShellVM.PlaylistsItems.First(t => t.Label == selectedPlaylist.Name).Label = pl.Name; //change playlist name in the hamburgermenu LibVM.Options.First(t => t.Text == selectedPlaylist.Name).Text = pl.Name; //change playlist name in context menu of each song. LibVM.db.playlists.FindOne(t => t.Name == selectedPlaylist.Name); //change playlist name in the 'playlist' collection in the database. dictPl.Key.Name = pl.Name; Playlist = pl; //set this.Playlist to pl (local variable); } stop.Stop(); System.Diagnostics.Debug.WriteLine("It took: " + stop.ElapsedMilliseconds.ToString()); }
async void DeletePlaylist(object playlist) { var stop = System.Diagnostics.Stopwatch.StartNew(); var dictPl = playlist != null ? (playlist as Dictionary <Playlist, IEnumerable <Mediafile> >).First() : CurrentDictionary.First(); //get the dictionary containing playlist and songs. var selectedPlaylist = dictPl.Key; //get selected playlist var songs = dictPl.Value; //get songs of the playlist Windows.UI.Popups.MessageDialog dia = new Windows.UI.Popups.MessageDialog("Do you want to delete this playlist?", "Confirmation"); dia.Commands.Add(new Windows.UI.Popups.UICommand("Yes") { Id = 0 }); dia.Commands.Add(new Windows.UI.Popups.UICommand("No") { Id = 1 }); dia.DefaultCommandIndex = 0; dia.CancelCommandIndex = 1; var result = await dia.ShowAsync(); if (result.Label == "Yes") { if (songs.Count() > 0) //check to see if there are any songs. If not then the playlist is empty. { foreach (var file in songs) { file.Playlists.Remove(file.Playlists.First(t => t.Name == selectedPlaylist.Name)); //remove playlist from the song. LibVM.db.Update(file); //update database and save all changes. } } ShellVM.PlaylistsItems.Remove(ShellVM.PlaylistsItems.First(t => t.Label == selectedPlaylist.Name)); //delete from hamburger menu LibVM.Options.Remove(LibVM.Options.First(t => t.Text == selectedPlaylist.Name)); //delete from context menu LibVM.db.playlists.Delete(t => t.Name == selectedPlaylist.Name); //delete from database. } stop.Stop(); System.Diagnostics.Debug.WriteLine("It took: " + stop.ElapsedMilliseconds.ToString()); }