Example #1
0
        public Playlist GetPlaylist(int playlistId)
        {
            Playlist requestedPlaylist;

            try
            {
                // A bit taken on faith.  Safer would be to check for rows returned, possibly for exactly one row.
                DataRow playlist = DataAccess.DataAccess.GetTable("GetPlaylist", new Dictionary <string, object> {
                    { "PlaylistId", playlistId }
                }).Rows[0];
                requestedPlaylist = new Playlist();
                PlaylistDescriptor descriptor = new PlaylistDescriptor();
                descriptor.playlistId        = Int32.Parse(playlist["PlaylistId"].ToString());
                descriptor.name              = playlist["Name"].ToString();
                descriptor.description       = playlist["Description"].ToString();
                requestedPlaylist.descriptor = descriptor;

                // Add list of songs
                DataTable songTable = DataAccess.DataAccess.GetTable("GetPlaylistSongs", new Dictionary <string, object> {
                    { "PlaylistId", playlistId }
                });
                Song currentSong;
                foreach (DataRow r in songTable.Rows)
                {
                    currentSong = new Song()
                    {
                        songId = Int32.Parse(r["SongId"].ToString()),
                        title  = r["Title"].ToString(),
                        artist = r["Artist"].ToString(),
                        lyrics = r["Lyrics"].ToString()
                    };
                    requestedPlaylist.songs.Add(currentSong);
                }
            }
            catch (Exception ex)
            {
                Logging.Log.ToDB($"Error attempting to retrieve playlist for ID {playlistId}.  Details:\n{ex.Message}");
                requestedPlaylist = null;
            }
            return(requestedPlaylist);
        }
Example #2
0
        public List <PlaylistDescriptor> GetPlaylists()
        {
            List <PlaylistDescriptor> playlists = new List <PlaylistDescriptor>();
            PlaylistDescriptor        playlist;

            try
            {
                DataTable playlistTable = DataAccess.DataAccess.GetTable("GetPlaylists", new Dictionary <string, object>());
                foreach (DataRow r in playlistTable.Rows)
                {
                    playlist             = new PlaylistDescriptor();
                    playlist.playlistId  = Int32.Parse(r["PlaylistId"].ToString());
                    playlist.name        = r["Name"].ToString();
                    playlist.description = r["Description"].ToString();
                    playlists.Add(playlist);
                }
            }
            catch (Exception ex)
            {
                Logging.Log.ToDB($"Error attempting to retrieve playlists.  Details:\n{ex.Message}");
                playlists = null;
            }
            return(playlists);
        }
Example #3
0
 public Playlist()
 {
     descriptor = new PlaylistDescriptor();
     songs      = new List <Song>();
 }