Exemple #1
0
        public async Task <ActionResult> Index(string artistId)
        {
            Artist artist = await spotifyService.GetArtist(artistId);

            List <Track> topTracks = null;

            if (artist.id != null)
            {
                // Set cookie for homepage's related artists section
                Response.Cookies["cookie"].Value = artist.id;

                topTracks = await spotifyService.GetArtistTopTracks(artistId);

                List <Album> albums = await spotifyService.GetArtistAlbums(artistId);

                artist.youtubeProfile = await youtubeService.GetYoutubeChannel(artist.name);

                wikipediaService.GetArticleIntro(artist);

                // geniusService.SetTrackLyrics("PNL");

                ViewBag.Albums            = albums;
                ViewBag.ArtistName        = artist.name;
                ViewBag.ArtistImage       = artist.images[0].url;
                ViewBag.WikiActicle       = artist.wikipediaArticle;
                ViewBag.WikipediaURL      = artist.wikipediaProfile;
                ViewBag.YoutubeChannelURL = artist.youtubeProfile;
                ViewBag.SpotifyURL        = "https://play.spotify.com/artist/" + artist.id;
            }
            return(View(topTracks));
        }
        /// <summary>
        /// Bind the new playlist to the page
        /// </summary>
        /// <returns></returns>
        public async Task BindPlaylist()
        {
            ShowPlaylistSaved = false;
            Loaded            = false;

            try
            {
                Tracks.Clear();

                foreach (var artist in Artists)
                {
                    try
                    {
                        Tracks.AddRange((await SpotifyService.GetArtistTopTracks(artist.Id, AuthenticationService.AuthenticationToken)).Take(3).ToList());

                        if (Tracks.Count % 33 == 0)
                        {
                            StateHasChanged();
                        }
                    }
                    catch (Exception ex)
                    {
                        PageException = ex;
                    }
                }
            }
            catch (Exception ex)
            {
                PageException = ex;
            }

            Tracks = Tracks.OrderBy(o => Guid.NewGuid()).ToList();
            Loaded = true;

            StateHasChanged();
        }