/// <summary> /// Verify there is a site admin role/album mapping for the root album in the current gallery, creating one /// if necessary. /// </summary> /// <param name="albumId">The album ID of the root album in the current gallery.</param> /// <returns><c>true</c> if data was changed that necessitates reloading data from the data store, <c>false</c> otherwise.</returns> private static bool ConfigureRoleAlbumTable(int albumId) { var needToClearCache = false; using (var repoR = new RoleRepository()) { using (var repoRa = new RoleAlbumRepository()) { // Get admin roles that aren't assigned to the album, then assign them foreach (var rDto in repoR.Where(r => r.AllowAdministerSite && r.RoleAlbums.All(ra => ra.FKAlbumId != albumId))) { repoRa.Add(new RoleAlbumDto() { FKRoleName = rDto.RoleName, FKAlbumId = albumId }); needToClearCache = true; } repoRa.Save(); } } return(needToClearCache); }
/// <summary> /// Add each role specified in <see cref="Interfaces.IGallerySettings.DefaultRolesForUser" /> to this gallery's root album. /// </summary> private void AddDefaultRolesToRoleAlbumTable() { var rootAlbumId = Factory.LoadRootAlbumInstance(GalleryId).Id; foreach (var defaultRole in Factory.LoadGallerySetting(GalleryId).DefaultRolesForUser) { var defaultRole2 = defaultRole; using (var repoRole = new RoleRepository()) { if (!repoRole.Where(r => r.RoleName == defaultRole2).Any()) { continue; // We don't have a role with the name specified in the setting. Just skip it for now - RoleController.RemoveMissingRolesFromDefaultRolesForUsersSettings() will fix this when the maintenance routine runs. } } using (var repoRa = new RoleAlbumRepository()) { if (!repoRa.Where(r => r.FKRoleName == defaultRole2 && r.FKAlbumId == rootAlbumId).Any()) { // Add this role to the root album. repoRa.Add(new RoleAlbumDto() { FKRoleName = defaultRole2, FKAlbumId = rootAlbumId }); } repoRa.Save(); } } }
/// <summary> /// Verify there is a site admin role/album mapping for the root album in the current gallery, creating one /// if necessary. /// </summary> /// <param name="albumId">The album ID of the root album in the current gallery.</param> private static void ConfigureRoleAlbumTable(int albumId) { using (var repoR = new RoleRepository()) { using (var repoRa = new RoleAlbumRepository()) { // Get admin roles that aren't assigned to the album, then assign them foreach (var rDto in repoR.Where(r => r.AllowAdministerSite && r.RoleAlbums.All(ra => ra.FKAlbumId != albumId))) { repoRa.Add(new RoleAlbumDto() { FKRoleName = rDto.RoleName, FKAlbumId = albumId }); } repoRa.Save(); } } }