//Metodo Eliminar public void Eliminar() { try { using (var db = new modeloEscuela()) { db.Entry(this).State = EntityState.Deleted; db.SaveChanges(); } } catch (Exception ex) { throw; } }
public ResponseModel GuardarPerfil(HttpPostedFileBase Foto) { var rm = new ResponseModel(); try { using (var db = new modeloEscuela()) { db.Configuration.ValidateOnSaveEnabled = false; var Usu = db.Entry(this); Usu.State = EntityState.Modified; if (this.usuario_id == 0) { Usu.Property(x => x.usuario_id).IsModified = false; } if (this.persona_id == 0) { Usu.Property(x => x.persona_id).IsModified = false; } if (this.usuario_nombre == null) { Usu.Property(x => x.usuario_nombre).IsModified = false; } if (this.usuario_contraseña == null) { Usu.Property(x => x.usuario_contraseña).IsModified = false; } if (this.usuario_estado == null) { Usu.Property(x => x.usuario_estado).IsModified = false; } db.SaveChanges(); rm.SetResponse(true); } } catch (DbEntityValidationException e) { throw; } catch (Exception) { throw; } return(rm); }
//Metodo Guardar public void Guardar() { try { using (var db = new modeloEscuela()) { if (this.entrada_id > 0) { db.Entry(this).State = EntityState.Modified; } else { db.Entry(this).State = EntityState.Added; } db.SaveChanges(); } } catch { } }