Home > Software engineering >  Return Boolean from Task, That checks if string exist in Firebase Realtime Database
Return Boolean from Task, That checks if string exist in Firebase Realtime Database

Time:04-30

The Task passes through the two strings from getuser() on to DBFirebase class. It then uses those strings to check if they exist in The Firebase Realtime Database. How can i return "CheckLogin" to Loginpage?. I tried changing the task to Task, but then it prevents the string from sending to the DB. Any Suggestions?

//LoginPage.xaml.cs
public async void getuser()
        {
            await services.LoginCheck(EmailEntry.Text, PasswordEntry.Text);
                       
        }
//DBFirebase.cs
public async Task LoginCheck(string email, string password)
        {

            var LoginCheck = (await Client.Child("users").OnceAsync<users>()).FirstOrDefault(a => a.Object.email == email && a.Object.password == password);
            if (LoginCheck == null)
            {
                CheckLogin = false;

            }
            else
            {
                CheckLogin = true;
            }

CodePudding user response:

public async Task<bool> LoginCheck(string email, string password)
    {
        bool CheckLogin = false;

        var LoginCheck = (await Client.Child("users").OnceAsync<users>()).FirstOrDefault(a => a.Object.email == email && a.Object.password == password);
        if (LoginCheck == null)
        {
            CheckLogin = false;

        }
        else
        {
            CheckLogin = true;
        }

        return CheckLogin;
    }

to call it

var check = await services.LoginCheck(EmailEntry.Text, PasswordEntry.Text);
  • Related