private void btnAgregarNuevoRol_Click(object sender, EventArgs e) { roles nrol = new Modelo.roles(); nrol.pkRol = FrmCategoriaRoles.Rol; nrol.sNombre = txtRol.Text; nrol.sDescripcion = txtDescripcion.Text; nrol.modificar(nrol); wRol.cargardatos(); this.Close(); }
public void modificar(roles nrol) { try { using (var ctx = new DataModel()) { ctx.roles.Attach(nrol); ctx.Entry(nrol).State = EntityState.Modified; ctx.SaveChanges(); } } catch (Exception) { throw; } }
public void eliminar(int pkRol) { try { using (var ctx = new DataModel()) { roles user = ctx.roles.Single(r => r.pkRol == pkRol); ctx.Entry(user).State = EntityState.Deleted; ctx.SaveChanges(); } } catch (Exception) { throw; } }
public void guardar(roles nroles) { try { using (var ctx = new DataModel()) { if (nroles.pkRol > 0) { ctx.Entry(nroles).State = EntityState.Modified; } else { ctx.Entry(nroles).State = EntityState.Added; } ctx.SaveChanges(); } } catch (Exception) { throw; } }