//validar login public ResponseModel ValidarLogin(string Usuario, string Password) { var rm = new ResponseModel(); try { using (var db = new ModeloDatos()) { Password = HashHelper.MD5(Password); var usuario = db.Usuario.Where(x => x.nombre == Usuario) .Where(x => x.clave == Password).Where(x => x.estado.Equals("Activo")) .SingleOrDefault(); if (usuario != null) { SessionHelper.AddUserToSession(usuario.usuario_id.ToString()); rm.SetResponse(true); } else { rm.SetResponse(false, "¡Usuario o Password incorrecto! Ó ¡Usuario Inactivo!"); } } } catch (Exception e) { throw; } return(rm); }
//guardardocumento //Todo frontend //guardardocumento public ResponseModel GuardarDocumento(HttpPostedFileBase rar) { var rm = new ResponseModel(); string nombrearchivo = ""; try { using (var db = new ModeloDatos()) { db.Configuration.ValidateOnSaveEnabled = false; var Doc = db.Entry(this); Doc.State = System.Data.Entity.EntityState.Modified; if (rar != null) { string extension = Path.GetExtension(rar.FileName).ToLower(); var filtroextension = new[] { ".rar" }; var extensiones = Path.GetExtension(rar.FileName); if (filtroextension.Contains(extensiones)) { string archivo = Path.GetFileName(rar.FileName); nombrearchivo = Path.GetFileName(rar.FileName); rar.SaveAs(HttpContext.Current.Server.MapPath("~/Server/Docs/" + archivo)); this.nombre = archivo; this.tamanio = rar.ContentLength.ToString(); this.nombre = nombrearchivo; string value = extension; char delimiter = '.'; string[] substrings = value.Split(delimiter); foreach (var substring in substrings) { this.extension = substring; } this.estado = "Activo"; } } /// else rar.Property(X => X.nombre).IsModified = false; //if (this.estado == null) rar.Property(x => x.estado).IsModified = false; db.Entry(this).State = EntityState.Added; //si el valor es cero va a agregar db.SaveChanges(); rm.SetResponse(true); } } catch (DbEntityValidationException e) { throw; } catch (Exception) { throw; } return(rm); }
public ResponseModel GuardarPerfil(HttpPostedFileBase Foto) { var rm = new ResponseModel(); try { using (var db = new ModeloDatos()) { 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 * 7; //7 megas var filtroextension = new[] { ".jpg", ".jpeg", ".png", ".gif" }; 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("~/Server/Images/" + 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.persona_id == 0) { Usu.Property(x => x.persona_id).IsModified = false; } if (this.tipousuario == 0) { Usu.Property(x => x.tipousuario).IsModified = false; } if (this.clave == null) { Usu.Property(x => x.clave).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); }