I have an intranet web-based application that stores the information of added users in its database.
What I want to do is the following: when the user browses to the webstie, it will check if the user exists in its own database or not. If not, it is going to check his information using Active Directory.
I wrote the method but the problem after checking the database and if the user is not there, it will go to the second method which is checking the organization code of the employee:
public static bool isMember(string userid)
{
Employee employee = new Employee(userid);
if (!String.IsNullOrEmpty(userid))
{
string username = userid;
string connString = "Data Source=appServer\\sqlexpress;Initial Catalog=dbTest;Integrated Security=True";
string cmdText2 = "SELECT Count(*) FROM employee WHERE Username = @username";
using (SqlConnection conn = new SqlConnection(connString))
{
conn.Open();
// Open DB connection.
using (SqlCommand cmd = new SqlCommand(cmdText2, conn))
{
cmd.Parameters.Add("@Username", SqlDbType.VarChar);
cmd.Parameters["@username"].Value = username;
var count = (int)cmd.ExecuteScalar();
return count == 1; // return true if there's only one employee with given name
}
}
}
else if (employee.department.Code == "30003143") //The SapCode of department is "30003143"
return true;
else
return false;
}
So how to fix that? How to make the application goes through (else if) clause if the user does not exist in the database?
Pretty easy: