check if the name already exists in the firebase and c#

Asked

Viewed 163 times

1

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!

  • Having no idea how your database is organized, one solution that will work is: read all the records, from the first to the last, and compare with the desired name. If find stop, if you reach the end then the name does not exist in the base.

No answers

Browser other questions tagged

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