// ReSharper disable PossibleMultipleEnumeration public async Task RunAsync(IRestContext context) { ISystemApi systemApi = context.Factory.CreateSystemApi(); SqlQuery query = new SqlQuery { fields = "*", related = "apps,users,services" }; IEnumerable<RoleResponse> roles = await systemApi.GetRolesAsync(query); Console.WriteLine("GetRolesAsync(): {0}", roles.Select(x => x.name).ToStringList()); RoleResponse role = roles.SingleOrDefault(x => x.name == NewRole); if (role != null) { await DeleteRole(role, systemApi); } RoleRequest newRole = new RoleRequest { name = NewRole, description = "new role", is_active = true }; roles = await systemApi.CreateRolesAsync(new SqlQuery(), newRole); role = roles.Single(x => x.name == NewRole); Console.WriteLine("CreateRolesAsync(): {0}", context.ContentSerializer.Serialize(role)); newRole.id = role.id; newRole.description = "new description"; role = (await systemApi.UpdateRolesAsync(new SqlQuery(), newRole)).Single(x => x.name == NewRole); Console.WriteLine("UpdateUsersAsync(): new description={0}", role.description); await DeleteRole(role, systemApi); }
public async Task RunAsync(IRestContext context) { ISystemRoleApi roleApi = context.Factory.CreateSystemRoleApi(); SqlQuery query = new SqlQuery { Fields = "*", Related = string.Join(",", RelatedResources.Role.Apps, RelatedResources.Role.UsersInApps, RelatedResources.Role.ServicesInApps) }; IEnumerable<RoleResponse> roles = (await roleApi.GetRolesAsync(query)).ToList(); Console.WriteLine("GetRolesAsync(): {0}", roles.Select(x => x.Name).ToStringList()); RoleResponse role = roles.SingleOrDefault(x => x.Name == NewRole); if (role != null) { await DeleteRole(role, roleApi); } RoleRequest newRole = new RoleRequest { Name = NewRole, Description = "new role", IsActive = true }; roles = await roleApi.CreateRolesAsync(new SqlQuery(), newRole); role = roles.Single(x => x.Name == NewRole); Console.WriteLine("CreateRolesAsync(): {0}", context.ContentSerializer.Serialize(role)); newRole.Id = role.Id; newRole.Description = "new description"; role = (await roleApi.UpdateRolesAsync(new SqlQuery(), newRole)).Single(x => x.Name == NewRole); Console.WriteLine("UpdateUsersAsync(): new description={0}", role.Description); await DeleteRole(role, roleApi); }