コード例 #1
0
        public async Task <IViewComponentResult> InvokeAsync(string selectedArtistName = null)
        {
            var artistNamesAllViewModel = await artistService.GetAllArtistNamesAsync();

            if (!artistNamesAllViewModel.Any(artist => artist.FullName == selectedArtistName))
            {
                return(View(artistNamesAllViewModel));
            }

            var selected = artistNamesAllViewModel.Single(x => x.FullName == selectedArtistName);
            var index    = artistNamesAllViewModel.IndexOf(selected);
            var first    = artistNamesAllViewModel[0];

            artistNamesAllViewModel[0]     = selected;
            artistNamesAllViewModel[index] = first;

            return(View(artistNamesAllViewModel));
        }