I am using c# and winforms 4.0 to create a lo gin form using entity framework. Question is is my logic right. I am just a we bit worried about the return if it doesn't find a record i add a blank return record is that the correct way using entity framework to return a empty record as I want to pass the information found on the log in screen to the main form.
public NaviHrUsers ValidateUser(string username,string password)
{
try{
NaviHrUsers currentUser = naviEntities.NaviHrUsers.FirstOrDefault(r => r.login == username);
if (currentUser != null)
{
return currentUser;
}
else
{
NaviHrUsers nu = new NaviHrUsers();
nu.login = "";
nu.password = "";
nu.last_login = Convert.ToDateTime("1900/01/01");
nu.last_time = "";
nu.password_last_changed = Convert.ToDateTime("1900/01/01");
return nu;
}
}
catch (Exception ex)
{
throw new EntityContextException("ValidateUser failed.", ex);
}
}