public AdminResponse Register(AdminUserViewModel adminUserData) { _logger.LogInfo("Registration method called"); byte[] passwordHash, passwordSalt; try { AdminUser adminUser = _mapper.Map <AdminUser>(_adminUserRepo.GetAdminUser(adminUserData.UserName)); if (adminUser != null) { _logger.LogInfo("The user doesn't not exists"); throw new Exception(string.Format(_messageHandler.GetMessage(ErrorMessagesEnum.UserAlreadyExist))); } else { adminUser = _mapper.Map <AdminUser>(adminUserData); } CreatePasswordHash(adminUserData.Password, out passwordHash, out passwordSalt); _logger.LogInfo("HMACSHA512 password created"); adminUser.PasswordHash = passwordHash; adminUser.PasswordSalt = passwordSalt; _adminUserRepo.Register(adminUser); _logger.LogInfo("Successfully registered new admin user by role = " + adminUserData.Role); adminUserData.Password = null; adminUserData.ConfirmPassword = null; AdminResponse response = new AdminResponse(true, string.Format(_messageHandler.GetSuccessMessage(SuccessMessagesEnum.SuccessfullRegister))); response.AdminUser = adminUserData; return(response); } catch (Exception ex) { _logger.LogError(ex.Message); return(new AdminResponse(false, ex.Message)); } }