private void savebtn_Click(object sender, RoutedEventArgs e)
        {
            if (SystemClass.CheckConnection())
            {
                if (newpasswordpb.Password != confirmpasswordpb.Password)
                {
                    MessageBox.Show("Password mismatch!");
                }
                else
                {
                    Employee   employee       = db.Employees.Find(App.EmployeeID);
                    AspNetUser asp            = db.AspNetUsers.FirstOrDefault(m => m.UserName == employee.EmployeeNo);
                    var        passwordHasher = new Microsoft.AspNet.Identity.PasswordHasher();
                    asp.PasswordHash = passwordHasher.HashPassword(confirmpasswordpb.Password);
                    db.SaveChanges();
                    MessageBox.Show("Password updated successfully!");

                    var audit = new AuditTrailModel
                    {
                        Activity   = "User changes his/her password.",
                        ModuleName = this.GetType().Name,
                        EmployeeID = App.EmployeeID
                    };

                    SystemClass.InsertLog(audit);
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show(SystemClass.DBConnectionErrorMessage);
            }
        }
        private void btnSubmit_Click(object sender, RoutedEventArgs e)
        {
            if (SystemClass.CheckConnection())
            {
                try
                {
                    using (var db = new ImusCityHallEntities())
                    {
                        if (!String.IsNullOrEmpty(txtAnswer.Text))
                        {
                            var getanswer = db.SecurityQuestionUsers.Where(m => m.EmployeeID == App.EmployeeID && m.SecurityQuestionID == QuestionID).FirstOrDefault();

                            if (getanswer != null)
                            {
                                string inputAnswer = txtAnswer.Text;
                                if (inputAnswer.TrimStart().Trim().TrimEnd().ToLower() == getanswer.Answer.TrimStart().Trim().TrimEnd().ToLower())
                                {
                                    ChangePasswordWindow cp = new ChangePasswordWindow();
                                    cp.Show();
                                    var audit = new AuditTrailModel
                                    {
                                        Activity   = "User answer a security question for Forgot Password.",
                                        ModuleName = this.GetType().Name,
                                        EmployeeID = App.EmployeeID
                                    };

                                    SystemClass.InsertLog(audit);
                                    this.Close();
                                }
                                else
                                {
                                    MessageBox.Show("Incorrect answer.");
                                    return;
                                }
                            }
                            else
                            {
                                MessageBox.Show("Question not available.");
                                return;
                            }
                        }
                        else
                        {
                            MessageBox.Show("Please input answer.");
                            return;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
            else
            {
                MessageBox.Show(SystemClass.DBConnectionErrorMessage);
            }
        }
        private void loginbtn_Click(object sender, RoutedEventArgs e)
        {
            Mouse.OverrideCursor = Cursors.Wait;
            try
            {
                if (String.IsNullOrEmpty(usernametb.Text) || String.IsNullOrEmpty(passwordpb.Password))
                {
                    MessageBox.Show("Please input your sign-in credentials");
                }
                else
                {
                    if (SystemClass.CheckConnection())
                    {
                        using (var db = new ImusCityHallEntities())
                        {
                            var    passwordHasher = new Microsoft.AspNet.Identity.PasswordHasher();
                            string pass           = "";
                            var    asp            = db.AspNetUsers.Where(m => m.UserName == usernametb.Text).FirstOrDefault();

                            if (asp != null)
                            {
                                pass = passwordHasher.VerifyHashedPassword(asp.PasswordHash, passwordpb.Password).ToString();
                            }
                            else
                            {
                                MessageBox.Show("Log-in failed!");
                                Mouse.OverrideCursor = null;
                                return;
                            }

                            if (pass == "Success")
                            {
                                Mouse.OverrideCursor = Cursors.Wait;
                                var emp = db.Employees.FirstOrDefault(m => m.EmployeeNo == usernametb.Text);
                                App.EmployeeID = emp.EmployeeID;

                                if (passwordpb.Password == "imuscitygov")
                                {
                                    Mouse.OverrideCursor = null;
                                    MessageBox.Show("Please change your default password.");
                                    ChangePasswordWindow password = new ChangePasswordWindow();
                                    password.Show();
                                }
                                else if (emp.SecurityQuestionUsers.Count < 3 && emp.EmployeeNo != "123456")
                                {
                                    Mouse.OverrideCursor = null;
                                    MessageBox.Show("Please set-up your security questions.");
                                    SecurityQuestion secquestion = new SecurityQuestion();
                                    secquestion.Show();
                                    //
                                }
                                else
                                {
                                    var audit = new AuditTrailModel
                                    {
                                        Activity   = "Log-in to the system",
                                        ModuleName = this.GetType().Name,
                                        EmployeeID = App.EmployeeID
                                    };

                                    SystemClass.InsertLog(audit);
                                    MainWindow mw = new MainWindow();
                                    mw.Password = passwordpb.Password;
                                    mw.Show();
                                    this.Close();
                                }
                            }
                            else
                            {
                                MessageBox.Show("Log-in failed!");
                                Mouse.OverrideCursor = null;
                                return;
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show(SystemClass.DBConnectionErrorMessage);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            Mouse.OverrideCursor = null;
        }
        private void savebtn_Click(object sender, RoutedEventArgs e)
        {
            if (SystemClass.CheckConnection())
            {
                using (var db = new ImusCityHallEntities())
                {
                    QList = new List <QuestionList>();
                    if (!String.IsNullOrEmpty(cbSecurityQuestion1.Text) && !String.IsNullOrEmpty(txtAnswer1.Text))
                    {
                        QuestionList ql          = new QuestionList();
                        int          QuestionID1 = Convert.ToInt32(cbSecurityQuestion1.SelectedValue);
                        ql.EmployeeID = App.EmployeeID;
                        ql.QuestionID = QuestionID1;
                        ql.Answer     = txtAnswer1.Text;
                        QList.Add(ql);
                    }
                    else
                    {
                        MessageBox.Show("Please answer security questions.");
                        return;
                    }
                    if (!String.IsNullOrEmpty(cbSecurityQuestion2.Text) && !String.IsNullOrEmpty(txtAnswer2.Text))
                    {
                        QuestionList ql          = new QuestionList();
                        int          QuestionID2 = Convert.ToInt32(cbSecurityQuestion2.SelectedValue);
                        ql.EmployeeID = App.EmployeeID;
                        ql.QuestionID = QuestionID2;
                        ql.Answer     = txtAnswer2.Text;
                        QList.Add(ql);
                    }
                    else
                    {
                        MessageBox.Show("Please answer security questions.");
                        return;
                    }
                    if (!String.IsNullOrEmpty(cbSecurityQuestion3.Text) && !String.IsNullOrEmpty(txtAnswer3.Text))
                    {
                        QuestionList ql          = new QuestionList();
                        int          QuestionID3 = Convert.ToInt32(cbSecurityQuestion3.SelectedValue);
                        ql.EmployeeID = App.EmployeeID;
                        ql.QuestionID = QuestionID3;
                        ql.Answer     = txtAnswer3.Text;
                        QList.Add(ql);
                    }
                    else
                    {
                        MessageBox.Show("Please answer security questions.");
                        return;
                    }

                    foreach (var x in QList)
                    {
                        SecurityQuestionUser squ = new SecurityQuestionUser();
                        squ.EmployeeID         = x.EmployeeID;
                        squ.SecurityQuestionID = x.QuestionID;
                        squ.Answer             = x.Answer;
                        db.SecurityQuestionUsers.Add(squ);
                        db.SaveChanges();
                    }

                    MessageBox.Show("Security Questions set-up succesfully!");
                    var audit = new AuditTrailModel
                    {
                        Activity   = "User set-up security questions.",
                        ModuleName = this.GetType().Name,
                        EmployeeID = App.EmployeeID
                    };

                    SystemClass.InsertLog(audit);
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show(SystemClass.DBConnectionErrorMessage);
            }
        }