/// <summary> /// Run the code example. /// </summary> /// <param name="dfpUser">The DFP user object running the code example.</param> public override void Run(DfpUser dfpUser) { // Get the UserTeamAssociationService. UserTeamAssociationService userTeamAssociationService = (UserTeamAssociationService) dfpUser.GetService(DfpService.v201306.UserTeamAssociationService); // Set defaults for page and filterStatement. UserTeamAssociationPage page = new UserTeamAssociationPage(); Statement filterStatement = new Statement(); int offset = 0; try { do { // Create a statement to get all user team associations. filterStatement.query = "LIMIT 500 OFFSET " + offset; // Get user team associations by statement. page = userTeamAssociationService.getUserTeamAssociationsByStatement(filterStatement); if (page.results != null) { int i = page.startIndex; foreach (UserTeamAssociation userTeamAssociation in page.results) { Console.WriteLine("{0}) User team association between user with ID \"{1}\" and " + "team with ID \"{2}\" was found.", i, userTeamAssociation.userId, userTeamAssociation.teamId); i++; } } offset += 500; } while (offset < page.totalResultSetSize); Console.WriteLine("Number of results found: {0}." + page.totalResultSetSize); } catch (Exception ex) { Console.WriteLine("Failed to get user team associations. Exception says \"{0}\"", ex.Message); } }
/// <summary> /// Run the code example. /// </summary> /// <param name="dfpUser">The DFP user object running the code example.</param> public override void Run(DfpUser dfpUser) { // Get the UserTeamAssociationService. UserTeamAssociationService userTeamAssociationService = (UserTeamAssociationService) dfpUser.GetService(DfpService.v201306.UserTeamAssociationService); // Set the user to remove from its teams. long userId = long.Parse(_T("INSERT_USER_ID_HERE")); // Create filter text to select user team associations by the user ID. String statementText = "WHERE userId = :userId LIMIT 500"; Statement filterStatement = new StatementBuilder("").AddValue("userId", userId). ToStatement(); // Set defaults for page and offset. UserTeamAssociationPage page = new UserTeamAssociationPage(); int offset = 0; try { do { // Create a statement to page through user team associations. filterStatement.query = statementText + " OFFSET " + offset; // Get user team associations by statement. page = userTeamAssociationService.getUserTeamAssociationsByStatement(filterStatement); if (page.results != null) { int i = page.startIndex; foreach (UserTeamAssociation userTeamAssociation in page.results) { Console.WriteLine("{0}) User team association between user with ID \"{1}\" and " + "team with ID \"{2}\" will be deleted.", i, userTeamAssociation.userId, userTeamAssociation.teamId); i++; } } offset += 500; } while (offset < page.totalResultSetSize); Console.WriteLine("Number of teams that the user will be removed from: " + page.totalResultSetSize); if (page.totalResultSetSize > 0) { // Modify statement for action. filterStatement.query = "WHERE userId = :userId"; // Create action. DeleteUserTeamAssociations action = new DeleteUserTeamAssociations(); // Perform action. UpdateResult result = userTeamAssociationService.performUserTeamAssociationAction(action, filterStatement); // Display results. if (result != null && result.numChanges > 0) { Console.WriteLine("Number of teams that the user was removed from: " + result.numChanges); } else { Console.WriteLine("No user team associations were deleted."); } } } catch (Exception ex) { Console.WriteLine("Failed to delete user team associations. Exception says \"{0}\"", ex.Message); } }