/// <summary> /// Search for Users /// </summary> /// <param name="clientSearchCriteria">Search criteria.</param> /// <param name="keyWord">Search key word.</param> public void SearchUser( DCU.Enums.UserInfoSearchCriteria clientSearchCriteria, string keyWord) { // 1.) Get Service IUserManagementServices userManagementServices = ComponentManager.GetComponent <IUserManagementServices>(); // 2.) Create Request DCO.Enums.UserInfoSearchCriteriaEnum coreSearchCriteria = UserAccountConverter.ConvertToCoreUserInfoSearchCriteria(clientSearchCriteria); UserManagementRequest request = UserManagementHelper.CreateUserManagementRequest( UserManagementActionType.SearchUsers, searchKeyWord: keyWord, userInfoSearchCriteria: coreSearchCriteria); // 3.) Send Request UserManagementResponse response = userManagementServices.UserManagementHandleRequest(request); // 4.) Handle Response List <DCO.Objects.UserAccount> coreUserAccounts = response.UserAccountsRetrieved; List <DCU.Objects.UserAccount> clientUserAccounts = new List <DCU.Objects.UserAccount>(); foreach (DCO.Objects.UserAccount coreUserAccount in coreUserAccounts) { clientUserAccounts.Add(UserAccountConverter.CovertToClientUserAccount(coreUserAccount)); } // Get the logged in user account that was used by the server // when handling the request. DCU.Objects.UserAccount clientUserAccountLoggedIn = UserAccountConverter.CovertToClientUserAccount(response.RequestorUserAccount); UserAccountEventArgs userAccountEventArgs = createUserAccountEventArgs( UserAccountActionType.SearchUsers, clientUserAccounts, clientUserAccountLoggedIn, response.ResponseErrorMessage); // Broadcast to UserAccountEventArgs that a search user was triggered. EventBus <UserAccountEventArgs> .Broadcast( this, userAccountEventArgs); }
/// <summary> /// Performs a login request to UserManagementServices. /// </summary> /// <param name="userAccount">UserAccount to login.</param> public void Login(DCU.Objects.UserAccount userAccount) { // 1.) Get Service IUserManagementServices userManagementServices = ComponentManager.GetComponent <IUserManagementServices>(); // 2.) Populate and Create Request. DCO.Objects.UserAccount coreUserAccount = new DCO.Objects.UserAccount(); coreUserAccount.Username = userAccount.Username; coreUserAccount.Password = userAccount.Password; UserManagementRequest request = UserManagementHelper.CreateUserManagementRequest( DCO.Enums.UserManagementActionType.Login, coreUserAccount); // 3.) Send Request UserManagementResponse response = userManagementServices.UserManagementHandleRequest (request); // 4.) Handle Response DCU.Objects.UserAccount userAccountLoggedIn = new DCU.Objects.UserAccount(); if (response.UserAccountsRetrieved.Count > 0) { userAccountLoggedIn = UserAccountConverter.CovertToClientUserAccount(response.UserAccountsRetrieved[0]); } UserLoginEventArgs userLoginEventArg; if (response.IsRequestSuccessful) { ComponentManager.RegisterComponent <DCU.Objects.UserAccount>(userAccountLoggedIn); userLoginEventArg = createUserLoginEventArg( LoginResultType.Success, response.ResponseMessage); } else { userLoginEventArg = createUserLoginEventArg( LoginResultType.Failed, response.ResponseErrorMessage); } // 5.) Broadcast via the EventBus. EventBus <UserLoginEventArgs> .Broadcast(this, userLoginEventArg); }
/// <summary> /// Unlocks a User Account /// </summary> /// <param name="userAccount">User Account to be unlocked.</param> public void UnlockUser(DCU.Objects.UserAccount userAccount) { // 1.) Get Service IUserManagementServices userManagementServices = ComponentManager.GetComponent <IUserManagementServices>(); // 2.) Create Request UserManagementRequest request = UserManagementHelper.CreateUserManagementRequest( UserManagementActionType.UnlockUser, UserAccountConverter.CovertToCoreUserAccount(userAccount)); // 3.) Send Request UserManagementResponse response = userManagementServices.UserManagementHandleRequest(request); // 4.) Handle Response UserAccountActionType userAccountActionType; string message; if (response.IsRequestSuccessful) { userAccountActionType = UserAccountActionType.UnlockUser; message = response.ResponseMessage; } else { userAccountActionType = UserAccountActionType.UnlockUserFailed; message = response.ResponseErrorMessage; } // Get the logged in user account that was used by the server // when handling the request. DCU.Objects.UserAccount clientUserAccountLoggedIn = UserAccountConverter.CovertToClientUserAccount(response.RequestorUserAccount); UserAccountEventArgs userAccountEventArgs = createUserAccountEventArgs( userAccountActionType, null, clientUserAccountLoggedIn, message); // Broadcast to UserAccountEventARgs that an unlock user was triggered. EventBus <UserAccountEventArgs> .Broadcast( this, userAccountEventArgs); }
/// <summary> /// Updates User Accounts /// </summary> /// <param name="actionType">Action Type</param> public void UpdateUsers( UserAccountActionType actionType = UserAccountActionType.UpdateUsers) { // 1.) Get Service IUserManagementServices userManagementServices = ComponentManager.GetComponent <IUserManagementServices>(); // 2.) Create Request UserManagementRequest request = UserManagementHelper.CreateUserManagementRequest( UserManagementActionType.GetUsers); // 3.) Send Request UserManagementResponse response = userManagementServices.UserManagementHandleRequest(request); // 4.) Handle Response List <DCO.Objects.UserAccount> coreUserAccounts = response.UserAccountsRetrieved; List <DCU.Objects.UserAccount> clientUserAccounts = new List <DCU.Objects.UserAccount>(); foreach (DCO.Objects.UserAccount coreUserAccount in coreUserAccounts) { clientUserAccounts.Add(UserAccountConverter.CovertToClientUserAccount(coreUserAccount)); } // Get the logged in user account that was used by the server // when handling the request. DCU.Objects.UserAccount clientUserAccountLoggedIn = UserAccountConverter.CovertToClientUserAccount(response.RequestorUserAccount); UserAccountEventArgs userAccountEventArgs = createUserAccountEventArgs( actionType, clientUserAccounts, clientUserAccountLoggedIn, response.ResponseErrorMessage); // Broadcast to UserAccountEventArgs that update users was triggered. EventBus <UserAccountEventArgs> .Broadcast( this, userAccountEventArgs); }
/// <summary> /// Edits a User Account /// </summary> /// <param name="userAccount">User Account to be edited.</param> public void EditUser(DCU.Objects.UserAccount userAccount) { // 1.) Get Service IUserManagementServices userManagementServices = ComponentManager.GetComponent <IUserManagementServices>(); // 2.) Create Request UserManagementRequest request = UserManagementHelper.CreateUserManagementRequest( UserManagementActionType.EditUser, UserAccountConverter.CovertToCoreUserAccount(userAccount)); // 3.) Send Request UserManagementResponse response = userManagementServices.UserManagementHandleRequest(request); // 4.) Handle Response if (response.IsRequestSuccessful) { // Broadcast to UserAccountEventArgs that add was successful. UpdateUsers(UserAccountActionType.EditUser); } else { // Get the logged in user account that was used by the server // when handling the request. DCU.Objects.UserAccount clientUserAccountLoggedIn = UserAccountConverter.CovertToClientUserAccount(response.RequestorUserAccount); UserAccountEventArgs userAccountEventArgs = createUserAccountEventArgs( UserAccountActionType.EditUserFailed, null, clientUserAccountLoggedIn, response.ResponseErrorMessage); // Broadcast to UserAccountEventArgs that add failed. EventBus <UserAccountEventArgs> .Broadcast( this, userAccountEventArgs); } }