//Metodo Guardar public void Guardar() { try { using (var db = new Modelo_Examen()) { if (this.persona_id > 0)//sis existe un valor mayor a cero es porque existe registro { db.Entry(this).State = System.Data.Entity.EntityState.Modified; } else { //SINO EXISTE EL REGISTRO LO GRABA(nuevo) db.Entry(this).State = System.Data.Entity.EntityState.Added; } db.SaveChanges(); } } catch (Exception ex) { throw; } }
//metodo Eliminar public void Eliminar() { try { using (var db = new Modelo_Examen()) { db.Entry(this).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); } } catch (Exception ex) { throw; } }