private void MakeStaffButton_Click(object sender, RoutedEventArgs e) { if (!Staff.Can(StaffModel.Permission.AccessEmployeeData)) { MessageBox.Show("You do not have permission to do this!", "Not Authorised!", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (selectedRow == null) { return; } CustomerModel selected = selectedRow as CustomerModel; var toStaff = new StaffModel() { ID = selected.ID, FirstName = selected.FirstName, LastName = selected.LastName, PhoneNumber = selected.PhoneNumber, EmailAddress = selected.EmailAddress, Address = selected.Address }; toStaff.Permissions = DBAccessHelper.CalculatePermissions(1); DBAccessHelper.AlterStaff(toStaff, 1); }
private bool SaveStaffChanges() { if (!CheckFields()) { return(false); } #region Calculate new permissions byte newPerms = 0; if (employeeCB_RCD.IsChecked ?? false) { newPerms += 1; } if (employeeCB_WCD.IsChecked ?? false) { newPerms += 2; } if (employeeCB_DCD.IsChecked ?? false) { newPerms += 4; } if (employeeCB_RSD.IsChecked ?? false) { newPerms += 8; } if (employeeCB_WSD.IsChecked ?? false) { newPerms += 16; } if (employeeCB_DSD.IsChecked ?? false) { newPerms += 32; } if (employeeCB_AED.IsChecked ?? false) { newPerms += 64; } #endregion Calculate new permissions var changedModel = new StaffModel() { ID = ((StaffModel)selectedRow).ID, FirstName = formEmployeeFirstNameTextbox.Text.Trim(), LastName = formEmployeeLastNameTextbox.Text.Trim(), PhoneNumber = formEmployeePhoneNumberTextbox.Text.Trim(), EmailAddress = formEmployeeEmailAddressTextbox.Text.Trim(), Address = $"{formEmployeeHouseNumberNameTextbox.Text.Trim()}|{formEmployeePostCodeTextbox.Text.Trim()}" }; bool changeEmail = employeePasswordTb.Visibility == Visibility.Visible; if (changeEmail) { if (formEmployeePasswordbox.Password == string.Empty) { MessageBox.Show("You need to input the staff member's password to change their email.", "No password entered!"); } else { return(DBAccessHelper.AlterStaff(changedModel, ((StaffModel)selectedRow).EmailAddress, formEmployeePasswordbox.Password, newPerms)); } } return(DBAccessHelper.AlterStaff(changedModel, newPerms)); }