private async void BtnGuardarRegistrarDivisionMateriasPrimas_Clicked(object sender, EventArgs e) { string connectionString = ConfigurationManager.AppSettings["ipServer"]; try { var nombreDivisionMateriasPrimasV = nombreDivisionesMateriasPrimas.Text; if (string.IsNullOrEmpty(nombreDivisionMateriasPrimasV)) { await DisplayAlert("Validacion", "Ingrese la división de la materia prima", "Aceptar"); nombreDivisionesMateriasPrimas.Focus(); return; } HttpClient client = new HttpClient(); client.BaseAddress = new Uri(connectionString); var divisionMateriasPrimas = new DivisionesMateriasPrima() { DivisionMateriaPrimaID = 0, Division = nombreDivisionMateriasPrimasV, }; //Convetir a Json var json = JsonConvert.SerializeObject(divisionMateriasPrimas); StringContent stringContent = new StringContent(json, Encoding.UTF8, "application/json"); //Ejecutar el api el introduces el metodo var request = await client.PostAsync("/api/DivisionesMateriasPrima/registrar", stringContent); if (request.IsSuccessStatusCode) { var responseJson = await request.Content.ReadAsStringAsync(); var respuesta = JsonConvert.DeserializeObject <Request>(responseJson); //Status if (respuesta.status) { await MaterialDialog.Instance.AlertAsync(message : "La División de la materia prima se registro correctamente", title : "Registro", acknowledgementText : "Aceptar"); } else { await MaterialDialog.Instance.AlertAsync(message : "La División de la materia prima no pudo registrarse correctamente", title : "Registro", acknowledgementText : "Aceptar"); } } else { await MaterialDialog.Instance.AlertAsync(message : "Error", title : "Error", acknowledgementText : "Aceptar"); } } catch (Exception ex) { await MaterialDialog.Instance.AlertAsync(message : ex.Message, title : "Error", acknowledgementText : "Aceptar"); } limpiarCampos(); await Navigation.PushAsync(new DivisionesMateriasPrimas.GestionarDivisionesMateriasPrimas()); }
private async void BtnModificarDivisionMateriaPrima_Clicked(object sender, EventArgs e) { string connectionString = ConfigurationManager.AppSettings["ipServer"]; try { var ModificarDivisioMateriaPrimaIDV = divisionMateriaPrimaID; var ModificarDivisionMateriaPrimaV = nombreModificarDivisionMateriaPrima.Text; if (string.IsNullOrEmpty(ModificarDivisionMateriaPrimaV)) { await DisplayAlert("Validacion", "Asegurar que la división esté ingresada", "Aceptar"); nombreModificarDivisionMateriaPrima.Focus(); return; } HttpClient client = new HttpClient(); client.BaseAddress = new Uri(connectionString); var ModificarDivisionMateriaPrima = new DivisionesMateriasPrima() { DivisionMateriaPrimaID = divisionMateriaPrimaID, Division = ModificarDivisionMateriaPrimaV }; var json = JsonConvert.SerializeObject(ModificarDivisionMateriaPrima); StringContent stringContent = new StringContent(json, Encoding.UTF8, "application/json"); var request = await client.PostAsync("/api/DivisionesMateriasPrima/modificar", stringContent); if (request.IsSuccessStatusCode) { var responseJson = await request.Content.ReadAsStringAsync(); var respuesta = JsonConvert.DeserializeObject <Request>(responseJson); if (respuesta.status) { await MaterialDialog.Instance.AlertAsync(message : "La división se modificó correctamente", title : "Modificación", acknowledgementText : "Aceptar"); } else { await MaterialDialog.Instance.AlertAsync(message : "La división no pudo modificarse correctamente", title : "Modificacion", acknowledgementText : "Aceptar"); } } else { await MaterialDialog.Instance.AlertAsync(message : "Error", title : "Error", acknowledgementText : "Aceptar"); } } catch (Exception ex) { await MaterialDialog.Instance.AlertAsync(message : ex.Message, title : ex.Message, acknowledgementText : "Aceptar"); } await Navigation.PushAsync(new DivisionesMateriasPrimas.GestionarDivisionesMateriasPrimas()); }