Exemplo n.º 1
0
 private void AddEmployeeCommandExecute(object obj)
 {
     try
     {
         if (EntryValidation.ValidateForLetters(employee.FullName) == false)
         {
             MessageBox.Show("Name can only contain letters. Please try again", "Invalid input");
             return;
         }
         if (EntryValidation.ValidateDate(employee.DateOfBirth) == false)
         {
             MessageBox.Show("Person must be at least 16 years old. Please try again", "Invalid input");
             return;
         }
         if (EntryValidation.ValidateEmail(employee.Email) == false)
         {
             MessageBox.Show("Invalid Email format. Please try again", "Invalid input");
             return;
         }
         if (employee.UserName.Length < 8)
         {
             MessageBox.Show("Username must be at least 8 characters", "Invalid input");
             return;
         }
         if (EntryValidation.ValidateNumber(employee.FloorNumber.ToString()) == false)
         {
             MessageBox.Show("Floor must be a number", "Invalid input");
             return;
         }
         if (EntryValidation.ValidateForLetters(employee.Citizenship) == false)
         {
             MessageBox.Show("Citizenship can only contain letters. Please try again", "Invalid input");
             return;
         }
         if (IsManagerOnGivenFloor(employee.FloorNumber) == false)
         {
             MessageBox.Show("No manager present on a given floor, please choose another floor number.", "Invalid input");
             return;
         }
         string password        = (obj as PasswordBox).Password;
         string encryptPassword = EncryptionHelper.Encrypt(password);
         employee.Password = encryptPassword;
         dataBaseService.AddEmployee(employee);
         MessageBox.Show("New employee registered successfully!", "Info");
         employeeView.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }