/// <summary> /// Adds a new user to the customer tenant. /// </summary> private static GraphClient.IUser AddCustomerUser(GraphClient.IUser newUser) { // Get the C# client GraphClient.ActiveDirectoryClient activeDirectoryClient = azureADGraphApiHelper.GetActiveDirectoryClient(); // Add user activeDirectoryClient.Users.AddUserAsync(newUser).Wait(); // Return added user return GetCustomerUser(newUser.UserPrincipalName); }
private static void UpdateProperty(PeopleManager peopleManager, GraphApi.User user, Property prop) { var propertyNewValue = typeof(GraphApi.User).GetProperty(prop.ADAttributeName).GetValue(user); if (propertyNewValue != null || prop.WriteIfBlank) { if (prop.IsMulti) { peopleManager.SetMultiValuedProfileProperty(UserProfilePrefix + user.UserPrincipalName, prop.UserProfileAttributeName, new List<string>() { }); } else { peopleManager.SetSingleValueProfileProperty(UserProfilePrefix + user.UserPrincipalName, prop.UserProfileAttributeName, propertyNewValue == null ? string.Empty : propertyNewValue.ToString()); } Console.WriteLine("Updated User: {0} Property: {1} New Value: {2}", user.DisplayName, prop.UserProfileAttributeName, propertyNewValue); } //logic to write only if different }
/// <summary> /// Assigns or Removes licenses to a customer user. /// </summary> private static GraphClient.IUser AssignOrRemoveLicensesToUser(string userPrincipalName, GraphClient.AssignedLicense licenseToAdd, Guid? licenseToRemove = null) { // Create licenses objects IList<GraphClient.AssignedLicense> licensesToAdd = new GraphClient.AssignedLicense[] { }; IList<Guid> licensesToRemove = new Guid[] { }; GraphClient.IUser iUser = GetCustomerUser(userPrincipalName); if (licenseToAdd != null) { licensesToAdd = new[] { licenseToAdd }; } if (licenseToRemove != null) { licensesToRemove = new Guid[] { licenseToRemove.Value }; } // Assign/Remove licenses return iUser.AssignLicenseAsync(licensesToAdd, licensesToRemove).Result; }