private void btnAgregarEditorial_Click(object sender, EventArgs e) { if (btnAgregarEditorial.Text == "Agregar") { using (contexto db = new contexto()) { EDITORIAL nuevaEditorial = new EDITORIAL(); nuevaEditorial.descEditorial = txtEditorial.Text; db.EDITORIALs.Add(nuevaEditorial); db.SaveChanges(); cargarTablaEditoriales(); } } else { if (idEditorial != 0) { using (contexto db = new contexto()) { EDITORIAL editorialMod = db.EDITORIALs.Find(idEditorial); editorialMod.descEditorial = txtEditorial.Text; db.Entry(editorialMod).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); cargarTablaEditoriales(); } } } }
private void btnEliminarEditorial_Click(object sender, EventArgs e) { if (idEditorial != 0) { using (contexto db = new contexto()) { EDITORIAL editorialDel = db.EDITORIALs.Find(idEditorial); db.EDITORIALs.Remove(editorialDel); db.SaveChanges(); cargarTablaEditoriales(); } } }