You need to populate the RootAlbumIds property, not the AllAlbumIds property. Refer to the documentation (i.e. the XML comments in the source code) for the difference between the two.
Your code will look similar to the RoleController.UpdateRoleAlbumRelationships function:
Code:/// <summary>
/// Replace the list of root album IDs for the <paramref name="role"/> with the album ID's specified in
/// <paramref name="topLevelCheckedAlbumIds"/>. Note that this function will cause the AllAlbumIds property
/// to be cleared out (Count = 0). The property can be repopulated by calling <see cref="IGalleryServerRole.Save"/>.
/// </summary>
/// <param name="role">The role whose root album/role relationships should be updated. When editing
/// an existing role, specify this.GalleryRole. For new roles, pass the newly created role before
/// saving it.</param>
/// <param name="topLevelCheckedAlbumIds">The top level checked album ids. May be null.</param>
public static void UpdateRoleAlbumRelationships(IGalleryServerRole role, IIntegerCollection topLevelCheckedAlbumIds)
{
if (role == null)
throw new ArgumentNullException("role");
if (topLevelCheckedAlbumIds == null)
topLevelCheckedAlbumIds = new IntegerCollection();
int[] rootAlbumIdsOld = new int[role.RootAlbumIds.Count];
role.RootAlbumIds.CopyTo(rootAlbumIdsOld, 0);
role.RootAlbumIds.Clear();
if (role.AllowAdministerSite)
{
// Administer site permission automatically applies to all albums, so all we need to do is get
// a reference to the root album ID.
role.RootAlbumIds.Add(Factory.LoadRootAlbumInstance().Id);
}
else
{
role.RootAlbumIds.AddRange(topLevelCheckedAlbumIds);
}
if (IsRoleAnAlbumOwnerRole(role.RoleName))
ValidateAlbumOwnerRoles(role.RoleName, rootAlbumIdsOld, role.RootAlbumIds);
}
Roger Martin
Creator and Lead Developer of Gallery Server Pro