//Metodod ValidarLogin public spmClsResponseModel ValidarLogin(string Usuario, string Password) { var rm = new spmClsResponseModel(); try { using (var db = new Modelo_Sistema()) { //Password = spmClsHashHelper.SHA1(Password); //Encriptar Password var usuario = db.spmUSUtUsuario.Where(x => x.USUnombre_usuario == Usuario) //Sentencia LINQ .Where(x => x.USUcontraseña == Password) .SingleOrDefault(); if (usuario != null) { spmClsSessionHelper.AddUserToSession(usuario.USUid.ToString()); rm.SetResponse(true); } else { rm.SetResponse(false, "Usuario o Password incorrecto..."); } } } catch (Exception) { throw; } return(rm); }
//Metodo Eliminar public void Eliminar() { try { using (var db = new Modelo_Sistema()) { db.Entry(this).State = EntityState.Deleted; //elimina el registro db.SaveChanges(); } } catch (Exception ex) { throw; } }
//----------------------------------------------------------------------------------------------------------------- //Metodo Listar public List <spmUSUtUsuario> Listar() //Retorna una colleccion { var objUsuario = new List <spmUSUtUsuario>(); try { using (var db = new Modelo_Sistema()) { objUsuario = db.spmUSUtUsuario.ToList(); //codigo LINQ } } catch (Exception ex) { throw; } return(objUsuario); }
public List <spmRECpReceta> ListarRecetas() //retorna una collection { var objIngrediente = new List <spmRECpReceta>(); try { using (var db = new Modelo_Sistema()) { objIngrediente = db.spmRECpReceta.ToList(); } } catch (Exception ex) { throw; } return(objIngrediente); }
// METODO LISTAR //***************************************************************** public List <spmRINpReceta_Ingrediente> Listar() //retorna una collection { var objRecetaIngre = new List <spmRINpReceta_Ingrediente>(); try { using (var db = new Modelo_Sistema()) { objRecetaIngre = db.spmRINpReceta_Ingrediente.Include("spmINGtIngrediente").Include("spmRECpReceta").ToList(); } } catch (Exception ex) { throw; } return(objRecetaIngre); }
// METODO LISTAR //***************************************************************** public List <spmPADtPadecimiento_Salud> Listar() //retorna una collection { var objSalud = new List <spmPADtPadecimiento_Salud>(); try { using (var db = new Modelo_Sistema()) { objSalud = db.spmPADtPadecimiento_Salud.ToList(); } } catch (Exception ex) { throw; } return(objSalud); }
// METODO LISTAR //***************************************************************** public List <spmRECpReceta> Listar() //retorna una collection { var objReceta = new List <spmRECpReceta>(); try { using (var db = new Modelo_Sistema()) { objReceta = db.spmRECpReceta.Include("spmPADtPadecimiento_Salud").Include("spmUSUtUsuario").ToList(); } } catch (Exception ex) { throw; } return(objReceta); }
//METODO OBTENER //***************************************************************** public spmINGtIngrediente Obtener(int id) // retorna solo un objeto { var objIngrediente = new spmINGtIngrediente(); try { using (var db = new Modelo_Sistema()) { objIngrediente = db.spmINGtIngrediente.Where(x => x.INGid == id) .SingleOrDefault(); } } catch (Exception ex) { throw; } return(objIngrediente); }
//METODO OBTENER //***************************************************************** public spmRINpReceta_Ingrediente Obtener(int id) // retorna solo un objeto { var objRecetaIngre = new spmRINpReceta_Ingrediente(); try { using (var db = new Modelo_Sistema()) { objRecetaIngre = db.spmRINpReceta_Ingrediente.Include("spmINGtIngrediente").Include("spmRECpReceta").Where(x => x.RECid == id) .SingleOrDefault(); } } catch (Exception ex) { throw; } return(objRecetaIngre); }
//METODO OBTENER //***************************************************************** public spmRECpReceta Obtener(int id) // retorna solo un objeto { var objReceta = new spmRECpReceta(); try { using (var db = new Modelo_Sistema()) { objReceta = db.spmRECpReceta.Include("spmPADtPadecimiento_Salud").Include("spmUSUtUsuario").Where(x => x.RECid == id) .SingleOrDefault(); } } catch (Exception ex) { throw; } return(objReceta); }
//Metodo Obtener public spmUSUtUsuario Obtener(int id) //Retorna solo un objeto,por eso no se pone list { var objUsuario = new spmUSUtUsuario(); try { using (var db = new Modelo_Sistema()) { objUsuario = db.spmUSUtUsuario .Where(x => x.USUid == id) .SingleOrDefault(); } } catch (Exception ex) { throw; } return(objUsuario); }
//Metodo Guardar public void Guardar() { try { using (var db = new Modelo_Sistema()) { if (this.USUid > 0) { //si existe un valor mayor a cero, es porque existe el registro db.Entry(this).State = EntityState.Modified; } else { //si no existe el registro lo guarda(nuevo) db.Entry(this).State = EntityState.Added; } db.SaveChanges(); } } catch (Exception ex) { throw; } }
//Metodod Actualizar Perfil Personal public spmClsResponseModel GuardarPerfil(HttpPostedFileBase USUfoto) { var rm = new spmClsResponseModel(); var objUsuario = new spmUSUtUsuario(); try { using (var db = new Modelo_Sistema()) { db.Configuration.ValidateOnSaveEnabled = false; var Usu = db.Entry(this); Usu.State = EntityState.Modified; if (USUfoto != null) { string extension = Path.GetExtension(USUfoto.FileName).ToLower(); int size = 1024 * 1024 * 5; var filtroextension = new[] { ".jpg", ".jpeg", ".png", ".gif", ".PNG", ".JPEG" }; var extensiones = Path.GetExtension(USUfoto.FileName); if (filtroextension.Contains(extensiones) && (USUfoto.ContentLength <= size)) { string archivo = Path.GetFileName(USUfoto.FileName); USUfoto.SaveAs(HttpContext.Current.Server.MapPath("~/Archivos/" + archivo)); this.USUfoto = archivo; } } else { Usu.Property(x => x.USUfoto).IsModified = false; } if (this.USUid == 0) { Usu.Property(x => x.USUid).IsModified = false; } if (this.USUnombre == null) { Usu.Property(x => x.USUnombre).IsModified = false; } if (this.USUapellido == null) { Usu.Property(x => x.USUapellido).IsModified = false; //true para permitir cambiar } if (this.USUnombre_usuario == null) { Usu.Property(x => x.USUnombre_usuario).IsModified = false; } if (this.USUcontraseña == null) { Usu.Property(x => x.USUcontraseña).IsModified = false; } if (this.USUcorreo_electronico == null) { Usu.Property(x => x.USUcorreo_electronico).IsModified = false; } db.SaveChanges(); rm.SetResponse(true); } } catch (DbEntityValidationException e) { throw; } catch (Exception) { throw; } return(rm); }