// Returns searchObject that contains 'artists' list [returns the Root Object] public async Task <SearchRootObject> SearchArtist(string name, int offset) { name += "*"; var output = (Object)null; if (offset > 0) { // At the end: limit and offset output = await _spotify.SearchItemsAsync(name, SpotifyAPI.Web.Enums.SearchType.Artist, 20, offset, ""); } else { // (string q, SearchType type, int limit = 20, int offset = 0, string market = ""); output = await _spotify.SearchItemsAsync(name, SpotifyAPI.Web.Enums.SearchType.Artist, 20, 0, ""); } string outputString = JsonConvert.SerializeObject(output); // Deserialize the JSON string into a Artists Object / Item[an Artist is an item] SearchRootObject searchObject = JsonConvert.DeserializeObject <SearchRootObject>(outputString); return(searchObject); }
public async Task <ActionResult> Index(string searchTerm) { SearchRootObject searchResult = null; string param = this.Request.QueryString["offset"]; int offset = 0; if (param != null) { offset = Int32.Parse(param); searchResult = await spotifyService.SearchArtist(searchTerm, offset); } else { searchResult = await spotifyService.SearchArtist(searchTerm, 0); } // Page total // First of page always adds up to 20 more than the last one ViewBag.FirstOfPage = 1 + offset; ViewBag.Total = searchResult.artists.total; ViewBag.Next = searchResult.artists.next; ViewBag.Previous = searchResult.artists.previous; ViewBag.Term = searchTerm; // Total of this page int totalCount = 0; foreach (var result in searchResult.artists.items) { totalCount++; } ViewBag.PageCount = totalCount + offset; ViewBag.Offset = offset; return(View(searchResult.artists.items)); }