コード例 #1
0
ファイル: spmUSUtUsuario.cs プロジェクト: jotaele89/receta
        //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);
        }
コード例 #2
0
ファイル: spmUSUtUsuario.cs プロジェクト: jotaele89/receta
        //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);
        }