Exemple #1
0
        public ActionResult Search(string searchTerm = "", bool isAPost = false)
        {
            var spotifyHelper = new SpotifyHelper();
            var vm            = new SearchViewModel();

            if (isAPost && searchTerm == "")
            {
                searchTerm = "Muse";
            }

            // Initial load of the page
            if (searchTerm == "")
            {
                return(View());
            }

            // To aid searching eg que
            searchTerm   += "*";
            vm.SearchTerm = searchTerm;

            string json   = spotifyHelper.CallSpotifyAPIArtistSearch(searchTerm);
            var    result = JsonConvert.DeserializeObject <ArtistsResponse2>(json);

            vm.ArtistsResponse2 = result;

            // eg fat bo* .. only get first 5
            json = spotifyHelper.CallSpotifyAPITrackSearch(searchTerm);
            var result2 = JsonConvert.DeserializeObject <TrackSearchResponse>(json);

            vm.TrackSearchResponse = result2;

            return(View(vm));
        }