Exemplo n.º 1
0
        public async Task <IActionResult> Delete(string id)
        {
            // Ensure we have permission
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.DeleteThemes))
            {
                return(Unauthorized());
            }

            // Get theme
            var theme = _siteThemeLoader
                        .AvailableThemes.FirstOrDefault(t => t.Id.Equals(id, StringComparison.OrdinalIgnoreCase));

            // Ensure we found the theme
            if (theme == null)
            {
                return(NotFound());
            }

            // Is the theme we are deleting our current theme
            var currentTheme = await _contextFacade.GetCurrentThemeAsync();

            if (currentTheme.Equals(theme.FullPath, StringComparison.OrdinalIgnoreCase))
            {
                // Get settings
                var settings = await _siteSettingsStore.GetAsync();

                // Clear theme, ensures we fallback to our default theme
                settings.Theme = "";

                // Save settings
                var updatedSettings = await _siteSettingsStore.SaveAsync(settings);

                if (updatedSettings != null)
                {
                    // Recycle shell context to ensure changes take effect
                    _platoHost.RecycleShell(_shellSettings);
                }
            }

            // Delete the theme from the file system
            var result = _fileSystem.DeleteDirectory(theme.FullPath);

            if (result)
            {
                _alerter.Success(T["Theme Deleted Successfully"]);
            }
            else
            {
                _alerter.Danger(T[$"Could not delete the theme at \"{theme.FullPath}\""]);
            }

            return(RedirectToAction(nameof(Index)));
        }