private void Editar_Click(object sender, RoutedEventArgs e) { string friend = ListaAmigos.SelectedItem.ToString(); string[] S = friend.Split('-'); string id = S[0]; using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:54321/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); CajaLat.SelectAll(); CajaNombre.SelectAll(); CajaLon.SelectAll(); Amigo pepe = new Amigo() { name = CajaNombre.SelectedText, longi = CajaLon.SelectedText, lati = CajaLat.SelectedText }; pepe.ID = Convert.ToInt16(id); HttpResponseMessage response = client.PutAsJsonAsync("api/amigo/" + id, pepe).Result; if (response.IsSuccessStatusCode) { MessageBox.Show(this, "Amigo editado con éxito", "200 OK", MessageBoxButton.OK, MessageBoxImage.Information); } } }
private void Button_Click(object sender, RoutedEventArgs e) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:54321/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); CajaLat.SelectAll(); CajaNombre.SelectAll(); CajaLon.SelectAll(); Amigo pepe = new Amigo() { name = CajaNombre.SelectedText, longi = CajaLon.SelectedText, lati = CajaLat.SelectedText }; HttpResponseMessage response = client.PostAsJsonAsync("api/amigo", pepe).Result; if (response.IsSuccessStatusCode) { MessageBox.Show(this, "Amigo creado con éxito", "200 OK", MessageBoxButton.OK, MessageBoxImage.Information); } } }