Beispiel #1
0
        /// <summary>
        /// Get the PlaylistItems and associated songs for this playlist
        /// </summary>
        /// <param name="playlistItems"></param>
        public void GetContents(IEnumerable <SongPlaylistItem> playlistItems)
        {
            // Get all the SongPlaylistItem entries associated with this SongPlaylist and then the Song entries for each of them
            PlaylistItems.AddRange(playlistItems.Where(item => item.PlaylistId == Id));

            foreach (SongPlaylistItem playlistItem in PlaylistItems)
            {
                playlistItem.Song        = Songs.GetSongById(playlistItem.SongId);
                playlistItem.Artist      = Artists.GetArtistById(ArtistAlbums.GetArtistAlbumById(playlistItem.Song.ArtistAlbumId).ArtistId);
                playlistItem.Song.Artist = playlistItem.Artist;
            }

            PlaylistItems.Sort((a, b) => a.Index.CompareTo(b.Index));
        }
Beispiel #2
0
        /// <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);
            }
        }