public async Task <bool> MakeAddUserRole(string userId, string roleId) { var result = await Api.ApiUsersByIdRolesByRidPostWithHttpMessagesAsync(userId, roleId); IdentityUserRoleString roleString = result.Body; return(true); }
public override void Command(MenuItem menuItem, string UserInput) { UsersMenuItem usersMenuItem = (UsersMenuItem)menuItem; usersMenuItem.Refresh(); string[] commands = UserInput.Split(" "); if (commands.Length < 3 || commands.Length > 4 || commands[0].ToLower() != "create") { menuItem.PrintInvalidOptionError(UserInput); EliteConsole.PrintFormattedErrorLine("Usage: Create <username> <password> [<roles>]"); return; } CovenantUser user = this.CovenantClient.ApiUsersPost(new CovenantUserLogin(commands[1], commands[2])); if (user != null) { EliteConsole.PrintFormattedHighlightLine("Created user: \"" + commands[1] + "\""); if (commands.Length == 4) { string[] roleNames = commands[3].Split(","); foreach (string roleName in roleNames) { IdentityRole role = this.CovenantClient.ApiRolesGet().FirstOrDefault(R => R.Name == roleName); if (role != null) { IdentityUserRoleString roleResult = this.CovenantClient.ApiUsersByUidRolesByRidPost(user.Id, role.Id); if (roleResult.UserId == user.Id && roleResult.RoleId == role.Id) { EliteConsole.PrintFormattedHighlightLine("Added user: \"" + commands[1] + "\"" + " to role: \"" + roleName + "\""); } else { EliteConsole.PrintFormattedErrorLine("Failed to add user: \"" + commands[1] + "\" to role: \"" + roleName + "\""); } } } } } else { EliteConsole.PrintFormattedErrorLine("Failed to create user: \"" + commands[1] + "\""); } }