Search code examples
c#asp.netapiumbraco

how using if inside public object C# asp.net


I'am new using C# and i have problem when using if inside "public object" method, this my code :

public object Login([FromBody] MailParameters data)
    {

        UmbracoDatabase db = ApplicationContext.DatabaseContext.Database;
        var select = new Sql("SELECT UserID FROM Users where Email='" + data.Email + "';");
        var ids = db.Fetch<listUsersChecks>(select);

        if (ids)
        {
        var getByEncrypt = new Sql("SELECT * FROM Users where Email='" + data.Email + "' AND password='" + data.Password + "';");
        var listue = db.Fetch<listUsers>(getByEncrypt);
        }else{
            var listue = "";
        }
        return listue;
    }

the output is :

error CS0029: Cannot implicitly convert type 'System.Collections.Generic.List<LoginController.listUsersChecks>' to 'bool'

the error is in if(ids){ , how to solved this?

thanks


Solution

  • Look at the error message, if statement required a Boolean, but you feed in with a List. In this case, your ids is a list List<LoginController.listUsersChecks>

    Since it's a list, you can check by counting number of item in this list:

    if(ids.Count >0){} else{}