예제 #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);
        }
예제 #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);
        }
예제 #3
0
        public Song GetSong(int songId)
        {
            Song requestedSong;
            PlaylistDescriptor playlist;

            try
            {
                DataRow song = DataAccess.DataAccess.GetTable("GetSong", new Dictionary <string, object> {
                    { "SongId", songId }
                }).Rows[0];
                requestedSong        = new Song();
                requestedSong.songId = Int32.Parse(song["SongId"].ToString());
                requestedSong.title  = song["Title"].ToString();
                requestedSong.artist = song["Artist"].ToString();
                requestedSong.lyrics = song["Lyrics"].ToString();

                DataTable member = DataAccess.DataAccess.GetTable("GetSongPlaylist", new Dictionary <string, object> {
                    { "SongId", songId }
                });
                requestedSong.membership = new List <PlaylistDescriptor>();
                foreach (DataRow dr in member.Rows)
                {
                    playlist             = new PlaylistDescriptor();
                    playlist.playlistId  = Int32.Parse(dr["PlaylistId"].ToString());
                    playlist.name        = dr["Name"].ToString();
                    playlist.description = dr["Description"].ToString();
                    requestedSong.membership.Add(playlist);
                }
            }
            catch (Exception ex)
            {
                Logging.Log.ToDB($"Error attempting to retrieve song for SongID {songId}.  Details:\n{ex.Message}");
                requestedSong = null;
            }
            return(requestedSong);
        }
예제 #4
0
 public Playlist()
 {
     descriptor = new PlaylistDescriptor();
     songs      = new List <Song>();
 }