/// <summary> /// Run the code example. /// </summary> /// <param name="dfpUser">The DFP user object running the code example.</param> public override void Run(DfpUser user) { // Get the UserTeamAssociationService. UserTeamAssociationService userTeamAssociationService = (UserTeamAssociationService)user.GetService( DfpService.v201311.UserTeamAssociationService); // Set the IDs of the user and team to get the association for. long userId = long.Parse(_T("INSERT_USER_ID_HERE")); long teamId = long.Parse(_T("INSERT_TEAM_ID_HERE")); try { // Get the user team association. UserTeamAssociation userTeamAssociation = userTeamAssociationService.getUserTeamAssociation( teamId, userId); if (userTeamAssociation != null) { Console.WriteLine("User team association between user with ID \"{0}\" and team with " + "ID \"{1}\" was found.", userTeamAssociation.userId, userTeamAssociation.teamId); } else { Console.WriteLine("No user team association found."); } } 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 void Run(DfpUser dfpUser) { using (UserTeamAssociationService userTeamAssociationService = (UserTeamAssociationService)dfpUser.GetService(DfpService.v201805 .UserTeamAssociationService)) { // Set the users and team to add them to. long teamId = long.Parse(_T("INSERT_TEAM_ID_HERE")); long[] userIds = new long[] { long.Parse(_T("INSERT_USER_ID_HERE")) }; // Create an array to store local user team association objects. UserTeamAssociation[] userTeamAssociations = new UserTeamAssociation[userIds.Length]; // For each user, associate it with the given team. int i = 0; foreach (long userId in userIds) { UserTeamAssociation userTeamAssociation = new UserTeamAssociation(); userTeamAssociation.userId = userId; userTeamAssociation.teamId = teamId; userTeamAssociations[i++] = userTeamAssociation; } try { // Create the user team associations on the server. userTeamAssociations = userTeamAssociationService.createUserTeamAssociations(userTeamAssociations); if (userTeamAssociations != null) { foreach (UserTeamAssociation userTeamAssociation in userTeamAssociations) { Console.WriteLine( "A user team association between user with ID \"{0}\" and team " + "with ID \"{1}\" was created.", userTeamAssociation.userId, userTeamAssociation.teamId); } } else { Console.WriteLine("No user team associations created."); } } catch (Exception e) { Console.WriteLine( "Failed to create user team associations. Exception says \"{0}\"", e.Message); } } }
/// <summary> /// Run the code example. /// </summary> /// <param name="user">The DFP user object running the code example.</param> public override void Run(DfpUser user) { // Get the UserTeamAssociationService. UserTeamAssociationService userTeamAssociationService = (UserTeamAssociationService)user.GetService( DfpService.v201408.UserTeamAssociationService); // Set the user id of the user team association to update. long userId = long.Parse(_T("INSERT_USER_ID_HERE")); // Set the team id of the user team association to update. long teamId = long.Parse(_T("INSERT_TEAM_ID_HERE")); // Create a statement to select the user team association. StatementBuilder statementBuilder = new StatementBuilder() .Where("userId = :userId and teamId = :teamId") .OrderBy("userId ASC, teamId ASC") .Limit(1) .AddValue("userId", userId) .AddValue("teamId", teamId); try { // Get user team associations by statement. UserTeamAssociationPage page = userTeamAssociationService.getUserTeamAssociationsByStatement( statementBuilder.ToStatement()); UserTeamAssociation userTeamAssociation = page.results[0]; userTeamAssociation.overriddenTeamAccessType = TeamAccessType.READ_ONLY; // Update the user team associations on the server. UserTeamAssociation[] userTeamAssociations = userTeamAssociationService.updateUserTeamAssociations( new UserTeamAssociation[] { userTeamAssociation }); if (userTeamAssociations != null) { foreach (UserTeamAssociation updatedUserTeamAssociation in userTeamAssociations) { Console.WriteLine("User team association between user with ID \"{0}\" and team " + "with ID \"{1}\" was updated to access type \"{2}\".", updatedUserTeamAssociation.userId, updatedUserTeamAssociation.teamId, updatedUserTeamAssociation.overriddenTeamAccessType); } } else { Console.WriteLine("No user team associations updated."); } } catch (Exception ex) { Console.WriteLine("Failed to update 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.v201508.UserTeamAssociationService); // Set the users and team to add them to. long teamId = long.Parse(_T("INSERT_TEAM_ID_HERE")); long[] userIds = new long[] {long.Parse(_T("INSERT_USER_ID_HERE"))}; // Create an array to store local user team association objects. UserTeamAssociation[] userTeamAssociations = new UserTeamAssociation[userIds.Length]; // For each user, associate it with the given team. int i = 0; foreach (long userId in userIds) { UserTeamAssociation userTeamAssociation = new UserTeamAssociation(); userTeamAssociation.userId = userId; userTeamAssociation.teamId = teamId; userTeamAssociations[i++] = userTeamAssociation; } try { // Create the user team associations on the server. userTeamAssociations = userTeamAssociationService.createUserTeamAssociations(userTeamAssociations); if (userTeamAssociations != null) { foreach (UserTeamAssociation userTeamAssociation in userTeamAssociations) { Console.WriteLine("A user team association between user with ID \"{0}\" and team " + "with ID \"{1}\" was created.", userTeamAssociation.userId, userTeamAssociation.teamId); } } else { Console.WriteLine("No user team associations created."); } } catch (Exception e) { Console.WriteLine("Failed to create user team associations. Exception says \"{0}\"", e.Message); } }