private async void button1_Click(object sender, EventArgs e) { PLANTEN p = await GetPlantAsync((string)plantComboBox.SelectedValue); if (p != null) { pLANTENBindingSource.DataSource = p; } else { MessageBox.Show("Niet gevonden"); } }
public IHttpActionResult GetPlant(String id) { using (deschopEntities db = new deschopEntities()) { PLANTEN plant = db.PLANTEN.FirstOrDefault(p => p.ART_CODE == id); if (plant != null) { return(Ok(plant)); } else { return(NotFound()); } } }
private async Task <PLANTEN> GetPlantAsync(String art_code) { using (HttpClient client = new HttpClient()) { PLANTEN planten = null; client.BaseAddress = new Uri("http://localhost:59318/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept .Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = await client.GetAsync("api/planten/" + art_code); if (response.IsSuccessStatusCode) { return(planten = await response.Content.ReadAsAsync <PLANTEN>()); } else { return(null); } } }