/// <summary> /// Delete the specified Albums from the storage and the collections /// </summary> /// <param name="albumToDelete"></param> /// <returns></returns> public static void DeleteAlbums(IEnumerable <Album> albumsToDelete) { // No need to wait for the delete DbAccess.DeleteItemsAsync(albumsToDelete); foreach (Album albumToDelete in albumsToDelete) { AlbumCollection.Remove(albumToDelete); IdLookup.Remove(albumToDelete.Id); } }
/// <summary> /// Delete the specified Artists from the storage and the collections /// </summary> /// <param name="artistsToDelete"></param> public static void DeleteArtists(IEnumerable <Artist> artistsToDelete) { DbAccess.DeleteItemsAsync(artistsToDelete); foreach (Artist artistToDelete in artistsToDelete) { ArtistCollection.Remove(artistToDelete); IdLookup.Remove(artistToDelete.Id); } }
/// <summary> /// Delete all the specified ArtistAlbum from the storage and the collections /// </summary> /// <param name="artistAlbumsToDelete"></param> /// <returns></returns> public static void DeleteArtistAlbums(IEnumerable <ArtistAlbum> artistAlbumsToDelete) { // No need to wait for the ArtistAlbums to be deleted from storage DbAccess.DeleteItemsAsync(artistAlbumsToDelete); foreach (ArtistAlbum artAlbum in artistAlbumsToDelete) { ArtistAlbumCollection.Remove(artAlbum); IdLookup.Remove(artAlbum.Id); } }
/// <summary> /// Get the Playlists collection from storage /// </summary> /// <returns></returns> public static async Task GetDataAsync() { if (PlaylistCollection == null) { PlaylistCollection = new List <Playlist>(); // Get the current set of SongPlaylists List <SongPlaylist> songPlaylists = await DbAccess.LoadAsync <SongPlaylist>(); // Get all the SongPlaylistItems List <SongPlaylistItem> songPlaylistItems = await DbAccess.LoadAsync <SongPlaylistItem>(); // Make sure all these items are linked to songs. Remove any that aren't List <SongPlaylistItem> orphanItems = songPlaylistItems.Where(item => Songs.GetSongById(item.SongId) == null).ToList(); // Remove any orphaned items orphanItems.ForEach(item => songPlaylistItems.Remove(item)); DbAccess.DeleteItemsAsync(orphanItems); // Link the playlists with their playlistitems songPlaylists.ForEach(playlist => playlist.GetContents(songPlaylistItems)); // Add these to the main collection PlaylistCollection.AddRange(songPlaylists); // Now do the same for the AlbumPlaylists List <AlbumPlaylist> albumPlaylists = await DbAccess.LoadAsync <AlbumPlaylist>(); // Get all the PlaylistItems List <AlbumPlaylistItem> albumPlaylistItems = await DbAccess.LoadAsync <AlbumPlaylistItem>(); // Link the album playlist items to thier playlists albumPlaylists.ForEach(playlist => playlist.GetContents(albumPlaylistItems)); PlaylistCollection.AddRange(albumPlaylists); } }
/// <summary> /// Remove the supplied list of songs from local and persistent storage. /// This is used for bulk deletion, so rather than removing each song from the collection, O(n), reform the collection ignoring /// thoses to be delted /// </summary> /// <param name="songsToDelete"></param> public static void DeleteSongs(List <Song> songsToDelete) { lock ( lockObject ) { // Form a hash from all the song ids being deleted HashSet <int> songIds = new(songsToDelete.Select(song => song.Id)); // Make a new collection that only contains entries not in the deleted songs SongCollection = SongCollection.Where(song => songIds.Contains(song.Id) == false).ToList(); // Reform the lookups artistAlbumLookup = new(); albumLookup = new(); IdLookup = new(); foreach (Song song in SongCollection) { IdLookup[song.Id] = song; artistAlbumLookup.AddValue(song.ArtistAlbumId, song); albumLookup.AddValue(song.AlbumId, song); } } DbAccess.DeleteItemsAsync(songsToDelete); }