Esempio n. 1
0
        public async Task <IActionResult> SelectArtist()
        {
            CronosState.CurrentState = UserState.SelectArtist;

            var CurrentFeedback = "Search for an artist or select one of your recents from below";

            if (!ModelState.IsValid)
            {
                var oldVm = _mapper.Map <SelectArtistViewModel>(CronosState);
                return(View(oldVm));
            }

            if (CronosState.AlbumResults == null || !CronosState.AlbumResults.Any() && string.IsNullOrEmpty(CronosState.SearchTerm))
            {
                var recentlyPlayed = await _spotifyService.GetRecentlyPlayed();

                CronosState.ArtistResults = _mapper.Map <IEnumerable <Artist> >(recentlyPlayed);
            }



            var vm = _mapper.Map <SelectArtistViewModel>(CronosState);

            vm.ArtistListMessage = CurrentFeedback;

            if (vm.SelectedArtist != null)
            {
                var selectedArtist = vm.ArtistResults.FirstOrDefault(a => a.Id == vm.SelectedArtist.Id);
                if (selectedArtist != null)
                {
                    vm.ArtistResults = vm.ArtistResults.OrderByDescending(a => a.IsSelectedArtist);
                    selectedArtist.IsSelectedArtist = true;
                }
                else
                {
                    var arrayOfArtists   = vm.ArtistResults.ToArray();
                    var newListOfArtists = new List <Artist> {
                        vm.SelectedArtist
                    };
                    newListOfArtists.AddRange(arrayOfArtists);
                    vm.ArtistResults = newListOfArtists;
                }
            }


            return(View(vm));
        }