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 button1_Click(object sender, EventArgs e) { try { if (CajaId.Equals("")) { MessageBox.Show("La caja Identificacion esta vacia"); CajaId.Focus(); } else if (CajaNombre.Equals("")) { MessageBox.Show("La caja Nombre esta vacia"); CajaNombre.Focus(); } else if (CajaCantidad.Equals("")) { MessageBox.Show("La caja Cantidad esta vacia "); CajaCantidad.Focus(); } else { MySqlCommand comando = new MySqlCommand("validarUbicacion", conexion.crearConexion()); comando.CommandType = CommandType.StoredProcedure; comando.Parameters.AddWithValue("id", CajaId.Text); comando.Parameters.AddWithValue("nom", CajaNombre.Text); comando.Parameters.AddWithValue("can", CajaCantidad.Text); comando.ExecuteScalar(); MySqlDataReader r = comando.ExecuteReader(); while (r.Read()) { busquedad = r.GetString(0); } if (busquedad.Equals("1")) { MessageBox.Show("El id Ubicacion o el Nombre de la Ubicacion ya Existe!!! "); CajaCantidad.Text = ""; CajaId.Text = ""; CajaNombre.Text = ""; } else { ingresar(); } } } catch (Exception n) { MessageBox.Show("A ocurrido un erro al crear una ubicacion", n.ToString()); } }
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); } } }