/// <summary> /// Author: Caitlin Abelson /// Created Date: 1/30/19 /// /// The btnSave_Click method is used for saving a new employee or updating /// an existing employee in the system. /// </summary> private void btnSave_Click(object sender, RoutedEventArgs e) { if (btnSave.Content.Equals("Submit")) { if (!ValidateInput()) { return; } _newEmployee = new Employee() { FirstName = txtFirstName.Text, LastName = txtLastName.Text, Email = txtEmail.Text, PhoneNumber = txtPhone.Text, DepartmentID = cbxDepartment.SelectedItem.ToString() }; Role role = new Role(); role.RoleID = cbxEmployeeRole.SelectedItem.ToString(); _newEmployee.EmployeeRoles.Add(role); try { if (_oldEmployee == null) { _employeeManager.InsertEmployee(_newEmployee); Employee employeeExtra = _employeeManager.RetrieveEmployeeIDByEmail(_newEmployee.Email); _employeeManager.AddEmployeeRole(employeeExtra.EmployeeID, _newEmployee.EmployeeRoles[0]); MessageBox.Show("Employee Created: " + "\nFirst Name: " + _newEmployee.FirstName + "\nLast Name: " + _newEmployee.LastName + "\nEmail: " + _newEmployee.Email + "\nPhone Number: " + _newEmployee.PhoneNumber + "\nDepartment: " + _newEmployee.DepartmentID); } else { _newEmployee.Active = (bool)chkActive.IsChecked; _employeeManager.UpdateEmployee(_newEmployee, _oldEmployee); SetError(""); _employeeManager.RemoveEmployeeRole(_oldEmployee.EmployeeID, _oldEmployee.EmployeeRoles[0]); _employeeManager.AddEmployeeRole(_oldEmployee.EmployeeID, _newEmployee.EmployeeRoles[0]); MessageBox.Show("Employee update successful: " + "\nNew First Name: " + _newEmployee.FirstName + "\nNew Last Name: " + _newEmployee.LastName + "\nNew Phone Number: " + _newEmployee.PhoneNumber + "\nNew Email: " + _newEmployee.Email + "\nNew DepartmentID: " + _newEmployee.DepartmentID + "\nOld First Name: " + _oldEmployee.FirstName + "\nOld Last Name: " + _oldEmployee.LastName + "\nOld Phone Number: " + _oldEmployee.PhoneNumber + "\nOld Email: " + _oldEmployee.Email + "\nOld DepartmentID: " + _oldEmployee.DepartmentID); } } catch (Exception ex) { SetError(ex.Message); } Close(); } else if (btnSave.Content.Equals("Update")) { editableForm(); } }