Exemplo n.º 1
0
        private void getSongsBtn_Click(object sender, EventArgs e)
        {
            var playlist  = _service.GetAllSongs(_dataStorage.CurrentSelectedPartyId).OrderByDescending(aux => aux.rating).ToList();
            var userVotes = _service.GetAllRatings(_dataStorage.CurrentSelectedPartyId, _dataStorage.UserId).ToList();

            RefreshSpotifyPlaylist(playlist);

            if (getSongsResultLB.InvokeRequired)
            {
                getSongsResultLB.Invoke(new MethodInvoker(delegate { getSongsResultLB.Items.Clear(); }));
            }
            else
            {
                getSongsResultLB.Items.Clear();
            }


            _existingPlaylist          = new List <string>();
            _existingFullTrackPlaylist = new List <string>();
            _collectionOfVotes         = new List <SongRatingFromPartyTable>();
            // _existingFullList = new List<WCFService.SongsForPartyTable>();

            userVotes.ForEach(vote =>
            {
                SongRatingFromPartyTable songRating = new SongRatingFromPartyTable
                {
                    partyID  = vote.partyID,
                    songURL  = vote.songURL,
                    voteType = vote.voteType,
                    userID   = vote.userID
                };
                _collectionOfVotes.Add(songRating);
            }
                              );

            playlist.ForEach(song =>
            {
                //addTrack(newPlaylist,song.songURL);

                string myArtists      = null;
                SongsForPartyTable sp = new SongsForPartyTable
                {
                    partyID = song.partyID,
                    songURL = song.songURL,
                    rating  = song.rating
                };
                _existingFullTrackPlaylist.Add(sp.songURL);
                // _existingFullList.Add(sp);
                var fullTrack = _spotify.GetTrack(song.songURL.Substring(14, song.songURL.Length - 14));

                var list = fullTrack.Artists;
                list.ForEach(artist => {
                    if (myArtists == null)
                    {
                        myArtists = artist.Name;
                    }
                    else
                    {
                        myArtists += ", " + artist.Name;
                    }
                });
                _existingPlaylist.Add(fullTrack.Uri);
                if (getSongsResultLB.InvokeRequired)
                {
                    getSongsResultLB.Invoke(new MethodInvoker(delegate { getSongsResultLB.Items.Add($"{fullTrack.Name } : { myArtists}"); }));
                }
                else
                {
                    getSongsResultLB.Items.Add($"{fullTrack.Name } : { myArtists}");
                }
            });
        }