private async void SearchFriends() { if (!string.IsNullOrEmpty(FriendSearchbar)) { ObservableSearchPlayerList.Clear(); //do web request and get the possible friends back. -> api/player/GetAccountsByNameSearch Dictionary <string, string> parameters = new Dictionary <string, string> { { "name", FriendSearchbar.Trim() }, { "user", MultiplayerHubProxy.Instance.CurrentPlayer.UserId.ToString() } }; var response = await RestHelper.GetRequestAsync("api/player/GetAccountsByNameSearch", parameters); if (response.StatusCode == System.Net.HttpStatusCode.OK) { List <Player> foundPlayers = RestHelper.ConvertJsonToObject <List <Player> >(response.Content); if (foundPlayers != null && foundPlayers?.Count != 0) { foreach (Player p in foundPlayers) { SearchPlayerObject SearchPlayer = new SearchPlayerObject() { PlayerName = p.PlayerName, PlayerGuid = p.PlayerGuid, OnAddFriend = new RelayCommand(() => CreateFriendShip(p)) }; ObservableSearchPlayerList.Add(SearchPlayer); } } } } }
private async void CreateFriendShip(Player player) { List <Player> Friends = new List <Player> { MultiplayerHubProxy.Instance.CurrentPlayer, player }; var response = await RestHelper.PostRequestAsync("api/player/CreateFriendship", Friends); if (response.StatusCode == System.Net.HttpStatusCode.OK) { //friend has been added, update friendlist at the top: await UpdateFriendships(MultiplayerHubProxy.Instance.CurrentPlayer.UserId.ToString()); ObservableSearchPlayerList.Clear(); FriendSearchbar = ""; NotifyPropertyChanged("FriendSearchbar"); } }