Name check in c# and firebase

Asked

Viewed 39 times

0

I have not been able to find any results for my question and I will try here. So, I have a firebase database in a c# application and I was wondering if it was possible to check if the name entered is the same or different from the name entered in the database. I appreciate your understanding. I wait for results.

I’ll put a few bits of code for a better answer

I started by creating a "User" and made a function "Eigual_register"

public static bool EIgual_Registo(Usuario user1, Usuario user2)
    {
        if (user1 == null || user2 == null) { return false; }

        if (user1.Nome == user2.Nome)
        {
            erro = "O nome inseirdo já existe na nossa base de dados!";
            return false;
        }
        return true;
    }

Then I created a code where you will do the checks on the page "Register"

private void Butao_registar_Click(object sender, EventArgs e)
    {
        #region Condicao
        if (string.IsNullOrWhiteSpace(textBox_Nome.Text) &&
            string.IsNullOrWhiteSpace(textBox_Pass.Text))
        {
            MessageBox.Show("Favor preencher todos os campos!!");
            ActiveControl = textBox_Nome;
            return;
        }
        #endregion

        FirebaseResponse res = client.Get("Contas/" + textBox_Nome.Text);
        Usuario ResUsuario = res.ResultAs<Usuario>();// resultado da base de dados
        Usuario CurUsuario = new Usuario()
        {
            Nome = textBox_Nome.Text
        };


        if (Usuario.EIgual_Registo(CurUsuario, ResUsuario))
        {
            Usuario usuario = new Usuario()
            {
                Nome = textBox_Nome.Text,
                Pass = textBox_Pass.Text,
                Genero = comboBox_Genero.Text,
                Aniversario = dateTimePicker_Aniversario.Text
            };

            SetResponse set = client.Set(@"Contas/" + textBox_Nome.Text, usuario);

            MessageBox.Show("O Usuário foi inserido com sucesso!");
            Close();
        }
        else
        {
            Usuario.MostraErro();
            textBox_Nome.Clear();
            textBox_Pass.Clear();
        }

    }

i enter the data into the respective fields, and the code actually searches for all the names and really sees that it found an equal name. inserir a descrição da imagem aqui

Now doing with another name. inserir a descrição da imagem aqui

Seriously if someone is there to help me thank you so much!

1 answer

0

So after a night’s sleep, I went back to the code and solved the problem. It was just changing the order in the if cycle. Already in the class section. was simply to do -> "user1.Name != user2.Name" instead of "user1.Name == user2.Name". By the way thank you who commented!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.