// function to check if the username already exists.
    // return 1 if username is available
    public int checkAvailability(String username, String email)
    {
        List<String> myList1 = new List<string>();
        List<String> myList2 = new List<string>();

        DBConnection myConnection = new DBConnection();
        myConnection.connect("LILY-PC", "projectdb1", "admin", "123");
        String query1 = String.Format("SELECT * FROM UserAcc WHERE u_name = '{0}'", username);
        String query2 = String.Format("SELECT email FROM Candidate WHERE email = '{0}'", email);

        myList1 = myConnection.getResultsList(query1, "u_name");
        myList2 = myConnection.getResultsList(query2, "email");

        if ((myList1.Count >= 1) || (myList2.Count >= 1)) { return 0; }
        else { return 1; }
    }
 public List<String> getListOfForums()
 {
     DBConnection myConnection = new DBConnection();
     myConnection.connect("LILY-PC", "projectdb1", "admin", "123");
     String query = "SELECT f_title FROM [projectdb1].[dbo].[Forum]";
     return myConnection.getResultsList(query, "f_title");
 }
 public String getForumID(String forumName)
 {
     List<String> myList = new List<string>();
     DBConnection myConnection = new DBConnection();
     myConnection.connect("LILY-PC", "projectdb1", "admin", "123");
     String query = String.Format("SELECT f_id FROM [projectdb1].[dbo].[Forum] WHERE f_title = '{0}'", forumName);
     myList = myConnection.getResultsList(query, "f_id");
     return myList.First();
 }
 // functionto check the password for a given username
 public int checkPassword(String username, String password)
 {
     List<String> myList1 = new List<string>();
     List<String> myList2 = new List<string>();
     DBConnection myConnection = new DBConnection();
     myConnection.connect("LILY-PC", "projectdb1", "admin", "123");
     String query = String.Format("SELECT * FROM UserAcc WHERE u_name='{0}'", username);
     myList1 = myConnection.getResultsList(query, "u_name");
     myList2 = myConnection.getResultsList(query, "passd");
     String[] array1 = myList1.ToArray();
     String[] array2 = myList2.ToArray();
     for (int i = 0; i < array1.Length; i++ )
     {
         if (array1[i]==username && array2[i]==password) { return 1; }
     }
     return 0;
 }
 public String getUsername()
 {
     String userId = (String)HttpContext.Current.Session["userID"];
     DBConnection myConnection = new DBConnection();
     myConnection.connect("LILY-PC", "projectdb1", "admin", "123");
     String query = String.Format("SELECT u_name FROM UserAcc WHERE u_id='{0}'", userId);
     return myConnection.getResultsList(query, "u_name").ElementAt(0);
 }
 public String getID(String username)
 {
     String id; List<String> myList = new List<string>();
     DBConnection myConnection = new DBConnection();
     myConnection.connect("LILY-PC", "projectdb1", "admin", "123");
     String query = String.Format("SELECT * FROM UserAcc WHERE u_name='{0}'", username);
     myList = myConnection.getResultsList(query, "u_id");
     String[] array = myList.ToArray();
     id = array[0];
     return id;
 }
 public String getFirstName(String userId)
 {
     List<String> myList = new List<string>();
     DBConnection myConnection = new DBConnection();
     myConnection.connect("LILY-PC", "projectdb1", "admin", "123");
     String query = String.Format("SELECT f_name FROM Candidate WHERE u_id='{0}'", userId);
     myList = myConnection.getResultsList(query, "f_name");
     if (myList.Count == 0)
     {
         return this.getUsername();
     }
     return myList.ElementAt(0);
 }