public void DeleteSelectedUser() { if (SelectedUser != null) { _logger.Info($"Button for deleting selected user pressed. Selected user was not null."); //if access level is not admin (at least one admin account have to stay) and if user is not trying to delete himself bool canBeDeleted = CheckUserDeletionCnditions(SelectedUser.AccessLevel) && (SelectedUser.UserID != _runtimeData.DataOfCurrentlyLoggedUser.Identity); if (!canBeDeleted) { _logger.Info($"Deleting user with ID: {SelectedUser.UserID} cannot be done because of deletion codiftions."); MessageBox.Show("This user cannot be deleted.", "Information", MessageBoxButton.OK, MessageBoxImage.Information); } else { MessageBoxResult msgRes = MessageBox.Show($"Are you sure to delete {SelectedUser.UserName} accunt?", "Confirm", MessageBoxButton.OKCancel, MessageBoxImage.Warning); if (msgRes == MessageBoxResult.OK) { _logger.Info($"Deletion of user confirmed. Start deletion."); UserDataManipulationHandler deleter = new UserDataManipulationHandler(_realmProvider); bool done = deleter.DeleteUser(SelectedUser.UserID); ReadAllUserDataFromDB(); if (!done) { _logger.Info($"Deleting user with ID: {SelectedUser.UserID} went wrong!"); MessageBox.Show("Couldn't delete this user from DB!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } } } }
//method with algorithm for adding new user to DB private (bool, bool) ExecuteAddingNewUserAlgorithm() { bool newUserSuccessfullyAdded = false; _logger.Info($"Execution of algorithm for checking if inputed data was correct (new user mode), started."); bool ok = CheckUserName(); if (ok) { ok = CheckPasswords(); } if (ok) { ok = CheckIfAccessLevelIsChoosen(); } if (ok) { ok = CheckIfTimeoutIsChoosen(); } if (ok) { _logger.Info($"Adding new user to DB procedure started."); UserDataManipulationHandler adder = new UserDataManipulationHandler(_realmProvider); newUserSuccessfullyAdded = adder.AddNewUser(UserNameText, PasswordText1, SelectedLevel.AccessLevel, AutomaticLogOff, SelectedTimeout.Minutes, CountLanguagePrevilages()); } return(newUserSuccessfullyAdded, ok); }
//method with algorithm for modifying existing user in DB private (bool, bool) ExecuteUserModificationAlgorithm() { bool userSuccessfullyModified = false; _logger.Info($"Execution of algorithm for checking if inputed data was correct (modifying user mode), started."); bool ok = CheckIfAccessLevelIsChoosen(); if (ok) { ok = CheckIfTimeoutIsChoosen(); } if (ok) { _logger.Info($"Modifying existing user in DB procedure started."); UserDataManipulationHandler modifier = new UserDataManipulationHandler(_realmProvider); userSuccessfullyModified = modifier.ModifyUser(_modificatedPlayerID, SelectedLevel.AccessLevel, AutomaticLogOff, SelectedTimeout.Minutes, CountLanguagePrevilages()); } return(userSuccessfullyModified, ok); }
private void CreateUserHandler() { _handler = new UserDataManipulationHandler(_realmProvider); }