public void Guardar() { try { using (var db = new ModeloSistema()) { if (this.usuario_id > 0) { db.Entry(this).State = EntityState.Modified; } else { db.Entry(this).State = EntityState.Added; } db.SaveChanges(); } } catch (Exception ex) { throw; } }
//metodo de perfil public ResponseModel Guardarperfil(HttpPostedFileBase Foto) { var rm = new ResponseModel(); try { using (var db = new ModeloSistema()) { db.Configuration.ValidateOnSaveEnabled = false; var usu = db.Entry(this); usu.State = EntityState.Modified; if (Foto != null) { string extension = Path.GetExtension(Foto.FileName).ToLower(); int size = 1024 * 1024 * 5; var filtroextension = new[] { ".jpg", ".png", ".jpeg" }; var extensiones = Path.GetExtension(Foto.FileName); if (filtroextension.Contains(extensiones) && (Foto.ContentLength <= size)) { string archivo = Path.GetFileName(Foto.FileName); Foto.SaveAs(HttpContext.Current.Server.MapPath("~/Uploads/" + archivo)); this.avatar = archivo; } } else { usu.Property(x => x.avatar).IsModified = false; } if (this.usuario_id == 0) { usu.Property(x => x.usuario_id).IsModified = false; } if (this.docente_id == 0) { usu.Property(x => x.docente_id).IsModified = false; } if (this.nombre == null) { usu.Property(x => x.nombre).IsModified = false; } if (this.clave == null) { usu.Property(x => x.clave).IsModified = false; } if (this.nivel == null) { usu.Property(x => x.nivel).IsModified = false; } if (this.estado == null) { usu.Property(x => x.estado).IsModified = false; } db.SaveChanges(); rm.SetResponse(true); } } catch (DbEntityValidationException e) { throw; } catch (Exception) { throw; } return(rm); }