async void BtnBETTING_Clicked(System.Object sender, System.EventArgs e) { Trellocard card = new Trellocard(); try { int Hometeam = Int32.Parse(BETTING_HOMETEAM.Text); int Awayteam = Int32.Parse(BETTING_AWAYTEAM.Text); card.Name = list[0].strHomeTeam + "-" + list[0].strAwayTeam + " = " + BETTING_HOMETEAM.Text + "-" + BETTING_AWAYTEAM.Text; await FootballRepo.AddBetting("5fbf760ec952e73423a16be3", card); Navigation.PushAsync(new MainPage()); } catch (FormatException) { await DisplayAlert("ERROR", "ONLY NUMBERS(1,2,3...)", "OK"); } }
public static async Task AddBetting(string listid, Trellocard card) { string url = $"{_BASEURI}/cards?idList={listid}&key={_APIKEY}&token={_USERTOKEN}"; using (HttpClient client = GetHttpClient()) { try { string json = JsonConvert.SerializeObject(card); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); var response = await client.PostAsync(url, content); if (!response.IsSuccessStatusCode) { string errormsg = $"Unsucessfull POST to url {url} , object:{json}"; throw new Exception(errormsg); // Springt automatisch naar de catch function } } catch (Exception ex) { throw ex; } } }