Reputation:
I have a method to authenticate my users, but it returns user = null
even if I have records in my table.
public bool AuthenticateUser(string username, string password)
{
var user = GetSingleRow(c => c.Email.Equals(username) && c.Password.Equals(password) && IsActive);
if(user !=null && user.Id > 0)
{
// my statements
}
}
Class & Method Implementation :
public partial class UserAccount :IRepository<UserAccount>
{
private static readonly MeriRanchiDataContext Context;
public UserAccount GetSingleRow(Func<UserAccount, bool> criteria)
{
return Context.UserAccounts.Where(criteria).SingleOrDefault();
//tried this also: return Context.UserAccounts.SingleOrDefault(criteria);
}
}
Upvotes: 0
Views: 162
Reputation: 34297
You're missing your range variable (c) on IsActive. Do this:
var user = GetSingleRow(c => c.Email.Equals(username) && c.Password.Equals(password) && c.IsActive);
Upvotes: 3