Beispiel #1
0
        /*REALIZA O LOGIN DO USUARIO*/
        public bool LoginUsuario(string email, string senha)
        {
            UsuarioDAL DAL = new UsuarioDAL(conStr);
            CarrinhoBL CarrinhoBL = new CarrinhoBL(conStr);

            try
            {
                int userId = DAL.dbValidarUsuario(email, senha);

                //Se for igual a -1 é porque a autenticação falhou
                if (userId.Equals(-1))
                {

                    return false;
                }

                //Autenticação bem sucedida, insere na sessão de login o usuario
                else
                {
                    //COLOCA O USER NA SESSAO
                    SessaoUsuario = DAL.dbObterUsuario(userId);

                    //ATRELA O CARRINHO ATIVO A ESTE USUARIO
                    CarrinhoBL.AtrelarCarrinho(ObterUsuarioLogado().ID, CarrinhoBL.ObterCarrinhoAtivo().ID);

                    return true;
                }

            }

            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Beispiel #2
0
        /*INSERE UM NOVO USUARIO*/
        public bool CadastrarUsuario(string nome, string email, string senha)
        {
            UsuarioDAL DAL = new UsuarioDAL(conStr);

            try
            {
                //Caso o e-mail esteja disponivel, insere o usuario na base
                if (DAL.dbEmailDisponivel(email))
                {
                    //string encyptedPass;
                    //DO ENCRYPTION SHIT

                    DAL.dbInserirUsuario(nome, email, senha); //TODO: PASSAR SENHA ENCRYPTADA

                    return true;
                }

                else
                {
                    return false;
                }

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Beispiel #3
0
        /*LISTA TODOS OS USUARIOS*/
        public List<Usuario> ListarUsuarios()
        {
            try
            {
                UsuarioDAL DAL = new UsuarioDAL(conStr);

                return DAL.dbListarUsuarios();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Beispiel #4
0
        /*RETORNA O USUARIO QUE ESTÁ LOGADO*/
        public Usuario ObterUsuarioLogado()
        {
            UsuarioDAL DAL = new UsuarioDAL(conStr);
            try
            {
                if (UsuarioLogado())
                {
                    return SessaoUsuario;
                }

                else
                {
                    throw new Exception("ERRO: Não existe nenhum usuario logado no sistema!");
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }