Esempio n. 1
0
        public async Task <ActionResult> SetCurrentTheme(string id)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ApplyTheme))
            {
                return(Forbid());
            }

            if (String.IsNullOrEmpty(id))
            {
                // Don't use any theme on the front-end
            }
            else
            {
                var feature = (await _shellFeaturesManager.GetAvailableFeaturesAsync())
                              .FirstOrDefault(f => f.IsTheme() && f.Id == id);

                if (feature == null)
                {
                    return(NotFound());
                }
                else
                {
                    var isAdmin = IsAdminTheme(feature.Extension.Manifest);

                    if (isAdmin)
                    {
                        await _adminThemeService.SetAdminThemeAsync(id);
                    }
                    else
                    {
                        await _siteThemeService.SetSiteThemeAsync(id);
                    }

                    // Enable the feature lastly to avoid accessing a disposed IMemoryCache (due to the current shell being disposed after updating).
                    var enabledFeatures = await _shellFeaturesManager.GetEnabledFeaturesAsync();

                    var isEnabled = enabledFeatures.Any(x => x.Extension.Id == feature.Id);

                    if (!isEnabled)
                    {
                        await _shellFeaturesManager.EnableFeaturesAsync(new[] { feature }, force : true);

                        await _notifier.SuccessAsync(H["{0} was enabled", feature.Name ?? feature.Id]);
                    }

                    await _notifier.SuccessAsync(H["{0} was set as the default {1} theme", feature.Name ?? feature.Id, isAdmin ? "Admin" : "Site"]);
                }
            }

            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 2
0
        public async Task <ActionResult> Index(SelectThemesViewModel model)
        {
            await _siteThemeService.SetSiteThemeAsync(model.SiteThemeName);

            await _adminThemeService.SetAdminThemeAsync(model.AdminThemeName);

            return(RedirectToAction("Index"));
        }
Esempio n. 3
0
        public override async Task ExecuteAsync(RecipeExecutionContext recipeContext)
        {
            var model = recipeContext.RecipeStep.Step.ToObject <ThemeStepModel>();

            if (!String.IsNullOrEmpty(model.Site))
            {
                await _siteThemeService.SetSiteThemeAsync(model.Site);
            }

            if (!String.IsNullOrEmpty(model.Admin))
            {
                await _adminThemeService.SetAdminThemeAsync(model.Admin);
            }
        }
Esempio n. 4
0
        public async Task ExecuteAsync(RecipeExecutionContext context)
        {
            if (!String.Equals(context.Name, "Themes", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var model = context.Step.ToObject <ThemeStepModel>();

            if (!String.IsNullOrEmpty(model.Site))
            {
                await _siteThemeService.SetSiteThemeAsync(model.Site);
            }

            if (!String.IsNullOrEmpty(model.Admin))
            {
                await _adminThemeService.SetAdminThemeAsync(model.Admin);
            }
        }
Esempio n. 5
0
        public async Task <ActionResult> SetCurrentTheme(string id)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ApplyTheme)) // , T["Couldn't set the current theme."]
            {
                return(Unauthorized());
            }

            var feature = _extensionManager.GetFeatures().FirstOrDefault(f => f.Extension.IsTheme() && f.Id == id);

            if (feature == null)
            {
                return(NotFound());
            }
            else
            {
                var isAdmin = IsAdminTheme(feature.Extension.Manifest);

                if (isAdmin)
                {
                    await _adminThemeService.SetAdminThemeAsync(id);
                }
                else
                {
                    await _siteThemeService.SetSiteThemeAsync(id);
                }

                // Enable the feature lastly to avoid accessing a disposed IMemoryCache (due to the current shell being disposed after updating).
                var enabledFeatures = await _shellFeaturesManager.GetEnabledFeaturesAsync();

                var isEnabled = enabledFeatures.Any(x => x.Extension.Id == feature.Id);

                if (!isEnabled)
                {
                    await _shellFeaturesManager.EnableFeaturesAsync(new[] { feature }, force : true);

                    _notifier.Success(T["{0} was enabled", feature.Name ?? feature.Id]);
                }

                _notifier.Success(T["{0} was set as the default {1} theme", feature.Name ?? feature.Id, isAdmin ? "Admin" : "Site"]);
            }

            return(RedirectToAction("Index"));
        }