protected void Modificar_Click(object sender, EventArgs e) { using (ModeloFMI contextoBD = new ModeloFMI()) { int modificar = Convert.ToInt32(cmbpais.SelectedValue); GestionPrestamos aux = contextoBD.GestionPrestamoes.Where(x => x.idPais == modificar).FirstOrDefault(); if (aux == null) { ScriptManager.RegisterStartupScript(this, this.GetType(), "s1", "alert('El registro no se encontro')", true); return; } aux.idPais = Convert.ToInt32(cmbpais.SelectedValue); aux.Habitantes = Convert.ToInt32(txtHabitantes.Text); aux.idIdioma = Convert.ToInt32(cmbIdioma.SelectedValue); aux.PIB = Convert.ToDecimal(txtPIB.Text); aux.Superficie = Convert.ToInt32(txtSuperficie.Text); aux.Prestamo = Check.Checked; aux.Riesgo = Radio.SelectedItem.Text; contextoBD.SaveChanges(); cargarGrid(); } }
protected void Eliminar_Click(object sender, EventArgs e) { using (ModeloFMI contextoBD = new ModeloFMI()) { int borrado = Convert.ToInt32(cmbpais.SelectedValue); GestionPrestamos aux = contextoBD.GestionPrestamoes.Where(x => x.idPais == borrado).FirstOrDefault(); if (aux == null) { ScriptManager.RegisterStartupScript(this, this.GetType(), "s1", "alert('El registro no se encontro')", true); return; } contextoBD.GestionPrestamoes.Remove(aux); contextoBD.SaveChanges(); cargarGrid(); } }
protected void Registrar_Click(object sender, EventArgs e) { using (ModeloFMI contextoBD = new ModeloFMI()) { GestionPrestamos objPrestamo = new GestionPrestamos(); objPrestamo.idPais = Convert.ToInt32(cmbpais.SelectedValue); objPrestamo.Habitantes = Convert.ToInt32(txtHabitantes.Text); objPrestamo.idIdioma = Convert.ToInt32(cmbIdioma.SelectedValue); objPrestamo.PIB = Convert.ToDecimal(txtPIB.Text); objPrestamo.Superficie = Convert.ToInt32(txtSuperficie.Text); objPrestamo.Prestamo = Check.Checked; objPrestamo.Riesgo = Radio.SelectedItem.Text; contextoBD.GestionPrestamoes.Add(objPrestamo); contextoBD.SaveChanges(); //COMMIT cargarGrid(); } }