private async void addToBlacklist(string search) { //Check if the string is empty if (string.IsNullOrEmpty(search)) { return; } switch (cbx_Type.SelectedIndex) { case 0: // Spotify Artist Blacklist // If the API is not connected just don't do anything? if (APIHandler.spotify == null) { MessageDialogResult msgResult = await this.ShowMessageAsync("Notification", "Spotify is not connected. You need to connect to Spotify in order to fill the blacklist.", MessageDialogStyle.Affirmative); return; } // Perform a search via the spotify API SpotifyAPI.Web.Models.SearchItem searchItem = APIHandler.GetArtist(search); if (searchItem.Artists.Items.Count <= 0) { return; } SpotifyAPI.Web.Models.FullArtist fullartist = searchItem.Artists.Items[0]; foreach (object item in ListView_Blacklist.Items) { if (item.ToString() == fullartist.Name) { return; } } ListView_Blacklist.Items.Add(fullartist.Name); break; case 1: ListView_UserBlacklist.Items.Add(search); break; } SaveBlacklist(); }
//show albums public ActionResult ShowAlbums(string artistName) { //search the artist string fullName = artistName; //if full name has space replace it with %20 for searching if (fullName.Contains(" ")) { int index = fullName.IndexOf(' '); fullName = fullName.Substring(0, index) + "%20" + fullName.Substring(index + 1); Response.Write(fullName); } //search the artist string url = $"https://api.spotify.com/v1/search?q={fullName}&type=artist"; SpotifyAPI.Web.Models.SearchItem t = new SpotifyAPI.Web.Models.SearchItem(); t = GetFromSpotify <SpotifyAPI.Web.Models.SearchItem>(url); try { string artistID = t.Artists.Items[0].Id; //search artist's albums string urlArtist = $"https://api.spotify.com/v1/artists/{artistID}/albums"; SpotifyAPI.Web.Models.Paging <SpotifyAPI.Web.Models.SimpleAlbum> allAlbumsSimplified = new SpotifyAPI.Web.Models.Paging <SpotifyAPI.Web.Models.SimpleAlbum>(); allAlbumsSimplified = GetFromSpotify <SpotifyAPI.Web.Models.Paging <SpotifyAPI.Web.Models.SimpleAlbum> >(urlArtist); //get only 5 albums int count; if (allAlbumsSimplified.Items.Count > 5) { count = 5; } else { count = allAlbumsSimplified.Items.Count; } //use the herf to get the album's full details SpotifyAPI.Web.Models.FullAlbum[] fullAlbum = new SpotifyAPI.Web.Models.FullAlbum[count]; for (int i = 0; i < count; i++) { fullAlbum[i] = GetFromSpotify <SpotifyAPI.Web.Models.FullAlbum>(allAlbumsSimplified.Items[i].Href); } //declare all the returned albums information string[] albumNames = new string[count]; string[] albumReleaseDate = new string[count]; string[] albumArtist = new string[count]; string[] NumberOfTracks = new string[count]; string[] Popularity = new string[count]; //store the returned albums information for (int i = 0; i < fullAlbum.Length; i++) { albumNames[i] = fullAlbum[i].Name; albumReleaseDate[i] = fullAlbum[i].ReleaseDate; albumArtist[i] = fullAlbum[i].Artists[0].Name; NumberOfTracks[i] = (fullAlbum[i].Tracks.Total).ToString(); Popularity[i] = (fullAlbum[i].Popularity).ToString(); } //store it in ViewBag to send it to View ViewBag.AlbumNames = albumNames; ViewBag.AlbumReleaseDate = albumReleaseDate; ViewBag.albumArtist = albumArtist; ViewBag.NumberOfTracks = NumberOfTracks; ViewBag.Popularity = Popularity; } catch (ArgumentOutOfRangeException e) { Response.Write("<H1>Artist Not Found</H1>"); } return(View()); }