private void btn_register_employee_Click(object sender, EventArgs e)
        {
            try
            {
                hideErrors();
                bool noErrors = true;
                if (String.IsNullOrEmpty(tb_username.Text) || (tb_username.Text.Length < 6))
                {
                    usernameErrorLabel.Text    = "Username must be above 6 characters";
                    usernameErrorLabel.Visible = true;
                    noErrors = false;
                }

                if (String.IsNullOrEmpty(tb_password.Text))
                {
                    passwordErrorLabel.Text    = "Password field must be filled";
                    passwordErrorLabel.Visible = true;
                    noErrors = false;
                }

                if (tb_password.Text != tb_repeat_password.Text)
                {
                    confirmPasswordErrorLabel.Text    = "Passwords do not match";
                    confirmPasswordErrorLabel.Visible = true;
                    noErrors = false;
                }

                if (!GeneralUtils.checkPasswordComplexity(tb_password.Text))
                {
                    passwordErrorLabel.Text    = "Password does not match the required complexity";
                    passwordErrorLabel.Visible = true;
                    noErrors = false;
                }

                if (cb_departments.SelectedIndex == -1)
                {
                    departmentErrorLabel.Text    = "Please select department";
                    departmentErrorLabel.Visible = true;
                    noErrors = false;
                }

                if (cb_roles.SelectedIndex == -1)
                {
                    roleErrorLabel.Text    = "Please select role";
                    roleErrorLabel.Visible = true;
                    noErrors = false;
                }
                if (!String.IsNullOrEmpty(tb_phoneNumber.Text))
                {
                    if (!tb_phoneNumber.ValidInput())
                    {
                        phoneNumberErrorLabel.Text    = "The phone number entered is not in a valid format";
                        phoneNumberErrorLabel.Visible = true;
                        noErrors = false;
                    }
                }
                if (noErrors)
                {
                    using (HBSModel _entity = new HBSModel())
                    {
                        User newUser = new User
                        {
                            Username = tb_username.Text
                        };
                        var isAlreadyRegistered = _entity.Users.FirstOrDefault(x => x.Username == newUser.Username);
                        if (isAlreadyRegistered != null)
                        {
                            usernameErrorLabel.Text    = "Username already registered";
                            usernameErrorLabel.Visible = true;
                        }
                        // hash the password
                        GeneralUtils.CreatePasswordHash(tb_password.Text, out byte[] passwordHash, out byte[] passwordSalt);
                        newUser.Pwd         = passwordHash;
                        newUser.PwdSalt     = passwordSalt;
                        newUser.PhoneNumber = tb_phoneNumber.Text;

                        // Find ID of selected role and department
                        try
                        {
                            var _selectedDepartment = _entity.Departments.First(dpt => dpt.DepartmentName == cb_departments.SelectedItem.ToString());
                            var _selectedRole       = _entity.Roles.First(role => role.RoleName == cb_roles.SelectedItem.ToString());
                            newUser.DepartmentID = _selectedDepartment.ID;
                            newUser.RoleID       = _selectedRole.ID;
                        }
                        catch (Exception ex)
                        {
                            DesktopAppUtils.popDefaultErrorMessageBox("Please select valid role and department:\n" + ex.Message);
                            return;
                        }

                        newUser.PhoneNumber = tb_phoneNumber.Text;

                        // get date and make it to datetime2
                        newUser.StartDate = dp_add_employee.Value.Date;

                        // calculate remaining days
                        newUser.RemainingDays = GeneralUtils.CalculateHolidayAllowanceOnRegistration(dp_add_employee.Value.Date);

                        try
                        {
                            _entity.Users.Add(newUser);
                            _entity.SaveChanges();

                            if (MessageBox.Show("Employee successfully registered", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.OK)
                            {
                                tb_username.Text             = "";
                                tb_password.Text             = "";
                                tb_repeat_password.Text      = "";
                                cb_departments.SelectedIndex = -1;
                                cb_roles.SelectedIndex       = -1;
                                dp_add_employee.Value        = DateTime.Now;
                                dp_add_employee.Format       = DateTimePickerFormat.Custom;
                            }
                        }
                        catch
                        {
                            DesktopAppUtils.popDefaultErrorMessageBox("Something went wrong, please try again later");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                DesktopAppUtils.popDefaultErrorMessageBox("Registration Error: \n" + ex.Message);
            }
        }
        public static void CreateUsers()
        {
            using (HBSModel _entity = new HBSModel())
            {
                if (_entity.Users.Count() < 2)
                {
                    byte[] passwordHash, passwordSalt;
                    GeneralUtils.CreatePasswordHash("password", out passwordHash, out passwordSalt);
                    _entity.Users.Add(new User()
                    {
                        Username      = "******",
                        Pwd           = passwordHash,
                        PwdSalt       = passwordSalt,
                        StartDate     = new DateTime(2020, 1, 1),
                        RemainingDays = GeneralUtils.CalculateHolidayAllowanceOnRegistration(new DateTime(2020, 1, 1)),
                        RoleID        = 3,
                        DepartmentID  = 3
                    });
                    _entity.Users.Add(new User()
                    {
                        Username      = "******",
                        Pwd           = passwordHash,
                        PwdSalt       = passwordSalt,
                        StartDate     = new DateTime(2010, 1, 1),
                        RemainingDays = GeneralUtils.CalculateHolidayAllowanceOnRegistration(new DateTime(2010, 1, 1)),
                        RoleID        = 4,
                        DepartmentID  = 3
                    });
                    _entity.Users.Add(new User()
                    {
                        Username      = "******",
                        Pwd           = passwordHash,
                        PwdSalt       = passwordSalt,
                        StartDate     = new DateTime(2019, 1, 1),
                        RemainingDays = GeneralUtils.CalculateHolidayAllowanceOnRegistration(new DateTime(2019, 1, 1)),
                        RoleID        = 6,
                        DepartmentID  = 3
                    });
                    _entity.Users.Add(new User()
                    {
                        Username      = "******",
                        Pwd           = passwordHash,
                        PwdSalt       = passwordSalt,
                        StartDate     = new DateTime(2018, 5, 5),
                        RemainingDays = GeneralUtils.CalculateHolidayAllowanceOnRegistration(new DateTime(2018, 5, 5)),
                        RoleID        = 7,
                        DepartmentID  = 3
                    });
                    _entity.Users.Add(new User()
                    {
                        Username      = "******",
                        Pwd           = passwordHash,
                        PwdSalt       = passwordSalt,
                        StartDate     = new DateTime(2019, 6, 6),
                        RemainingDays = GeneralUtils.CalculateHolidayAllowanceOnRegistration(new DateTime(2019, 6, 6)),
                        RoleID        = 8,
                        DepartmentID  = 3
                    });
                    _entity.Users.Add(new User()
                    {
                        Username      = "******",
                        Pwd           = passwordHash,
                        PwdSalt       = passwordSalt,
                        StartDate     = new DateTime(2019, 2, 2),
                        RemainingDays = GeneralUtils.CalculateHolidayAllowanceOnRegistration(new DateTime(2019, 2, 2)),
                        RoleID        = 5,
                        DepartmentID  = 3
                    });
                    _entity.Users.Add(new User()
                    {
                        Username      = "******",
                        Pwd           = passwordHash,
                        PwdSalt       = passwordSalt,
                        StartDate     = new DateTime(2017, 3, 3),
                        RemainingDays = GeneralUtils.CalculateHolidayAllowanceOnRegistration(new DateTime(2017, 3, 3)),
                        RoleID        = 7,
                        DepartmentID  = 3
                    });
                    _entity.Users.Add(new User()
                    {
                        Username      = "******",
                        Pwd           = passwordHash,
                        PwdSalt       = passwordSalt,
                        StartDate     = new DateTime(2019, 9, 9),
                        RemainingDays = GeneralUtils.CalculateHolidayAllowanceOnRegistration(new DateTime(2019, 9, 9)),
                        RoleID        = 6,
                        DepartmentID  = 3
                    });
                    _entity.Users.Add(new User()
                    {
                        Username      = "******",
                        Pwd           = passwordHash,
                        PwdSalt       = passwordSalt,
                        StartDate     = new DateTime(2012, 6, 6),
                        RemainingDays = GeneralUtils.CalculateHolidayAllowanceOnRegistration(new DateTime(2012, 6, 6)),
                        RoleID        = 5,
                        DepartmentID  = 3
                    });

                    _entity.SaveChanges();
                }
            }
        }