diff --git a/src/OrchardCore.Modules/OrchardCore.AuditTrail/Services/AuditTrailBackgroundTask.cs b/src/OrchardCore.Modules/OrchardCore.AuditTrail/Services/AuditTrailBackgroundTask.cs index f9a40a7bb1b..b7e228a5cb3 100644 --- a/src/OrchardCore.Modules/OrchardCore.AuditTrail/Services/AuditTrailBackgroundTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.AuditTrail/Services/AuditTrailBackgroundTask.cs @@ -23,7 +23,7 @@ public async Task DoWorkAsync(IServiceProvider serviceProvider, CancellationToke { var siteService = serviceProvider.GetRequiredService(); - var settings = (await siteService.GetSiteSettingsAsync()).As(); + var settings = await siteService.GetSettingsAsync(); if (settings.Disabled) { return; diff --git a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/ContentRequestCultureProvider.cs b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/ContentRequestCultureProvider.cs index beb5afec15e..6302191019f 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/ContentRequestCultureProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/ContentRequestCultureProvider.cs @@ -24,7 +24,7 @@ public override async Task DetermineProviderCultureResult if (localization != null) { - var settings = (await siteService.GetSiteSettingsAsync()).As(); + var settings = await siteService.GetSettingsAsync(); if (settings.SetCookie) { culturePickerService.SetContentCulturePickerCookie(localization.Culture); diff --git a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Controllers/ContentCulturePickerController.cs b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Controllers/ContentCulturePickerController.cs index 1f4917ec918..bf8177fa01e 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Controllers/ContentCulturePickerController.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Controllers/ContentCulturePickerController.cs @@ -47,7 +47,7 @@ public async Task RedirectToLocalizedContent(string targetCulture if (supportedCultures.Any(t => t == targetCulture)) { - var settings = (await _siteService.GetSiteSettingsAsync()).As(); + var settings = await _siteService.GetSettingsAsync(); if (settings.SetCookie) { _culturePickerService.SetContentCulturePickerCookie(targetCulture); diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Contents/AdminMenu.cs index 188aad57cb9..08999ac4f83 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/AdminMenu.cs @@ -83,7 +83,7 @@ await content.AddAsync(S["Content Items"], S["Content Items"].PrefixPosition(), }); }); - var adminSettings = (await _siteService.GetSiteSettingsAsync()).As(); + var adminSettings = await _siteService.GetSettingsAsync(); if (adminSettings.DisplayNewMenu && contentTypes.Any()) { diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/AuditTrail/Handlers/AuditTrailContentHandler.cs b/src/OrchardCore.Modules/OrchardCore.Contents/AuditTrail/Handlers/AuditTrailContentHandler.cs index 641439157ef..9ec5cfa7ff2 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/AuditTrail/Handlers/AuditTrailContentHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/AuditTrail/Handlers/AuditTrailContentHandler.cs @@ -72,9 +72,8 @@ private async Task RecordAuditTrailEventAsync(string name, ContentItem content) return; } - var siteSettings = await _siteService.GetSiteSettingsAsync(); + var settings = await _siteService.GetSettingsAsync(); - var settings = siteSettings.As(); if (!settings.AllowedContentTypes.Contains(content.ContentItem.ContentType)) { return; diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetContentDriver.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetContentDriver.cs index 92619b9059f..b21e82475e6 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetContentDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetContentDriver.cs @@ -29,8 +29,8 @@ public override IDisplayResult Display(ContentItem model) { if (await _deploymentPlanService.DoesUserHaveExportPermissionAsync()) { - var siteSettings = await _siteService.GetSiteSettingsAsync(); - var exportContentToDeploymentTargetSettings = siteSettings.As(); + var exportContentToDeploymentTargetSettings = await _siteService.GetSettingsAsync(); + if (exportContentToDeploymentTargetSettings.ExportContentToDeploymentTargetPlanId != 0) { return true; @@ -45,8 +45,8 @@ public override IDisplayResult Display(ContentItem model) { if (await _deploymentPlanService.DoesUserHaveExportPermissionAsync()) { - var siteSettings = await _siteService.GetSiteSettingsAsync(); - var exportContentToDeploymentTargetSettings = siteSettings.As(); + var exportContentToDeploymentTargetSettings = await _siteService.GetSettingsAsync(); + if (exportContentToDeploymentTargetSettings.ExportContentToDeploymentTargetPlanId != 0) { return true; diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetContentsAdminListDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetContentsAdminListDisplayDriver.cs index 09874c97824..abf6f3818c3 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetContentsAdminListDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetContentsAdminListDisplayDriver.cs @@ -24,8 +24,8 @@ public override async Task DisplayAsync(ContentOptionsViewModel { if (await _deploymentPlanService.DoesUserHaveExportPermissionAsync()) { - var siteSettings = await _siteService.GetSiteSettingsAsync(); - var exportContentToDeploymentTargetSettings = siteSettings.As(); + var exportContentToDeploymentTargetSettings = await _siteService.GetSettingsAsync(); + if (exportContentToDeploymentTargetSettings.ExportContentToDeploymentTargetPlanId != 0) { return Combine( diff --git a/src/OrchardCore.Modules/OrchardCore.Cors/Services/CorsService.cs b/src/OrchardCore.Modules/OrchardCore.Cors/Services/CorsService.cs index 25d33fc0161..ac3f97f58fc 100644 --- a/src/OrchardCore.Modules/OrchardCore.Cors/Services/CorsService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Cors/Services/CorsService.cs @@ -16,8 +16,7 @@ public CorsService(ISiteService siteService) public async Task GetSettingsAsync() { - var siteSettings = await _siteService.GetSiteSettingsAsync(); - return siteSettings.As(); + return await _siteService.GetSettingsAsync(); } internal async Task UpdateSettingsAsync(CorsSettings corsSettings) diff --git a/src/OrchardCore.Modules/OrchardCore.Email.Azure/Services/AzureEmailOptionsConfiguration.cs b/src/OrchardCore.Modules/OrchardCore.Email.Azure/Services/AzureEmailOptionsConfiguration.cs index 5b639b6d285..48c07365e0c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email.Azure/Services/AzureEmailOptionsConfiguration.cs +++ b/src/OrchardCore.Modules/OrchardCore.Email.Azure/Services/AzureEmailOptionsConfiguration.cs @@ -23,10 +23,9 @@ public AzureEmailOptionsConfiguration( public void Configure(AzureEmailOptions options) { - var settings = _siteService.GetSiteSettingsAsync() + var settings = _siteService.GetSettingsAsync() .GetAwaiter() - .GetResult() - .As(); + .GetResult(); options.IsEnabled = settings.IsEnabled; options.DefaultSender = settings.DefaultSender; diff --git a/src/OrchardCore.Modules/OrchardCore.Email.Smtp/Services/SmtpOptionsConfiguration.cs b/src/OrchardCore.Modules/OrchardCore.Email.Smtp/Services/SmtpOptionsConfiguration.cs index 0ac92e3870f..28b4a52b838 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email.Smtp/Services/SmtpOptionsConfiguration.cs +++ b/src/OrchardCore.Modules/OrchardCore.Email.Smtp/Services/SmtpOptionsConfiguration.cs @@ -25,9 +25,9 @@ public SmtpOptionsConfiguration( public void Configure(SmtpOptions options) { - var settings = _siteService.GetSiteSettingsAsync() - .GetAwaiter().GetResult() - .As(); + var settings = _siteService.GetSettingsAsync() + .GetAwaiter() + .GetResult(); options.DefaultSender = settings.DefaultSender; options.DeliveryMethod = settings.DeliveryMethod; diff --git a/src/OrchardCore.Modules/OrchardCore.Email/Migrations/EmailMigrations.cs b/src/OrchardCore.Modules/OrchardCore.Email/Migrations/EmailMigrations.cs index 6c814c84bf9..4c21c5a48b9 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email/Migrations/EmailMigrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Email/Migrations/EmailMigrations.cs @@ -28,9 +28,7 @@ public int Create() } var siteService = scope.ServiceProvider.GetRequiredService(); - var site = await siteService.GetSiteSettingsAsync(); - - var smtpSettings = site.As(); + var smtpSettings = await siteService.GetSettingsAsync(); if (!string.IsNullOrEmpty(smtpSettings.DefaultSender) || scope.ServiceProvider.GetService>()?.Value.ConfigurationExists() == true) diff --git a/src/OrchardCore.Modules/OrchardCore.Facebook/Filters/FacebookPixelFilter.cs b/src/OrchardCore.Modules/OrchardCore.Facebook/Filters/FacebookPixelFilter.cs index 5593343cd4d..35b0fabc1c0 100644 --- a/src/OrchardCore.Modules/OrchardCore.Facebook/Filters/FacebookPixelFilter.cs +++ b/src/OrchardCore.Modules/OrchardCore.Facebook/Filters/FacebookPixelFilter.cs @@ -34,7 +34,7 @@ public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultE if (_scriptsCache == null && canTrack) { - var settings = (await _siteService.GetSiteSettingsAsync()).As(); + var settings = await _siteService.GetSettingsAsync(); if (!string.IsNullOrWhiteSpace(settings?.PixelId)) { diff --git a/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Services/FacebookLoginService.cs b/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Services/FacebookLoginService.cs index adcd8ce2967..19ae818b849 100644 --- a/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Services/FacebookLoginService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Services/FacebookLoginService.cs @@ -19,11 +19,8 @@ public FacebookLoginService(ISiteService siteService) _siteService = siteService; } - public async Task GetSettingsAsync() - { - var container = await _siteService.GetSiteSettingsAsync(); - return container.As(); - } + public Task GetSettingsAsync() + => _siteService.GetSettingsAsync(); public async Task LoadSettingsAsync() { diff --git a/src/OrchardCore.Modules/OrchardCore.Facebook/ScriptsMiddleware.cs b/src/OrchardCore.Modules/OrchardCore.Facebook/ScriptsMiddleware.cs index d42ab4ac2f8..abfc058c76d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Facebook/ScriptsMiddleware.cs +++ b/src/OrchardCore.Modules/OrchardCore.Facebook/ScriptsMiddleware.cs @@ -26,8 +26,8 @@ public async Task Invoke(HttpContext httpContext) if (httpContext.Request.Path.StartsWithSegments("/OrchardCore.Facebook/sdk", StringComparison.OrdinalIgnoreCase)) { var script = default(string); - var site = (await _siteService.GetSiteSettingsAsync()); - var settings = site.As(); + var settings = await _siteService.GetSettingsAsync(); + if (Path.GetFileName(httpContext.Request.Path.Value) == "fbsdk.js") { var locale = CultureInfo.CurrentUICulture.Name.Replace('-', '_'); diff --git a/src/OrchardCore.Modules/OrchardCore.Facebook/Services/FacebookService.cs b/src/OrchardCore.Modules/OrchardCore.Facebook/Services/FacebookService.cs index c4e0ff96c47..2cf5856c730 100644 --- a/src/OrchardCore.Modules/OrchardCore.Facebook/Services/FacebookService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Facebook/Services/FacebookService.cs @@ -23,11 +23,8 @@ public FacebookService( S = stringLocalizer; } - public async Task GetSettingsAsync() - { - var container = await _siteService.GetSiteSettingsAsync(); - return container.As(); - } + public Task GetSettingsAsync() + => _siteService.GetSettingsAsync(); public async Task UpdateSettingsAsync(FacebookSettings settings) { diff --git a/src/OrchardCore.Modules/OrchardCore.Facebook/Views/FacebookPluginPart.Summary.cshtml b/src/OrchardCore.Modules/OrchardCore.Facebook/Views/FacebookPluginPart.Summary.cshtml index e00313a1ee8..dad761f16b4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Facebook/Views/FacebookPluginPart.Summary.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Facebook/Views/FacebookPluginPart.Summary.cshtml @@ -2,9 +2,9 @@ @using OrchardCore.Settings @using OrchardCore.Facebook.Settings @model OrchardCore.Facebook.Widgets.ViewModels.FacebookPluginPartViewModel -@inject ISiteService _site +@inject ISiteService SiteService @{ - var fbInit = (await _site.GetSiteSettingsAsync()).As().FBInit; + var fbInit = (await SiteService.GetSettingsAsync()).FBInit; } @Html.Raw(Model.Html) diff --git a/src/OrchardCore.Modules/OrchardCore.Facebook/Views/FacebookPluginPart.cshtml b/src/OrchardCore.Modules/OrchardCore.Facebook/Views/FacebookPluginPart.cshtml index e00313a1ee8..dad761f16b4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Facebook/Views/FacebookPluginPart.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Facebook/Views/FacebookPluginPart.cshtml @@ -2,9 +2,9 @@ @using OrchardCore.Settings @using OrchardCore.Facebook.Settings @model OrchardCore.Facebook.Widgets.ViewModels.FacebookPluginPartViewModel -@inject ISiteService _site +@inject ISiteService SiteService @{ - var fbInit = (await _site.GetSiteSettingsAsync()).As().FBInit; + var fbInit = (await SiteService.GetSettingsAsync()).FBInit; } @Html.Raw(Model.Html) diff --git a/src/OrchardCore.Modules/OrchardCore.GitHub/Services/GithubAuthenticationService.cs b/src/OrchardCore.Modules/OrchardCore.GitHub/Services/GithubAuthenticationService.cs index 4d954cff7c2..36acc67972b 100644 --- a/src/OrchardCore.Modules/OrchardCore.GitHub/Services/GithubAuthenticationService.cs +++ b/src/OrchardCore.Modules/OrchardCore.GitHub/Services/GithubAuthenticationService.cs @@ -22,11 +22,8 @@ public GitHubAuthenticationService( S = stringLocalizer; } - public async Task GetSettingsAsync() - { - var container = await _siteService.GetSiteSettingsAsync(); - return container.As(); - } + public Task GetSettingsAsync() + => _siteService.GetSettingsAsync(); public async Task LoadSettingsAsync() { diff --git a/src/OrchardCore.Modules/OrchardCore.Google/Analytics/GoogleAnalyticsFilter.cs b/src/OrchardCore.Modules/OrchardCore.Google/Analytics/GoogleAnalyticsFilter.cs index 31671da1642..5d71ab5faac 100644 --- a/src/OrchardCore.Modules/OrchardCore.Google/Analytics/GoogleAnalyticsFilter.cs +++ b/src/OrchardCore.Modules/OrchardCore.Google/Analytics/GoogleAnalyticsFilter.cs @@ -33,7 +33,7 @@ public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultE if (_scriptsCache == null && canTrack) { - var settings = (await _siteService.GetSiteSettingsAsync()).As(); + var settings = await _siteService.GetSettingsAsync(); if (!string.IsNullOrWhiteSpace(settings?.TrackingID)) { diff --git a/src/OrchardCore.Modules/OrchardCore.Google/Analytics/Services/GoogleAnalyticsService.cs b/src/OrchardCore.Modules/OrchardCore.Google/Analytics/Services/GoogleAnalyticsService.cs index e356ebf9431..70cacb3205d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Google/Analytics/Services/GoogleAnalyticsService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Google/Analytics/Services/GoogleAnalyticsService.cs @@ -14,10 +14,7 @@ public GoogleAnalyticsService( _siteService = siteService; } - public async Task GetSettingsAsync() - { - var container = await _siteService.GetSiteSettingsAsync(); - return container.As(); - } + public Task GetSettingsAsync() + => _siteService.GetSettingsAsync(); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Google/TagManager/GoogleTagManagerFilter.cs b/src/OrchardCore.Modules/OrchardCore.Google/TagManager/GoogleTagManagerFilter.cs index 75365c9670c..108f2c0e9eb 100644 --- a/src/OrchardCore.Modules/OrchardCore.Google/TagManager/GoogleTagManagerFilter.cs +++ b/src/OrchardCore.Modules/OrchardCore.Google/TagManager/GoogleTagManagerFilter.cs @@ -33,7 +33,7 @@ public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultE if (_scriptsCache == null && canTrack) { - var settings = (await _siteService.GetSiteSettingsAsync()).As(); + var settings = await _siteService.GetSettingsAsync(); if (!string.IsNullOrWhiteSpace(settings?.ContainerID)) { diff --git a/src/OrchardCore.Modules/OrchardCore.Google/TagManager/Services/GoogleTagManagerService.cs b/src/OrchardCore.Modules/OrchardCore.Google/TagManager/Services/GoogleTagManagerService.cs index 822fbf76805..9462a1700e4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Google/TagManager/Services/GoogleTagManagerService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Google/TagManager/Services/GoogleTagManagerService.cs @@ -13,10 +13,7 @@ public GoogleTagManagerService(ISiteService siteService) _siteService = siteService; } - public async Task GetSettingsAsync() - { - var container = await _siteService.GetSiteSettingsAsync(); - return container.As(); - } + public Task GetSettingsAsync() + => _siteService.GetSettingsAsync(); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Https/Services/HttpsService.cs b/src/OrchardCore.Modules/OrchardCore.Https/Services/HttpsService.cs index 8de37114e43..cc12eec7fa2 100644 --- a/src/OrchardCore.Modules/OrchardCore.Https/Services/HttpsService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Https/Services/HttpsService.cs @@ -13,10 +13,7 @@ public HttpsService(ISiteService siteService) _siteService = siteService; } - public async Task GetSettingsAsync() - { - var siteSettings = await _siteService.GetSiteSettingsAsync(); - return siteSettings.As(); - } + public Task GetSettingsAsync() + => _siteService.GetSettingsAsync(); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Layers/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Layers/Controllers/AdminController.cs index fa5fd65b26c..98df4a0f18e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Layers/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Layers/Controllers/AdminController.cs @@ -99,10 +99,9 @@ public async Task Index() var model = new LayersIndexViewModel { Layers = layers.Layers.ToList() }; - var siteSettings = await _siteService.GetSiteSettingsAsync(); var contentDefinitions = await _contentDefinitionManager.ListTypeDefinitionsAsync(); - model.Zones = siteSettings.As().Zones ?? []; + model.Zones = (await _siteService.GetSettingsAsync()).Zones ?? []; model.Widgets = []; foreach (var widget in widgets.OrderBy(x => x.Position)) diff --git a/src/OrchardCore.Modules/OrchardCore.Layers/Deployment/AllLayersDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Layers/Deployment/AllLayersDeploymentSource.cs index 746122cded8..74f4bbaea4d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Layers/Deployment/AllLayersDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Layers/Deployment/AllLayersDeploymentSource.cs @@ -41,13 +41,13 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan ["Layers"] = JArray.FromObject(layers.Layers, _jsonSerializerOptions), }); - var siteSettings = await _siteService.GetSiteSettingsAsync(); + var layerSettings = await _siteService.GetSettingsAsync(); // Adding Layer settings result.Steps.Add(new JsonObject { ["name"] = "Settings", - ["LayerSettings"] = JObject.FromObject(siteSettings.As()), + ["LayerSettings"] = JObject.FromObject(layerSettings), }); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Localization/Services/LocalizationService.cs b/src/OrchardCore.Modules/OrchardCore.Localization/Services/LocalizationService.cs index 7285b30bc05..0de425edef6 100644 --- a/src/OrchardCore.Modules/OrchardCore.Localization/Services/LocalizationService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Localization/Services/LocalizationService.cs @@ -47,11 +47,7 @@ public async Task GetSupportedCulturesAsync() private async Task InitializeLocalizationSettingsAsync() { - if (_localizationSettings == null) - { - var siteSettings = await _siteService.GetSiteSettingsAsync(); - _localizationSettings = siteSettings.As(); - } + _localizationSettings ??= await _siteService.GetSettingsAsync(); } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Media/Processing/MediaTokenOptionsConfiguration.cs b/src/OrchardCore.Modules/OrchardCore.Media/Processing/MediaTokenOptionsConfiguration.cs index 19302b3b138..f38d82c019a 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/Processing/MediaTokenOptionsConfiguration.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/Processing/MediaTokenOptionsConfiguration.cs @@ -14,9 +14,9 @@ public MediaTokenOptionsConfiguration(ISiteService siteService) public void Configure(MediaTokenOptions options) { - options.HashKey = _siteService.GetSiteSettingsAsync() - .GetAwaiter().GetResult() - .As() + options.HashKey = _siteService.GetSettingsAsync() + .GetAwaiter() + .GetResult() .HashKey; } } diff --git a/src/OrchardCore.Modules/OrchardCore.Media/Processing/MediaTokenSettingsUpdater.cs b/src/OrchardCore.Modules/OrchardCore.Media/Processing/MediaTokenSettingsUpdater.cs index a42e4693d63..a6e1880b8a8 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/Processing/MediaTokenSettingsUpdater.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/Processing/MediaTokenSettingsUpdater.cs @@ -34,7 +34,7 @@ public async Task ActivatedAsync() return; } - var mediaTokenSettings = (await _siteService.GetSiteSettingsAsync()).As(); + var mediaTokenSettings = await _siteService.GetSettingsAsync(); if (mediaTokenSettings.HashKey == null) { diff --git a/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Services/AzureADService.cs b/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Services/AzureADService.cs index 514cadd4dcc..02a5e94ffb8 100644 --- a/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Services/AzureADService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Services/AzureADService.cs @@ -22,11 +22,8 @@ public AzureADService( S = stringLocalizer; } - public async Task GetSettingsAsync() - { - var container = await _siteService.GetSiteSettingsAsync(); - return container.As(); - } + public Task GetSettingsAsync() + => _siteService.GetSettingsAsync(); public async Task LoadSettingsAsync() { diff --git a/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Services/MicrosoftAccountService.cs b/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Services/MicrosoftAccountService.cs index 2424d0f4f3e..96dbc9055a0 100644 --- a/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Services/MicrosoftAccountService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Services/MicrosoftAccountService.cs @@ -22,11 +22,8 @@ public MicrosoftAccountService( S = stringLocalizer; } - public async Task GetSettingsAsync() - { - var container = await _siteService.GetSiteSettingsAsync(); - return container.As(); - } + public Task GetSettingsAsync() + => _siteService.GetSettingsAsync(); public async Task LoadSettingsAsync() { diff --git a/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdClientService.cs b/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdClientService.cs index af48416387c..739a33ab9b8 100644 --- a/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdClientService.cs +++ b/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdClientService.cs @@ -24,11 +24,8 @@ public OpenIdClientService( S = stringLocalizer; } - public async Task GetSettingsAsync() - { - var container = await _siteService.GetSiteSettingsAsync(); - return container.As(); - } + public Task GetSettingsAsync() + => _siteService.GetSettingsAsync(); public async Task LoadSettingsAsync() { diff --git a/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/ReCaptchaForgotPasswordFormDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/ReCaptchaForgotPasswordFormDisplayDriver.cs index f3f6943ca40..971be8ecdeb 100644 --- a/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/ReCaptchaForgotPasswordFormDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/ReCaptchaForgotPasswordFormDisplayDriver.cs @@ -18,7 +18,7 @@ public ReCaptchaForgotPasswordFormDisplayDriver(ISiteService siteService) public override async Task EditAsync(ForgotPasswordForm model, BuildEditorContext context) { - var _reCaptchaSettings = (await _siteService.GetSiteSettingsAsync()).As(); + var _reCaptchaSettings = await _siteService.GetSettingsAsync(); if (!_reCaptchaSettings.IsValid()) { diff --git a/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/ReCaptchaLoginFormDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/ReCaptchaLoginFormDisplayDriver.cs index 08be62e8225..02ec8a5aa45 100644 --- a/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/ReCaptchaLoginFormDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/ReCaptchaLoginFormDisplayDriver.cs @@ -23,7 +23,7 @@ public ReCaptchaLoginFormDisplayDriver( public override async Task EditAsync(LoginForm model, BuildEditorContext context) { - var _reCaptchaSettings = (await _siteService.GetSiteSettingsAsync()).As(); + var _reCaptchaSettings = await _siteService.GetSettingsAsync(); if (!_reCaptchaSettings.IsValid() || !_reCaptchaService.IsThisARobot()) { diff --git a/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/ReCaptchaResetPasswordFormDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/ReCaptchaResetPasswordFormDisplayDriver.cs index 010fe0cba4a..a75a24820f0 100644 --- a/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/ReCaptchaResetPasswordFormDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/ReCaptchaResetPasswordFormDisplayDriver.cs @@ -18,7 +18,7 @@ public ReCaptchaResetPasswordFormDisplayDriver(ISiteService siteService) public override async Task EditAsync(ResetPasswordForm model, BuildEditorContext context) { - var _reCaptchaSettings = (await _siteService.GetSiteSettingsAsync()).As(); + var _reCaptchaSettings = await _siteService.GetSettingsAsync(); if (!_reCaptchaSettings.IsValid()) { diff --git a/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/RegisterUserFormDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/RegisterUserFormDisplayDriver.cs index 2ab32c34563..412a1622cce 100644 --- a/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/RegisterUserFormDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/RegisterUserFormDisplayDriver.cs @@ -18,9 +18,9 @@ public RegisterUserFormDisplayDriver(ISiteService siteService) public override async Task EditAsync(RegisterUserForm model, BuildEditorContext context) { - var _reCaptchaSettings = (await _siteService.GetSiteSettingsAsync()).As(); + var reCaptchaSettings = await _siteService.GetSettingsAsync(); - if (!_reCaptchaSettings.IsValid()) + if (!reCaptchaSettings.IsValid()) { return null; } diff --git a/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Forms/ReCaptchaPartDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Forms/ReCaptchaPartDisplayDriver.cs index a09409f0247..3937b598a88 100644 --- a/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Forms/ReCaptchaPartDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Forms/ReCaptchaPartDisplayDriver.cs @@ -19,8 +19,7 @@ public override IDisplayResult Display(ReCaptchaPart part, BuildPartDisplayConte { return Initialize("ReCaptchaPart", async model => { - var siteSettings = await _siteService.GetSiteSettingsAsync(); - var settings = siteSettings.As(); + var settings = await _siteService.GetSettingsAsync(); model.SettingsAreConfigured = settings.IsValid(); }).Location("Detail", "Content"); } @@ -29,8 +28,7 @@ public override IDisplayResult Edit(ReCaptchaPart part, BuildPartEditorContext c { return Initialize("ReCaptchaPart_Fields_Edit", async model => { - var siteSettings = await _siteService.GetSiteSettingsAsync(); - var settings = siteSettings.As(); + var settings = await _siteService.GetSettingsAsync(); model.SettingsAreConfigured = settings.IsValid(); }); } diff --git a/src/OrchardCore.Modules/OrchardCore.ReverseProxy/Services/ReverseProxyService.cs b/src/OrchardCore.Modules/OrchardCore.ReverseProxy/Services/ReverseProxyService.cs index 6873ca847bb..69e16baa3ca 100644 --- a/src/OrchardCore.Modules/OrchardCore.ReverseProxy/Services/ReverseProxyService.cs +++ b/src/OrchardCore.Modules/OrchardCore.ReverseProxy/Services/ReverseProxyService.cs @@ -13,10 +13,7 @@ public ReverseProxyService(ISiteService siteService) _siteService = siteService; } - public async Task GetSettingsAsync() - { - var siteSettings = await _siteService.GetSiteSettingsAsync(); - return siteSettings.As(); - } + public Task GetSettingsAsync() + => _siteService.GetSettingsAsync(); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Handlers/ElasticsearchAuthorizationHandler.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Handlers/ElasticsearchAuthorizationHandler.cs index a7f1b382d80..6399cac7bd3 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Handlers/ElasticsearchAuthorizationHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Handlers/ElasticsearchAuthorizationHandler.cs @@ -62,8 +62,7 @@ private async Task GetIndexNameAsync(SearchPermissionParameters paramete } _siteService ??= _serviceProvider.GetRequiredService(); - var siteSettings = await _siteService.GetSiteSettingsAsync(); - return siteSettings.As().SearchIndex; + return (await _siteService.GetSettingsAsync()).SearchIndex; } } diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Services/ElasticSearchService.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Services/ElasticSearchService.cs index 15f8e097b5d..9f675bf3c26 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Services/ElasticSearchService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Services/ElasticSearchService.cs @@ -66,8 +66,7 @@ public async Task SearchAsync(string indexName, string term, int s return result; } - var siteSettings = await _siteService.GetSiteSettingsAsync(); - var searchSettings = siteSettings.As(); + var searchSettings = await _siteService.GetSettingsAsync(); var index = !string.IsNullOrWhiteSpace(indexName) ? indexName.Trim() : searchSettings.SearchIndex; diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Handler/LuceneAuthorizationHandler.cs b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Handler/LuceneAuthorizationHandler.cs index 1b662abecdf..a63926e3e7c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Handler/LuceneAuthorizationHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Handler/LuceneAuthorizationHandler.cs @@ -61,8 +61,7 @@ private async Task GetIndexNameAsync(SearchPermissionParameters paramete } _siteService ??= _serviceProvider.GetRequiredService(); - var siteSettings = await _siteService.GetSiteSettingsAsync(); - return siteSettings.As().SearchIndex; + return (await _siteService.GetSettingsAsync()).SearchIndex; } } diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneIndexingService.cs b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneIndexingService.cs index 415452028fe..c633e130e8d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneIndexingService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneIndexingService.cs @@ -6,7 +6,6 @@ using Microsoft.Extensions.Logging; using OrchardCore.ContentLocalization; using OrchardCore.ContentManagement; -using OrchardCore.Entities; using OrchardCore.Environment.Shell; using OrchardCore.Indexing; using OrchardCore.Modules; @@ -298,17 +297,6 @@ public async Task RebuildIndexAsync(string indexName) } public async Task GetLuceneSettingsAsync() - { - var siteSettings = await _siteService.GetSiteSettingsAsync(); - - if (siteSettings.Has()) - { - return siteSettings.As(); - } - else - { - return new LuceneSettings(); - } - } + => await _siteService.GetSettingsAsync() ?? new LuceneSettings(); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneSearchService.cs b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneSearchService.cs index c22c388e469..b5f21f6986b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneSearchService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneSearchService.cs @@ -79,11 +79,7 @@ public async Task SearchAsync(string indexName, string term, int s } private async Task DefaultIndexAsync() - { - var siteSettings = await _siteService.GetSiteSettingsAsync(); - - return siteSettings.As().SearchIndex; - } + => (await _siteService.GetSettingsAsync()).SearchIndex; private async Task GetSearchFieldsAsync() { diff --git a/src/OrchardCore.Modules/OrchardCore.Search/Controllers/SearchController.cs b/src/OrchardCore.Modules/OrchardCore.Search/Controllers/SearchController.cs index b6b1d00ade2..1620410a89c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search/Controllers/SearchController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search/Controllers/SearchController.cs @@ -68,9 +68,7 @@ public async Task Search(SearchViewModel viewModel, PagerSlimPara return View(); } - var siteSettings = await _siteService.GetSiteSettingsAsync(); - var searchSettings = siteSettings.As(); ISearchService searchService = null; diff --git a/src/OrchardCore.Modules/OrchardCore.Search/Deployment/SearchSettingsDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Search/Deployment/SearchSettingsDeploymentSource.cs index a461a61f723..9d1c201a7a6 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search/Deployment/SearchSettingsDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search/Deployment/SearchSettingsDeploymentSource.cs @@ -8,11 +8,11 @@ namespace OrchardCore.Search.Deployment { public class SearchSettingsDeploymentSource : IDeploymentSource { - private readonly ISiteService _site; + private readonly ISiteService _siteService; public SearchSettingsDeploymentSource(ISiteService site) { - _site = site; + _siteService = site; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) @@ -22,8 +22,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan return; } - var settings = await _site.GetSiteSettingsAsync(); - var searchSettings = settings.As(); + var searchSettings = await _siteService.GetSettingsAsync(); result.Steps.Add(new JsonObject { diff --git a/src/OrchardCore.Modules/OrchardCore.Search/Services/SearchSettingsConfiguration.cs b/src/OrchardCore.Modules/OrchardCore.Search/Services/SearchSettingsConfiguration.cs index cb8ea451d30..c4c855b2ef6 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search/Services/SearchSettingsConfiguration.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search/Services/SearchSettingsConfiguration.cs @@ -6,18 +6,18 @@ namespace OrchardCore.Search.Configuration { public class SearchSettingsConfiguration : IConfigureOptions { - private readonly ISiteService _site; + private readonly ISiteService _siteService; public SearchSettingsConfiguration(ISiteService site) { - _site = site; + _siteService = site; } public void Configure(SearchSettings options) { - var settings = _site.GetSiteSettingsAsync() - .GetAwaiter().GetResult() - .As(); + var settings = _siteService.GetSettingsAsync() + .GetAwaiter() + .GetResult(); options.ProviderName = settings.ProviderName; } diff --git a/src/OrchardCore.Modules/OrchardCore.Security/Services/SecurityService.cs b/src/OrchardCore.Modules/OrchardCore.Security/Services/SecurityService.cs index d1f1db889f6..11599cc8136 100644 --- a/src/OrchardCore.Modules/OrchardCore.Security/Services/SecurityService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Security/Services/SecurityService.cs @@ -13,11 +13,7 @@ public SecurityService(ISiteService siteService) _siteService = siteService; } - public async Task GetSettingsAsync() - { - var securityHeadersSettings = await _siteService.GetSiteSettingsAsync(); - - return securityHeadersSettings.As(); - } + public Task GetSettingsAsync() + => _siteService.GetSettingsAsync(); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Seo/Services/SiteSettingsRobotsProvider.cs b/src/OrchardCore.Modules/OrchardCore.Seo/Services/SiteSettingsRobotsProvider.cs index 2ab7ce3eecc..d7d139323d1 100644 --- a/src/OrchardCore.Modules/OrchardCore.Seo/Services/SiteSettingsRobotsProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.Seo/Services/SiteSettingsRobotsProvider.cs @@ -21,7 +21,7 @@ public SiteSettingsRobotsProvider( public async Task GetContentAsync() { - var settings = (await _siteService.GetSiteSettingsAsync()).As(); + var settings = await _siteService.GetSettingsAsync(); var content = new StringBuilder(); diff --git a/src/OrchardCore.Modules/OrchardCore.Settings/PagerOptionsConfiguration.cs b/src/OrchardCore.Modules/OrchardCore.Settings/PagerOptionsConfiguration.cs index 573767e03f9..a2d8e60abe8 100644 --- a/src/OrchardCore.Modules/OrchardCore.Settings/PagerOptionsConfiguration.cs +++ b/src/OrchardCore.Modules/OrchardCore.Settings/PagerOptionsConfiguration.cs @@ -14,7 +14,9 @@ public PagerOptionsConfiguration(ISiteService siteService) public void PostConfigure(string name, PagerOptions options) { - var site = _siteService.GetSiteSettingsAsync().GetAwaiter().GetResult(); + var site = _siteService.GetSiteSettingsAsync() + .GetAwaiter() + .GetResult(); options.MaxPageSize = site.MaxPageSize; options.MaxPagedCount = site.MaxPagedCount; diff --git a/src/OrchardCore.Modules/OrchardCore.Settings/ResourceOptionsConfiguration.cs b/src/OrchardCore.Modules/OrchardCore.Settings/ResourceOptionsConfiguration.cs index a4589bf1750..43942989034 100644 --- a/src/OrchardCore.Modules/OrchardCore.Settings/ResourceOptionsConfiguration.cs +++ b/src/OrchardCore.Modules/OrchardCore.Settings/ResourceOptionsConfiguration.cs @@ -14,7 +14,9 @@ public ResourceOptionsConfiguration(ISiteService siteService) public void PostConfigure(string name, ResourceOptions options) { - var site = _siteService.GetSiteSettingsAsync().GetAwaiter().GetResult(); + var site = _siteService.GetSiteSettingsAsync() + .GetAwaiter() + .GetResult(); options.ResourceDebugMode = site.ResourceDebugMode; options.UseCdn = site.UseCdn; diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs index 240518005cc..d672f8ca193 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs @@ -45,7 +45,7 @@ public TaxonomyContentsAdminListDisplayDriver( public override async Task EditAsync(ContentOptionsViewModel model, IUpdateModel updater) { - var settings = (await _siteService.GetSiteSettingsAsync()).As(); + var settings = await _siteService.GetSettingsAsync(); if (settings.TaxonomyContentItemIds.Length == 0) { @@ -117,7 +117,7 @@ public override async Task EditAsync(ContentOptionsViewModel mod public override async Task UpdateAsync(ContentOptionsViewModel model, IUpdateModel updater) { - var settings = (await _siteService.GetSiteSettingsAsync()).As(); + var settings = await _siteService.GetSettingsAsync(); foreach (var contentItemId in settings.TaxonomyContentItemIds) { var viewModel = new TaxonomyContentsAdminFilterViewModel(); diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Services/TaxonomyContentsAdminListFilter.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Services/TaxonomyContentsAdminListFilter.cs index c1760a77678..922cdda0e65 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Services/TaxonomyContentsAdminListFilter.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Services/TaxonomyContentsAdminListFilter.cs @@ -26,7 +26,7 @@ public TaxonomyContentsAdminListFilter(ISiteService siteService) public async Task FilterAsync(ContentOptionsViewModel model, IQuery query, IUpdateModel updater) { - var settings = (await _siteService.GetSiteSettingsAsync()).As(); + var settings = await _siteService.GetSettingsAsync(); foreach (var contentItemId in settings.TaxonomyContentItemIds) { var viewModel = new TaxonomyContentsAdminFilterViewModel(); diff --git a/src/OrchardCore.Modules/OrchardCore.Themes/Drivers/ToggleThemeNavbarDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Themes/Drivers/ToggleThemeNavbarDisplayDriver.cs index 76e85554c93..34388fc97ac 100644 --- a/src/OrchardCore.Modules/OrchardCore.Themes/Drivers/ToggleThemeNavbarDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Themes/Drivers/ToggleThemeNavbarDisplayDriver.cs @@ -17,7 +17,7 @@ public ToggleThemeNavbarDisplayDriver(ISiteService siteService) public override IDisplayResult Display(Navbar model) { return View("ToggleTheme", model) - .RenderWhen(async () => (await _siteService.GetSiteSettingsAsync()).As().DisplayThemeToggler) + .RenderWhen(async () => (await _siteService.GetSettingsAsync()).DisplayThemeToggler) .Location("Detail", "Content:10") .Location("DetailAdmin", "Content:10"); } diff --git a/src/OrchardCore.Modules/OrchardCore.Themes/Services/ThemeTogglerService.cs b/src/OrchardCore.Modules/OrchardCore.Themes/Services/ThemeTogglerService.cs index a134f22e182..ed77b2179ec 100644 --- a/src/OrchardCore.Modules/OrchardCore.Themes/Services/ThemeTogglerService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Themes/Services/ThemeTogglerService.cs @@ -25,7 +25,7 @@ public ThemeTogglerService( public async Task CurrentTheme() { - var adminSettings = (await _siteService.GetSiteSettingsAsync()).As(); + var adminSettings = await _siteService.GetSettingsAsync(); if (adminSettings.DisplayThemeToggler) { diff --git a/src/OrchardCore.Modules/OrchardCore.Twitter/Services/TwitterSettingsService.cs b/src/OrchardCore.Modules/OrchardCore.Twitter/Services/TwitterSettingsService.cs index bbbeb3920fc..5905d377bad 100644 --- a/src/OrchardCore.Modules/OrchardCore.Twitter/Services/TwitterSettingsService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Twitter/Services/TwitterSettingsService.cs @@ -22,11 +22,8 @@ public TwitterSettingsService( S = stringLocalizer; } - public async Task GetSettingsAsync() - { - var container = await _siteService.GetSiteSettingsAsync(); - return container.As(); - } + public Task GetSettingsAsync() + => _siteService.GetSettingsAsync(); public async Task LoadSettingsAsync() { diff --git a/src/OrchardCore.Modules/OrchardCore.Twitter/Signin/Services/TwitterSigninService.cs b/src/OrchardCore.Modules/OrchardCore.Twitter/Signin/Services/TwitterSigninService.cs index 11182f78f51..f71509297f0 100644 --- a/src/OrchardCore.Modules/OrchardCore.Twitter/Signin/Services/TwitterSigninService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Twitter/Signin/Services/TwitterSigninService.cs @@ -16,11 +16,8 @@ public TwitterSigninService( _siteService = siteService; } - public async Task GetSettingsAsync() - { - var container = await _siteService.GetSiteSettingsAsync(); - return container.As(); - } + public Task GetSettingsAsync() + => _siteService.GetSettingsAsync(); public async Task LoadSettingsAsync() { diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/AccountController.cs b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/AccountController.cs index e19628fd5a3..28b10969334 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/AccountController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/AccountController.cs @@ -111,7 +111,7 @@ public async Task Login(string returnUrl = null) // Clear the existing external cookie to ensure a clean login process. await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme); - var loginSettings = (await _siteService.GetSiteSettingsAsync()).As(); + var loginSettings = await _siteService.GetSettingsAsync(); if (loginSettings.UseExternalProviderIfOnlyOneDefined) { var schemes = await _signInManager.GetExternalAuthenticationSchemesAsync(); @@ -142,7 +142,7 @@ public async Task Login(string returnUrl = null) [AllowAnonymous] public async Task DefaultExternalLogin(string protectedToken, string returnUrl = null) { - var loginSettings = (await _siteService.GetSiteSettingsAsync()).As(); + var loginSettings = await _siteService.GetSettingsAsync(); if (loginSettings.UseExternalProviderIfOnlyOneDefined) { var schemes = await _signInManager.GetExternalAuthenticationSchemesAsync(); @@ -185,7 +185,7 @@ public async Task LoginPOST(string returnUrl = null) var formShape = await _loginFormDisplayManager.UpdateEditorAsync(model, _updateModelAccessor.ModelUpdater, false, string.Empty, string.Empty); - var disableLocalLogin = (await _siteService.GetSiteSettingsAsync()).As().DisableLocalLogin; + var disableLocalLogin = (await _siteService.GetSettingsAsync()).DisableLocalLogin; if (disableLocalLogin) { @@ -378,7 +378,7 @@ public async Task ExternalLoginCallback(string returnUrl = null, return RedirectToLogin(returnUrl); } - var registrationSettings = (await _siteService.GetSiteSettingsAsync()).As(); + var registrationSettings = await _siteService.GetSettingsAsync(); var iUser = await _userManager.FindByLoginAsync(info.LoginProvider, info.ProviderKey); CopyTempDataErrorsToModelState(); @@ -539,7 +539,7 @@ public async Task RegisterExternalLogin(RegisterExternalLoginView return NotFound(); } - var settings = (await _siteService.GetSiteSettingsAsync()).As(); + var settings = await _siteService.GetSettingsAsync(); if (settings.UsersCanRegister == UserRegistrationType.NoRegistration) { @@ -942,7 +942,7 @@ private async Task AddConfirmEmailErrorAsync(IUser user) return false; } - var registrationSettings = (await _siteService.GetSiteSettingsAsync()).As(); + var registrationSettings = await _siteService.GetSettingsAsync(); if (registrationSettings.UsersMustValidateEmail) { // Require that the users have a confirmed email before they can log on. diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/AuthenticatorAppController.cs b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/AuthenticatorAppController.cs index 0072a7f730b..9ce1c2326ce 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/AuthenticatorAppController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/AuthenticatorAppController.cs @@ -67,7 +67,7 @@ public async Task Index(string returnUrl) return UserNotFound(); } - var loginSettings = (await SiteService.GetSiteSettingsAsync()).As(); + var loginSettings = await SiteService.GetSettingsAsync(); var model = await LoadSharedKeyAndQrCodeUriAsync(user, loginSettings); @@ -96,7 +96,7 @@ public async Task Index(EnableAuthenticatorViewModel model) { ModelState.AddModelError(model.Code, S["Verification code is invalid."]); - var loginSettings = (await SiteService.GetSiteSettingsAsync()).As(); + var loginSettings = await SiteService.GetSettingsAsync(); return View(await LoadSharedKeyAndQrCodeUriAsync(user, loginSettings)); } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ChangeEmailController.cs b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ChangeEmailController.cs index 965e620d918..9a07da48e68 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ChangeEmailController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ChangeEmailController.cs @@ -37,7 +37,7 @@ public ChangeEmailController( [Authorize] public async Task Index() { - if (!(await _siteService.GetSiteSettingsAsync()).As().AllowChangeEmail) + if (!(await _siteService.GetSettingsAsync()).AllowChangeEmail) { return NotFound(); } @@ -51,7 +51,7 @@ public async Task Index() [ValidateAntiForgeryToken] public async Task Index(ChangeEmailViewModel model) { - if (!(await _siteService.GetSiteSettingsAsync()).As().AllowChangeEmail) + if (!(await _siteService.GetSettingsAsync()).AllowChangeEmail) { return NotFound(); } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/RegistrationController.cs b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/RegistrationController.cs index 120f748c02c..cdfb02789c1 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/RegistrationController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/RegistrationController.cs @@ -55,7 +55,7 @@ public RegistrationController( [AllowAnonymous] public async Task Register(string returnUrl = null) { - var settings = (await _siteService.GetSiteSettingsAsync()).As(); + var settings = await _siteService.GetSettingsAsync(); if (settings.UsersCanRegister != UserRegistrationType.AllowRegistration) { return NotFound(); @@ -74,7 +74,7 @@ public async Task Register(string returnUrl = null) [ActionName(nameof(Register))] public async Task RegisterPOST(string returnUrl = null) { - var settings = (await _siteService.GetSiteSettingsAsync()).As(); + var settings = await _siteService.GetSettingsAsync(); if (settings.UsersCanRegister != UserRegistrationType.AllowRegistration) { diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ResetPasswordController.cs b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ResetPasswordController.cs index ce825aea29f..b4c8c8d5ef7 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ResetPasswordController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ResetPasswordController.cs @@ -65,7 +65,7 @@ public ResetPasswordController( [AllowAnonymous] public async Task ForgotPassword() { - if (!(await _siteService.GetSiteSettingsAsync()).As().AllowResetPassword) + if (!(await _siteService.GetSettingsAsync()).AllowResetPassword) { return NotFound(); } @@ -80,7 +80,7 @@ public async Task ForgotPassword() [ActionName(nameof(ForgotPassword))] public async Task ForgotPasswordPOST() { - if (!(await _siteService.GetSiteSettingsAsync()).As().AllowResetPassword) + if (!(await _siteService.GetSettingsAsync()).AllowResetPassword) { return NotFound(); } @@ -130,7 +130,7 @@ public IActionResult ForgotPasswordConfirmation() [AllowAnonymous] public async Task ResetPassword(string code = null) { - if (!(await _siteService.GetSiteSettingsAsync()).As().AllowResetPassword) + if (!(await _siteService.GetSettingsAsync()).AllowResetPassword) { return NotFound(); } @@ -152,7 +152,7 @@ public async Task ResetPassword(string code = null) [ActionName(nameof(ResetPassword))] public async Task ResetPasswordPOST() { - if (!(await _siteService.GetSiteSettingsAsync()).As().AllowResetPassword) + if (!(await _siteService.GetSettingsAsync()).AllowResetPassword) { return NotFound(); } @@ -191,7 +191,7 @@ private async Task MustValidateEmailAsync(User user) return false; } - return (await _siteService.GetSiteSettingsAsync()).As().UsersMustValidateEmail + return (await _siteService.GetSettingsAsync()).UsersMustValidateEmail && !await _userManager.IsEmailConfirmedAsync(user); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/SmsAuthenticatorController.cs b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/SmsAuthenticatorController.cs index 1acf3129dc4..e9a96334c45 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/SmsAuthenticatorController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/SmsAuthenticatorController.cs @@ -78,7 +78,7 @@ public async Task Index() return UserNotFound(); } - var settings = (await SiteService.GetSiteSettingsAsync()).As(); + var settings = await SiteService.GetSettingsAsync(); var currentPhoneNumber = await UserManager.GetPhoneNumberAsync(user); @@ -103,7 +103,7 @@ public async Task IndexPost(RequestCodeSmsAuthenticatorViewModel return UserNotFound(); } - var settings = (await SiteService.GetSiteSettingsAsync()).As(); + var settings = await SiteService.GetSettingsAsync(); var currentPhoneNumber = await UserManager.GetPhoneNumberAsync(user); @@ -123,7 +123,7 @@ public async Task IndexPost(RequestCodeSmsAuthenticatorViewModel var phoneNumber = canSetNewPhone ? model.PhoneNumber : currentPhoneNumber; var code = await UserManager.GenerateChangePhoneNumberTokenAsync(user, phoneNumber); - var smsSettings = (await SiteService.GetSiteSettingsAsync()).As(); + var smsSettings = await SiteService.GetSettingsAsync(); var message = new SmsMessage() { diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/TwoFactorAuthenticationBaseController.cs b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/TwoFactorAuthenticationBaseController.cs index f3b8169df39..f7be675bedf 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/TwoFactorAuthenticationBaseController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/TwoFactorAuthenticationBaseController.cs @@ -139,7 +139,7 @@ protected async Task RedirectToTwoFactorAsync(IUser user) { if (await UserManager.CountRecoveryCodesAsync(user) == 0) { - var twoFactorSettings = (await SiteService.GetSiteSettingsAsync()).As(); + var twoFactorSettings = await SiteService.GetSettingsAsync(); var recoveryCodes = await UserManager.GenerateNewTwoFactorRecoveryCodesAsync(user, twoFactorSettings.NumberOfRecoveryCodesToGenerate); await SetRecoveryCodesAsync(recoveryCodes.ToArray(), await UserManager.GetUserIdAsync(user)); diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/TwoFactorAuthenticationController.cs b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/TwoFactorAuthenticationController.cs index 16e4667468b..d50fd58cc68 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/TwoFactorAuthenticationController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/TwoFactorAuthenticationController.cs @@ -86,7 +86,7 @@ public async Task LoginWithTwoFactorAuthentication(bool rememberM return RedirectToAccountLogin(); } - var twoFactorSettings = (await SiteService.GetSiteSettingsAsync()).As(); + var twoFactorSettings = await SiteService.GetSettingsAsync(); var model = new LoginWithTwoFactorAuthenticationViewModel { @@ -125,7 +125,7 @@ public async Task LoginWithTwoFactorAuthenticationPost(LoginWithT if (ModelState.IsValid) { - var twoFactorSettings = (await SiteService.GetSiteSettingsAsync()).As(); + var twoFactorSettings = await SiteService.GetSettingsAsync(); var rememberDevice = twoFactorSettings.AllowRememberClientTwoFactorAuthentication && model.RememberDevice; var authenticatorCode = StripToken(model.VerificationCode); @@ -322,7 +322,7 @@ public async Task GenerateRecoveryCodesPost() return RedirectToAction(nameof(Index)); } - var twoFactorSettings = (await SiteService.GetSiteSettingsAsync()).As(); + var twoFactorSettings = await SiteService.GetSettingsAsync(); var recoveryCodes = await UserManager.GenerateNewTwoFactorRecoveryCodesAsync(user, twoFactorSettings.NumberOfRecoveryCodesToGenerate); await SetRecoveryCodesAsync(recoveryCodes.ToArray(), await UserManager.GetUserIdAsync(user)); diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Drivers/ForgotPasswordLoginFormDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Users/Drivers/ForgotPasswordLoginFormDisplayDriver.cs index 142225ebf7a..edd58581177 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Drivers/ForgotPasswordLoginFormDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Drivers/ForgotPasswordLoginFormDisplayDriver.cs @@ -17,7 +17,7 @@ public ForgotPasswordLoginFormDisplayDriver(ISiteService siteService) public override async Task EditAsync(LoginForm model, BuildEditorContext context) { - var settings = (await _siteService.GetSiteSettingsAsync()).As(); + var settings = await _siteService.GetSettingsAsync(); if (!settings.AllowResetPassword) { diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Drivers/RegisterUserLoginFormDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Users/Drivers/RegisterUserLoginFormDisplayDriver.cs index 707d406a26a..7d22481655f 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Drivers/RegisterUserLoginFormDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Drivers/RegisterUserLoginFormDisplayDriver.cs @@ -17,7 +17,7 @@ public RegisterUserLoginFormDisplayDriver(ISiteService siteService) public override async Task EditAsync(LoginForm model, BuildEditorContext context) { - var settings = (await _siteService.GetSiteSettingsAsync()).As(); + var settings = await _siteService.GetSettingsAsync(); if (settings.UsersCanRegister != UserRegistrationType.AllowRegistration) { diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Drivers/UserInformationDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Users/Drivers/UserInformationDisplayDriver.cs index b93fcace0ff..e5c1de87b82 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Drivers/UserInformationDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Drivers/UserInformationDisplayDriver.cs @@ -42,8 +42,7 @@ public override async Task EditAsync(User user, BuildEditorConte return null; } - var site = await _siteService.GetSiteSettingsAsync(); - var settings = site.As(); + var settings = await _siteService.GetSettingsAsync(); var canEditUserInfo = await CanEditUserInfoAsync(user); return Combine( Initialize("UserName_Edit", model => @@ -113,8 +112,7 @@ public override async Task UpdateAsync(User user, UpdateEditorCo } else { - var site = await _siteService.GetSiteSettingsAsync(); - var settings = site.As(); + var settings = await _siteService.GetSettingsAsync(); if (await CanEditUserInfoAsync(user)) { diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Endpoints/EmailAuthenticator/SendCode.cs b/src/OrchardCore.Modules/OrchardCore.Users/Endpoints/EmailAuthenticator/SendCode.cs index 461449be49e..25c7e9e56b5 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Endpoints/EmailAuthenticator/SendCode.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Endpoints/EmailAuthenticator/SendCode.cs @@ -50,7 +50,7 @@ private static async Task HandleAsync( }); } - var settings = (await siteService.GetSiteSettingsAsync()).As(); + var settings = await siteService.GetSettingsAsync(); var code = await userManager.GenerateTwoFactorTokenAsync(user, TokenOptions.DefaultEmailProvider); var to = await userManager.GetEmailAsync(user); diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Endpoints/SmsAuthenticator/SendCode.cs b/src/OrchardCore.Modules/OrchardCore.Users/Endpoints/SmsAuthenticator/SendCode.cs index b700b3e99dd..35e6bc54c89 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Endpoints/SmsAuthenticator/SendCode.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Endpoints/SmsAuthenticator/SendCode.cs @@ -52,7 +52,7 @@ private static async Task HandleAsync( }); } - var settings = (await siteService.GetSiteSettingsAsync()).As(); + var settings = await siteService.GetSettingsAsync(); var code = await userManager.GenerateTwoFactorTokenAsync(user, identityOptions.Value.Tokens.ChangePhoneNumberTokenProvider); var message = new SmsMessage() @@ -70,7 +70,7 @@ private static async Task HandleAsync( : errorMessage.Value, }); } - + private static Task GetBodyAsync( SmsAuthenticatorLoginSettings settings, IUser user, diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Extensions/ControllerExtensions.cs b/src/OrchardCore.Modules/OrchardCore.Users/Extensions/ControllerExtensions.cs index 4e07b7833f0..39fc1983a0c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Extensions/ControllerExtensions.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Extensions/ControllerExtensions.cs @@ -61,7 +61,7 @@ internal static async Task RegisterUser(this Controller controller, Regis return null; } - var settings = (await controller.ControllerContext.HttpContext.RequestServices.GetRequiredService().GetSiteSettingsAsync()).As(); + var settings = await controller.ControllerContext.HttpContext.RequestServices.GetRequiredService().GetSettingsAsync(); if (settings.UsersCanRegister != UserRegistrationType.NoRegistration) { diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Handlers/ScriptExternalLoginEventHandler.cs b/src/OrchardCore.Modules/OrchardCore.Users/Handlers/ScriptExternalLoginEventHandler.cs index 96d49701be7..f5cda5ef0ac 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Handlers/ScriptExternalLoginEventHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Handlers/ScriptExternalLoginEventHandler.cs @@ -35,7 +35,7 @@ ILogger logger public async Task GenerateUserName(string provider, IEnumerable claims) { - var registrationSettings = (await _siteService.GetSiteSettingsAsync()).As(); + var registrationSettings = await _siteService.GetSettingsAsync(); if (registrationSettings.UseScriptToGenerateUsername) { @@ -54,7 +54,8 @@ public async Task GenerateUserName(string provider, IEnumerable(); + var loginSettings = await _siteService.GetSettingsAsync(); + UpdateUserInternal(context, loginSettings); } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Services/IdentityOptionsConfigurations.cs b/src/OrchardCore.Modules/OrchardCore.Users/Services/IdentityOptionsConfigurations.cs index dc807379aa8..ea1f6d07962 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Services/IdentityOptionsConfigurations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Services/IdentityOptionsConfigurations.cs @@ -16,9 +16,9 @@ public IdentityOptionsConfigurations(ISiteService siteService) public void Configure(IdentityOptions options) { - var site = _siteService.GetSiteSettingsAsync().GetAwaiter().GetResult(); - - var settings = site.As(); + var settings = _siteService.GetSettingsAsync() + .GetAwaiter() + .GetResult(); if (!string.IsNullOrEmpty(settings.UserSettings?.AllowedUserNameCharacters)) { diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Services/RoleTwoFactorAuthenticationHandler.cs b/src/OrchardCore.Modules/OrchardCore.Users/Services/RoleTwoFactorAuthenticationHandler.cs index 5154f79ebca..f9ab298e5ea 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Services/RoleTwoFactorAuthenticationHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Services/RoleTwoFactorAuthenticationHandler.cs @@ -24,7 +24,7 @@ public async Task IsRequiredAsync(IUser user) { ArgumentNullException.ThrowIfNull(user); - var loginSettings = (await _siteService.GetSiteSettingsAsync()).As(); + var loginSettings = await _siteService.GetSettingsAsync(); if (loginSettings.RequireTwoFactorAuthenticationForSpecificRoles && loginSettings.Roles != null) { diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Services/UsersThemeSelector.cs b/src/OrchardCore.Modules/OrchardCore.Users/Services/UsersThemeSelector.cs index 536c335e20b..84a99e555a4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Services/UsersThemeSelector.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Services/UsersThemeSelector.cs @@ -43,33 +43,33 @@ public async Task GetThemeAsync() switch (routeValues["controller"]?.ToString()) { case "Account": - useSiteTheme = (await _siteService.GetSiteSettingsAsync()).As().UseSiteTheme; + useSiteTheme = (await _siteService.GetSettingsAsync()).UseSiteTheme; break; case "TwoFactorAuthentication": { if (routeValues["action"] != null && routeValues["action"].ToString().StartsWith("LoginWith", StringComparison.OrdinalIgnoreCase) - && (await _siteService.GetSiteSettingsAsync()).As().UseSiteTheme) + && (await _siteService.GetSettingsAsync()).UseSiteTheme) { useSiteTheme = true; } else { - useSiteTheme = (await _siteService.GetSiteSettingsAsync()).As().UseSiteTheme; + useSiteTheme = (await _siteService.GetSettingsAsync()).UseSiteTheme; } } break; case "SmsAuthenticator": case "AuthenticatorApp": { - useSiteTheme = (await _siteService.GetSiteSettingsAsync()).As().UseSiteTheme; + useSiteTheme = (await _siteService.GetSettingsAsync()).UseSiteTheme; } break; case "Registration": - useSiteTheme = (await _siteService.GetSiteSettingsAsync()).As().UseSiteTheme; + useSiteTheme = (await _siteService.GetSettingsAsync()).UseSiteTheme; break; case "ResetPassword": - useSiteTheme = (await _siteService.GetSiteSettingsAsync()).As().UseSiteTheme; + useSiteTheme = (await _siteService.GetSettingsAsync()).UseSiteTheme; break; default: return null; diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Views/Account/Login.cshtml b/src/OrchardCore.Modules/OrchardCore.Users/Views/Account/Login.cshtml index 2ba0283caed..ae85e1c2ee4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Views/Account/Login.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Users/Views/Account/Login.cshtml @@ -15,7 +15,7 @@ ViewLayout = "Layout__Login"; var loginProviders = (await SignInManager.GetExternalAuthenticationSchemesAsync()).ToList(); - var disableLocalLogin = (await SiteService.GetSiteSettingsAsync()).As().DisableLocalLogin; + var disableLocalLogin = (await SiteService.GetSettingsAsync()).DisableLocalLogin; } diff --git a/src/OrchardCore/OrchardCore.Email.Core/Services/EmailOptionsConfiguration.cs b/src/OrchardCore/OrchardCore.Email.Core/Services/EmailOptionsConfiguration.cs index a83e0be8ab8..0a010eda3a0 100644 --- a/src/OrchardCore/OrchardCore.Email.Core/Services/EmailOptionsConfiguration.cs +++ b/src/OrchardCore/OrchardCore.Email.Core/Services/EmailOptionsConfiguration.cs @@ -19,9 +19,9 @@ public EmailOptionsConfiguration( public void Configure(EmailOptions options) { - var site = _siteService.GetSiteSettingsAsync().GetAwaiter().GetResult(); - - var emailSettings = site.As(); + var emailSettings = _siteService.GetSettingsAsync() + .GetAwaiter() + .GetResult(); if (!string.IsNullOrEmpty(emailSettings.DefaultProviderName) && _emailProviderOptions.Providers.TryGetValue(emailSettings.DefaultProviderName, out var provider) diff --git a/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Settings/SiteServiceExtensions.cs b/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Settings/SiteServiceExtensions.cs new file mode 100644 index 00000000000..4ac36da4716 --- /dev/null +++ b/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Settings/SiteServiceExtensions.cs @@ -0,0 +1,15 @@ +using System.Threading.Tasks; + +namespace OrchardCore.Settings; + +public static class SiteServiceExtensions +{ + /// + /// Gets an instance of the specified settings if it exists. + /// + /// The type of the settings to attempt to get. + /// The site service. + /// An instance of the given type if one exists. + public static async Task GetSettingsAsync(this ISiteService siteService) where T : new() + => (await siteService.GetSiteSettingsAsync()).As(); +} diff --git a/src/OrchardCore/OrchardCore.ReCaptcha.Core/Configuration/ReCaptchaSettingsConfiguration.cs b/src/OrchardCore/OrchardCore.ReCaptcha.Core/Configuration/ReCaptchaSettingsConfiguration.cs index 93a3a6e1a67..e3e74d71274 100644 --- a/src/OrchardCore/OrchardCore.ReCaptcha.Core/Configuration/ReCaptchaSettingsConfiguration.cs +++ b/src/OrchardCore/OrchardCore.ReCaptcha.Core/Configuration/ReCaptchaSettingsConfiguration.cs @@ -14,9 +14,9 @@ public ReCaptchaSettingsConfiguration(ISiteService site) public void Configure(ReCaptchaSettings options) { - var settings = _site.GetSiteSettingsAsync() - .GetAwaiter().GetResult() - .As(); + var settings = _site.GetSettingsAsync() + .GetAwaiter() + .GetResult(); options.SiteKey = settings.SiteKey; options.SecretKey = settings.SecretKey; diff --git a/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Deployment/AzureAISearchSettingsDeploymentSource.cs b/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Deployment/AzureAISearchSettingsDeploymentSource.cs index f813c5d06ee..ebc6afeaf53 100644 --- a/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Deployment/AzureAISearchSettingsDeploymentSource.cs +++ b/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Deployment/AzureAISearchSettingsDeploymentSource.cs @@ -17,9 +17,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan return; } - var site = await _siteService.GetSiteSettingsAsync(); - - var settings = site.As(); + var settings = await _siteService.GetSettingsAsync(); result.Steps.Add(new JsonObject { diff --git a/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Handlers/AzureAISearchAuthorizationHandler.cs b/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Handlers/AzureAISearchAuthorizationHandler.cs index 89ec03f68fc..9ecb34d6cc1 100644 --- a/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Handlers/AzureAISearchAuthorizationHandler.cs +++ b/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Handlers/AzureAISearchAuthorizationHandler.cs @@ -66,8 +66,7 @@ private async Task GetIndexNameAsync(SearchPermissionParameters paramete } _siteService ??= _serviceProvider.GetRequiredService(); - var siteSettings = await _siteService.GetSiteSettingsAsync(); - return siteSettings.As().SearchIndex; + return (await _siteService.GetSettingsAsync()).SearchIndex; } } diff --git a/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Services/AzureAISearchDefaultOptionsConfigurations.cs b/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Services/AzureAISearchDefaultOptionsConfigurations.cs index a54eae036a8..f6cd1e96c17 100644 --- a/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Services/AzureAISearchDefaultOptionsConfigurations.cs +++ b/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Services/AzureAISearchDefaultOptionsConfigurations.cs @@ -49,8 +49,7 @@ public async void Configure(AzureAISearchDefaultOptions options) else { // At this point, we can allow the user to update the settings from UI. - var site = await _siteService.GetSiteSettingsAsync(); - var settings = site.As(); + var settings = await _siteService.GetSettingsAsync(); if (settings.UseCustomConfiguration) { diff --git a/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Services/AzureAISearchService.cs b/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Services/AzureAISearchService.cs index e34c634e412..186828c47a3 100644 --- a/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Services/AzureAISearchService.cs +++ b/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Services/AzureAISearchService.cs @@ -47,8 +47,7 @@ public async Task SearchAsync(string indexName, string term, int s return result; } - var siteSettings = await _siteService.GetSiteSettingsAsync(); - var searchSettings = siteSettings.As(); + var searchSettings = await _siteService.GetSettingsAsync(); var index = !string.IsNullOrWhiteSpace(indexName) ? indexName.Trim() : searchSettings.SearchIndex; diff --git a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexingService.cs b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexingService.cs index a463bd11635..55991703176 100644 --- a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexingService.cs +++ b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexingService.cs @@ -9,7 +9,6 @@ using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Records; -using OrchardCore.Entities; using OrchardCore.Environment.Shell; using OrchardCore.Indexing; using OrchardCore.Modules; @@ -280,17 +279,8 @@ public async Task RebuildIndexAsync(ElasticIndexSettings elasticIndexSettings) await ResetIndexAsync(elasticIndexSettings.IndexName); } - public async Task GetElasticSettingsAsync() - { - var siteSettings = await _siteService.GetSiteSettingsAsync(); - - if (siteSettings.Has()) - { - return siteSettings.As(); - } - - return new ElasticSettings(); - } + public async Task GetElasticSettingsAsync() + => await _siteService.GetSettingsAsync() ?? new ElasticSettings(); /// /// Synchronizes Elasticsearch content index settings with Lucene ones. diff --git a/src/OrchardCore/OrchardCore.Settings.Core/Deployment/SiteSettingsPropertyDeploymentSource.cs b/src/OrchardCore/OrchardCore.Settings.Core/Deployment/SiteSettingsPropertyDeploymentSource.cs index 1f57c38402c..ef3c3e278a5 100644 --- a/src/OrchardCore/OrchardCore.Settings.Core/Deployment/SiteSettingsPropertyDeploymentSource.cs +++ b/src/OrchardCore/OrchardCore.Settings.Core/Deployment/SiteSettingsPropertyDeploymentSource.cs @@ -21,10 +21,8 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan return; } - var siteSettings = await _siteService.GetSiteSettingsAsync(); - var settingJPropertyName = typeof(TModel).Name; - var settingJPropertyValue = JObject.FromObject(siteSettings.As()); + var settingJPropertyValue = JObject.FromObject(await _siteService.GetSettingsAsync()); var settingsStepJObject = result.Steps.FirstOrDefault(s => s["name"]?.ToString() == "Settings"); if (settingsStepJObject != null) diff --git a/src/OrchardCore/OrchardCore.Sms.Core/Services/DefaultSmsProviderResolver.cs b/src/OrchardCore/OrchardCore.Sms.Core/Services/DefaultSmsProviderResolver.cs index aab4b71fcef..bfc68db7603 100644 --- a/src/OrchardCore/OrchardCore.Sms.Core/Services/DefaultSmsProviderResolver.cs +++ b/src/OrchardCore/OrchardCore.Sms.Core/Services/DefaultSmsProviderResolver.cs @@ -31,9 +31,7 @@ public async Task GetAsync(string name = null) { if (string.IsNullOrEmpty(name)) { - var site = await _siteService.GetSiteSettingsAsync(); - - var settings = site.As(); + var settings = await _siteService.GetSettingsAsync(); name = settings.DefaultProviderName; } diff --git a/src/OrchardCore/OrchardCore.Sms.Core/Services/SmsSettingsConfiguration.cs b/src/OrchardCore/OrchardCore.Sms.Core/Services/SmsSettingsConfiguration.cs index 726145cf60b..91a5c9d2976 100644 --- a/src/OrchardCore/OrchardCore.Sms.Core/Services/SmsSettingsConfiguration.cs +++ b/src/OrchardCore/OrchardCore.Sms.Core/Services/SmsSettingsConfiguration.cs @@ -14,9 +14,9 @@ public SmsSettingsConfiguration(ISiteService siteService) public void PostConfigure(string name, SmsSettings options) { - var site = _siteService.GetSiteSettingsAsync().GetAwaiter().GetResult(); - - var settings = site.As(); + var settings = _siteService.GetSettingsAsync() + .GetAwaiter() + .GetResult(); options.DefaultProviderName = settings.DefaultProviderName; } diff --git a/src/OrchardCore/OrchardCore.Sms.Core/Services/TwilioProviderOptionsConfigurations.cs b/src/OrchardCore/OrchardCore.Sms.Core/Services/TwilioProviderOptionsConfigurations.cs index cf027b2ee9d..5cd9d2a7538 100644 --- a/src/OrchardCore/OrchardCore.Sms.Core/Services/TwilioProviderOptionsConfigurations.cs +++ b/src/OrchardCore/OrchardCore.Sms.Core/Services/TwilioProviderOptionsConfigurations.cs @@ -17,8 +17,9 @@ public void Configure(SmsProviderOptions options) { var typeOptions = new SmsProviderTypeOptions(typeof(TwilioSmsProvider)); - var site = _siteService.GetSiteSettingsAsync().GetAwaiter().GetResult(); - var settings = site.As(); + var settings = _siteService.GetSettingsAsync() + .GetAwaiter() + .GetResult(); typeOptions.IsEnabled = settings.IsEnabled; diff --git a/src/OrchardCore/OrchardCore.Sms.Core/Services/TwilioSmsProvider.cs b/src/OrchardCore/OrchardCore.Sms.Core/Services/TwilioSmsProvider.cs index c81848ddb2e..6fd3a97ade5 100644 --- a/src/OrchardCore/OrchardCore.Sms.Core/Services/TwilioSmsProvider.cs +++ b/src/OrchardCore/OrchardCore.Sms.Core/Services/TwilioSmsProvider.cs @@ -116,7 +116,7 @@ private async Task GetSettingsAsync() { if (_settings == null) { - var settings = (await _siteService.GetSiteSettingsAsync()).As(); + var settings = await _siteService.GetSettingsAsync(); var protector = _dataProtectionProvider.CreateProtector(ProtectorName); diff --git a/src/OrchardCore/OrchardCore.Users.Core/Services/DefaultTwoFactorAuthenticationHandler.cs b/src/OrchardCore/OrchardCore.Users.Core/Services/DefaultTwoFactorAuthenticationHandler.cs index aa9db239c36..098e96f33e1 100644 --- a/src/OrchardCore/OrchardCore.Users.Core/Services/DefaultTwoFactorAuthenticationHandler.cs +++ b/src/OrchardCore/OrchardCore.Users.Core/Services/DefaultTwoFactorAuthenticationHandler.cs @@ -15,7 +15,5 @@ public DefaultTwoFactorAuthenticationHandler(ISiteService siteService) } public async Task IsRequiredAsync(IUser user) - { - return (await _siteService.GetSiteSettingsAsync()).As().RequireTwoFactorAuthentication; - } + => (await _siteService.GetSettingsAsync()).RequireTwoFactorAuthentication; } diff --git a/src/OrchardCore/OrchardCore.Users.Core/Services/UserService.cs b/src/OrchardCore/OrchardCore.Users.Core/Services/UserService.cs index 2e40d3110f1..e03996e5b82 100644 --- a/src/OrchardCore/OrchardCore.Users.Core/Services/UserService.cs +++ b/src/OrchardCore/OrchardCore.Users.Core/Services/UserService.cs @@ -47,7 +47,7 @@ public UserService( public async Task AuthenticateAsync(string usernameOrEmail, string password, Action reportError) { - var disableLocalLogin = (await _siteService.GetSiteSettingsAsync()).As().DisableLocalLogin; + var disableLocalLogin = (await _siteService.GetSettingsAsync()).DisableLocalLogin; if (disableLocalLogin) { diff --git a/src/docs/releases/2.0.0.md b/src/docs/releases/2.0.0.md index 64dce12a17f..96198fd6f91 100644 --- a/src/docs/releases/2.0.0.md +++ b/src/docs/releases/2.0.0.md @@ -516,8 +516,22 @@ public class ReverseProxySettingsDisplayDriver : SectionDisplayDriver()` has been added to the `ISiteService` interface. This method allows you to retrieve specific settings with a single line of code. For example, to get the `LoginSettings`, you can now use: + +```csharp +await _siteService.GetSettingsAsync(); +``` + +Previously, achieving the same result required more code: + +```csharp +(await _siteService.GetSiteSettingsAsync()).As(); +``` + ### Content Fields Before this release, the `MarkdownField` used a single-line input field by default (named the Standard editor) and offered two different editors: Multi-line with a simple `textarea` and WYSIWYG with a rich editor. Now, by default, it uses a `textarea` as the Standard editor, and the separate Multi-line option has been removed. -You have nothing to do, fields configured with the Standard or Multi-line editors previously will both continue to work. Note though, that their editors will now be a `textarea`. \ No newline at end of file +You have nothing to do, fields configured with the Standard or Multi-line editors previously will both continue to work. Note though, that their editors will now be a `textarea`.