// activate jobseeker profile
        public bool ActivateJSProfile(Jobseeker jobseeker)
        {

            try
            {
                DALRecruiterWebsiteManager DALMngr = new DALRecruiterWebsiteManager();
                bool result = DALMngr.UpdateJSProfile(jobseeker);
                return result;
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        private void CreateNewJobseekerProfile()
        {
            //JOB SEEKER SIGNUP METHOD
            string jsUName = txtJSSUUsername.Text.ToString();
            string jsEmail = txtJSSUEmail.Text.ToString();
            string jsPhone = txtJSSUPhone.Text.ToString();
            string jsPassword = txtJSSUPassword.Text.ToString();

            bool runValidation = RunValidation(jsUName, jsEmail, jsPhone, jsPassword);
            if (runValidation)
            {
                string jsActivationCode = Guid.NewGuid().ToString();
                bool jsAccActive = false;
                if (txtJSSUPassword.Text == txtJSSUPasswordConfirm.Text)
                {
                    string saltHashReturned = PasswordHash.CreateHash(txtJSSUPassword.Text);
                    int commaIndex = saltHashReturned.IndexOf(":");
                    string extractedString = saltHashReturned.Substring(0, commaIndex);
                    commaIndex = saltHashReturned.IndexOf(":");
                    extractedString = saltHashReturned.Substring(commaIndex + 1);
                    commaIndex = extractedString.IndexOf(":");
                    string salt = extractedString.Substring(0, commaIndex);
                    commaIndex = extractedString.IndexOf(":");
                    extractedString = extractedString.Substring(commaIndex + 1);
                    string hash = extractedString;
                    Jobseeker js = new Jobseeker(jsUName, jsEmail, jsPhone, salt, saltHashReturned, jsActivationCode, jsAccActive);
                    BLLRecruiterWebsiteManager BLLRWebMngr = new BLLRecruiterWebsiteManager();

                    try
                    {
                        bool result = BLLRWebMngr.CreateJobSeekerProfile(js);
                        if (result)
                        {
                            Session["JobseekerID"] = js.JobseekerID;
                            SendActivationMail(jsEmail, jsUName, jsActivationCode);
                            Page.ClientScript.RegisterStartupScript(this.GetType(), "message", "confirm('Activation Email Sent')", true);
                            Response.Redirect("~/JobseekerActivation.aspx");

                        }
                        else
                        {
                            Page.ClientScript.RegisterStartupScript(this.GetType(), "message", "alert('Error: try again)", true);
                        }
                    }
                    catch (Exception ex)
                    {
                        Response.Write(ex.Message);
                        throw;
                    }
                }
                else
                {
                    txtJSSUPassword.Text = "Passwords don't match!";
                }
            }
        }
        // JOBSEEKER SIGNUP BLL METHOD    

        public bool CreateJobSeekerProfile(Jobseeker js)
        {
            bool result = false;
            DALRecruiterWebsiteManager DALRWebMngr = new DALRecruiterWebsiteManager();

            try
            {
                result = DALRWebMngr.CreateJSProfile(js);
            }
            catch (Exception ex)
            {
                throw;
            }
            return result;
        }
        // Gets a list of all Jobs for the Admin Section

        public List<Jobseeker> GetListOfActiveJobSeekers()
        {
            List<Jobseeker> ListOfActiveJobSeekers = new List<Jobseeker>();

            try
            {

                using (SqlConnection Cxn = new SqlConnection(CxnString))
                {
                    using (SqlCommand Cmd = new SqlCommand("spGetAllJobseekersForAdmin", Cxn))
                    {
                        Cxn.Open();
                        dr = Cmd.ExecuteReader();

                        while (dr.Read())
                        {
                            Jobseeker JobSeekerAdmin = new Jobseeker();
                            
                            int JobSeekerID = Convert.ToInt32(dr.GetValue(Convert.ToInt32(JS_GetJSObject.SP_GET_JS_ID)));
                            string JobSeekerUsername =(dr.GetValue(Convert.ToInt32(JS_GetJSObject.SP_GET_JS_UNAME)).ToString());
                            string JobSeekerEmail = (dr.GetValue(Convert.ToInt32(JS_GetJSObject.SP_GET_JS_EMAIL)).ToString());
                            string JobSeekerPhone = (dr.GetValue(Convert.ToInt32(JS_GetJSObject.SP_GET_JS_PHONE)).ToString());

                            JobSeekerAdmin.JobseekerID = JobSeekerID;
                            JobSeekerAdmin.JobseekerUsername = JobSeekerUsername;
                            JobSeekerAdmin.JobseekerEmail = JobSeekerEmail;
                            JobSeekerAdmin.JobseekerPhone = JobSeekerPhone;

                            ListOfActiveJobSeekers.Add(JobSeekerAdmin);

                        }

                        Cxn.Close();
                        dr.Close();
                    }
                }


            }
            catch (SqlException ex)
            {
                
                throw;
            }

            return ListOfActiveJobSeekers;
        }
        // activate jobseeker profile
        public bool UpdateJSProfile(Jobseeker js)
        {
            bool result = false;
            try
            {
                using (SqlConnection Cxn = new SqlConnection(CxnString))
                {
                    using (SqlCommand Cmd = new SqlCommand("spActiveJSProfile", Cxn))
                    {
                        Cmd.CommandType = CommandType.StoredProcedure;
                        SqlParameter UpdateUserNameParam = new SqlParameter("@JSUsername", SqlDbType.NVarChar, 20);

                        SqlParameter UpdateAccountActive = new SqlParameter("@JSAccountActive", SqlDbType.Bit);

                        UpdateUserNameParam.Value = js.JobseekerUsername;

                        UpdateAccountActive.Value = js.JobseekerAccountActive;


                        Cmd.Parameters.Add(UpdateUserNameParam);

                        Cmd.Parameters.Add(UpdateAccountActive);

                        Cxn.Open();

                        int i = Cmd.ExecuteNonQuery();
                        if (i > 0)
                        {
                            result = true;
                        }
                        Cxn.Close();

                    }
                }
            }

            catch (SqlException ex)
            {
                throw;
            }
            return result;
        }
        // returns list of jobseekers
        public List<Jobseeker> GetListOfJobseekers()
        {
            List<Jobseeker> JSList = new List<Jobseeker>();

            try
            {
                using (SqlConnection Cxn = new SqlConnection(CxnString))
                {
                    using (SqlCommand Cmd = new SqlCommand("spGetAllJS", Cxn))
                    {
                        Cmd.CommandType = CommandType.StoredProcedure;

                        
                        Cxn.Open();
                        dr = Cmd.ExecuteReader();
                        while (dr.Read())
                        {
                            int JSID = Convert.ToInt32(dr.GetValue(Convert.ToInt32(JS_GetJSObject.SP_GET_JS_ID)));
                            string JSUsername = dr.GetValue(Convert.ToInt32(JS_GetJSObject.SP_GET_JS_UNAME)).ToString();
                            string JSEmail = dr.GetValue(Convert.ToInt32(JS_GetJSObject.SP_GET_JS_EMAIL)).ToString();
                            string JSPhone = dr.GetValue(Convert.ToInt32(JS_GetJSObject.SP_GET_JS_PHONE)).ToString();
                            string JSSalt = dr.GetValue(Convert.ToInt32(JS_GetJSObject.SP_GET_JS_SALT)).ToString();
                            string JSSaltPwd = dr.GetValue(Convert.ToInt32(JS_GetJSObject.SP_GET_JS_SPWD)).ToString();
                            string JSAccKey = dr.GetValue(Convert.ToInt32(JS_GetJSObject.SP_GET_JS_ACCKEY)).ToString();
                            bool JSAccActive = dr.GetBoolean(Convert.ToInt32(JS_GetJSObject.SP_GET_JS_ACCACTIVE));

                            Jobseeker JS = new Jobseeker(JSUsername, JSEmail, JSPhone, JSSalt, JSSaltPwd, JSAccKey, JSAccActive);
                            JS.JobseekerID = JSID;
                            JSList.Add(JS);
                        }
                        dr.Close();
                        Cxn.Close();
                    }
                }
                return JSList;
            }
            catch (Exception ex)
            {
                throw;
            }

        }
        //JOBSEEKER LOGIN DAL Method

        public Jobseeker GetJOBSLogin(string jsUName, string jsSHPwd)
        {
            Jobseeker JS = null;

            try
            {
                using (SqlConnection Cxn = new SqlConnection(CxnString))
                {
                    using (SqlCommand Cmd = new SqlCommand("spGetJSLogin", Cxn))
                    {
                        Cmd.CommandType = CommandType.StoredProcedure;

                        SqlParameter InsertUserNameParam = new SqlParameter("@JSSUUsername", SqlDbType.NVarChar, 256);
                        InsertUserNameParam.Value = jsUName;
                        Cmd.Parameters.Add(InsertUserNameParam);
                        Cxn.Open();
                        dr = Cmd.ExecuteReader();
                        while (dr.Read())
                        {
                            int JSID = Convert.ToInt32(dr.GetValue(Convert.ToInt32(JS_GetJSObject.SP_GET_JS_ID)));
                            string JSUsername = dr.GetValue(Convert.ToInt32(JS_GetJSObject.SP_GET_JS_UNAME)).ToString();
                            string JSEmail = dr.GetValue(Convert.ToInt32(JS_GetJSObject.SP_GET_JS_EMAIL)).ToString();
                            string JSPhone = dr.GetValue(Convert.ToInt32(JS_GetJSObject.SP_GET_JS_PHONE)).ToString();
                            string JSSalt = dr.GetValue(Convert.ToInt32(JS_GetJSObject.SP_GET_JS_SALT)).ToString();
                            string JSSaltPwd = dr.GetValue(Convert.ToInt32(JS_GetJSObject.SP_GET_JS_SPWD)).ToString();
                            string JSAccKey = dr.GetValue(Convert.ToInt32(JS_GetJSObject.SP_GET_JS_ACCKEY)).ToString();
                            bool JSAccActive = dr.GetBoolean(Convert.ToInt32(JS_GetJSObject.SP_GET_JS_ACCACTIVE));

                            JS = new Jobseeker(JSUsername, JSEmail, JSPhone, JSSalt, JSSaltPwd, JSAccKey, JSAccActive);
                            JS.JobseekerID = JSID;
                        }
                        dr.Close();
                        Cxn.Close();
                    }
                }
                return JS;
            }
            catch (Exception ex)
            {
                throw;
            }

        }
        //JOBSEEKER SIGNUP DAL METHOD

        public bool CreateJSProfile(Jobseeker js)
        {
            bool result = false;
            try
            {
                using (SqlConnection Cxn = new SqlConnection(CxnString))
                {
                    using (SqlCommand Cmd = new SqlCommand("spCreateJSProfile", Cxn))
                    {
                        Cmd.CommandType = CommandType.StoredProcedure;
                        SqlParameter InsertUserNameParam = new SqlParameter("@JSSUUsername", SqlDbType.NVarChar, 20);
                        SqlParameter InsertEmailParam = new SqlParameter("@JSSSUEmail", SqlDbType.NVarChar, 100);
                        SqlParameter InsertPhoneParam = new SqlParameter("@JSSUPhone", SqlDbType.NVarChar, 10);
                        SqlParameter InsertSaltParam = new SqlParameter("@JSSalt", SqlDbType.NVarChar, 100);
                        SqlParameter InsertSlowHashSalt = new SqlParameter("@JSSlowHashSalt", SqlDbType.NVarChar, 256);
                        SqlParameter InsertActivationKey = new SqlParameter("@JSActivationKey", SqlDbType.NVarChar, 256);
                        SqlParameter InsertAccountActive = new SqlParameter("@JSAccountActive", SqlDbType.Bit);

                        SqlParameter InsertJSIDParam = new SqlParameter("@JSID", SqlDbType.Int);

                        InsertUserNameParam.Value = js.JobseekerUsername;
                        InsertEmailParam.Value = js.JobseekerEmail;
                        InsertPhoneParam.Value = js.JobseekerPhone;
                        InsertSaltParam.Value = js.JobseekerSalt;
                        InsertSlowHashSalt.Value = js.JobseekerSaltHashPwd;
                        InsertActivationKey.Value = js.JobseekerActivationKey;
                        InsertAccountActive.Value = js.JobseekerAccountActive;
                        InsertJSIDParam.Direction = ParameterDirection.Output;

                        Cmd.Parameters.Add(InsertUserNameParam);
                        Cmd.Parameters.Add(InsertEmailParam);
                        Cmd.Parameters.Add(InsertPhoneParam);
                        Cmd.Parameters.Add(InsertSaltParam);
                        Cmd.Parameters.Add(InsertSlowHashSalt);
                        Cmd.Parameters.Add(InsertActivationKey);
                        Cmd.Parameters.Add(InsertAccountActive);
                        Cmd.Parameters.Add(InsertJSIDParam);

                        Cxn.Open();
                        
                        int i = Cmd.ExecuteNonQuery();
                        if(i > 0)
                        {
                            js.JobseekerID = Convert.ToInt32(InsertJSIDParam.Value);
                            result = true;
                        }
                        Cxn.Close();

                    }
                }
            }

            catch (SqlException ex)
            {
                throw;
            }
            return result;
        }