Beispiel #1
0
        public JsonResult validaUsuario(string email, string senha)
        {
            Cliente   cliente = new Cliente();
            BDConexao conexao = new BDConexao();

            conexao.connection.Open();
            conexao.command.CommandText = "SELECT idCliente FROM CLIENTE WHERE EMAIL = @EMAIL AND SENHA = @SENHA";
            conexao.command.Parameters.Clear();
            conexao.command.Parameters.Add("@EMAIL", SqlDbType.VarChar).Value = email;
            conexao.command.Parameters.Add("@SENHA", SqlDbType.VarChar).Value = StatueStoreEncrypt.Encrypt(senha);

            var result = conexao.command.ExecuteScalar();
            int id;

            Console.WriteLine(result);
            if (result != null && Int32.TryParse(result.ToString(), out id))
            {
                cliente.GetClientById(id);
                return(Json(cliente));
            }
            else
            {
                return(Json("false"));
            }
        }
Beispiel #2
0
        public JsonResult cadastraUsuario(string email, string nome, string sobrenome, string senha, string cpf, string sexo, string dataNascimento)
        {
            Cliente   cliente = new Cliente();
            BDConexao conexao = new BDConexao();

            conexao.connection.Open();
            conexao.command.CommandText = "INSERT INTO CLIENTE OUTPUT INSERTED.IDCLIENTE VALUES(@EMAIL, @SENHA, @NOME, @SOBRENOME, @SEXO, @CPF, @DATANASC, GETDATE(), null)"; conexao.command.Parameters.Clear();
            conexao.command.Parameters.Add("@EMAIL", SqlDbType.VarChar).Value     = email;
            conexao.command.Parameters.Add("@SENHA", SqlDbType.VarChar).Value     = StatueStoreEncrypt.Encrypt(senha);
            conexao.command.Parameters.Add("@NOME", SqlDbType.VarChar).Value      = nome;
            conexao.command.Parameters.Add("@SOBRENOME", SqlDbType.VarChar).Value = sobrenome;
            conexao.command.Parameters.Add("@SEXO", SqlDbType.VarChar).Value      = sexo;
            conexao.command.Parameters.Add("@CPF", SqlDbType.VarChar).Value       = cpf;
            conexao.command.Parameters.Add("@DATANASC", SqlDbType.VarChar).Value  = dataNascimento.Replace("/", "-");

            try
            {
                var id = conexao.command.ExecuteScalar();
                Console.WriteLine(id);
                conexao.connection.Close();
                if (id == null)
                {
                    return(Json(null));
                }
                else
                {
                    cliente.GetClientById(Convert.ToInt32(id));
                    return(Json(cliente));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.GetHashCode());
                return(Json(null));
            }
        }