Esempio n. 1
0
 public RandomTrackVM MapToRandomTrackViewModel(SpotifyTracksResponse randomSearchResponse)
 {
     return randomSearchResponse.Tracks.Items.Select(x => new RandomTrackVM
     {
         Name = x.Name,
         Artist = x.Artists?[0].Name,
         ArtistId = x.Artists?[0].Id,
         PreviewUrl = x.Preview_url,
         ImageUrl = x.Album?.Images?[0].Url 
     }).First();
 }
        public async Task <IActionResult> Random()
        {
            try
            {
                var randomSearchResponse = new SpotifyTracksResponse();
                int trackCount           = 0;
                while (trackCount == 0)
                {
                    randomSearchResponse = await _recommendationService.GetRandom();

                    if (randomSearchResponse.Tracks.Items.Count > 0)
                    {
                        trackCount++;
                    }
                }
                var viewModel = _searchResultMapper.MapToRandomTrackViewModel(randomSearchResponse);
                return(View(viewModel));
            }
            catch (System.Exception)
            {
                //log exception
                return(RedirectToAction("Error"));
            }
        }