Ejemplo n.º 1
0
        public ActionResult DeleteTheme(int id)
        {
            // Check if the theme exists.
            if (!_themeRepository.DoesThemeExist(id))
            {
                return(SiteErrorHandler.GetBadRequestActionResult("Could not find the theme.", ""));
            }

            // Check if the theme is a system theme.
            if (_themeRepository.IsThemeReadOnly(id))
            {
                return(SiteErrorHandler.GetBadRequestActionResult($"This is a system theme and cannot be deleted.", ""));
            }

            // Check if the theme is in use.
            if (_themeRepository.IsActiveTheme(id))
            {
                return(SiteErrorHandler.GetBadRequestActionResult("Cannot delete the theme as it is currently in use.", ""));
            }

            // Delete the theme.
            _themeRepository.DeleteTheme(id);

            return(Json(new { message = "<strong>Success</strong>: The theme has been deleted." }));
        }
Ejemplo n.º 2
0
        public void Delete(string themename)
        {
            List <Theme> themes = _themes.GetThemes().ToList();
            Theme        theme  = themes.Where(item => item.ThemeName == themename).FirstOrDefault();

            if (theme != null && Utilities.GetAssemblyName(theme.ThemeName) != "Oqtane.Client")
            {
                // remove theme assets
                if (_installationManager.UninstallPackage(theme.PackageName))
                {
                    _logger.Log(LogLevel.Information, this, LogFunction.Delete, "Theme Assets Removed For {ThemeName}", theme.ThemeName);
                }
                else
                {
                    // attempt to delete assemblies based on naming convention
                    foreach (string asset in Directory.GetFiles(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), Utilities.GetTypeName(theme.ThemeName) + "*.*"))
                    {
                        System.IO.File.Delete(asset);
                    }
                    _logger.Log(LogLevel.Warning, this, LogFunction.Delete, "Theme Assets Removed For {ThemeName}. Please Note That Some Assets May Have Been Missed Due To A Missing Asset Manifest. An Asset Manifest Is Only Created If A Theme Is Installed From A Nuget Package.", theme.ThemeName);
                }

                // clean up theme static resource folder
                string assetpath = Path.Combine(_environment.WebRootPath, "Themes", Utilities.GetTypeName(theme.ThemeName));
                if (Directory.Exists(assetpath))
                {
                    Directory.Delete(assetpath, true);
                    _logger.Log(LogLevel.Information, this, LogFunction.Delete, "Theme Static Resource Folder Removed For {ThemeName}", theme.ThemeName);
                }

                // remove theme
                _themes.DeleteTheme(theme.ThemeName);
                _logger.Log(LogLevel.Information, this, LogFunction.Delete, "Theme Removed For {ThemeName}", theme.ThemeName);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Deletes theme with provided id
        /// </summary>
        /// <param name="themeId">id of selected theme</param>
        /// <returns>result of operation</returns>
        public bool DeleteTheme(int themeId)
        {
            var courses = _courseService.GetCoursesByTheme(themeId);

            foreach (var course in courses)
            {
                _courseService.DeleteCourse(course.CourseId);
            }
            var res = _themeRepository.DeleteTheme(themeId);

            return(res);
        }
Ejemplo n.º 4
0
        public void Delete(string themename)
        {
            List <Theme> themes = _themes.GetThemes().ToList();
            Theme        theme  = themes.Where(item => item.ThemeName == themename).FirstOrDefault();

            if (theme != null && Utilities.GetAssemblyName(theme.ThemeName) != "Oqtane.Client")
            {
                // remove theme assets
                string assetpath = Path.Combine(_environment.WebRootPath, "Themes", Utilities.GetTypeName(theme.ThemeName));
                if (System.IO.File.Exists(Path.Combine(assetpath, "assets.json")))
                {
                    // use assets.json to clean up file resources
                    List <string> assets = JsonSerializer.Deserialize <List <string> >(System.IO.File.ReadAllText(Path.Combine(assetpath, "assets.json")));
                    assets.Reverse();
                    foreach (string asset in assets)
                    {
                        // legacy support for assets that were stored as absolute paths
                        string filepath = (asset.StartsWith("\\")) ? Path.Combine(_environment.ContentRootPath, asset.Substring(1)) : asset;
                        if (System.IO.File.Exists(filepath))
                        {
                            System.IO.File.Delete(filepath);
                            if (!Directory.EnumerateFiles(Path.GetDirectoryName(filepath)).Any())
                            {
                                Directory.Delete(Path.GetDirectoryName(filepath));
                            }
                        }
                    }
                    _logger.Log(LogLevel.Information, this, LogFunction.Delete, "Theme Assets Removed For {ThemeName}", theme.ThemeName);
                }
                else
                {
                    // attempt to delete assemblies based on naming convention
                    foreach (string asset in Directory.GetFiles(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), Utilities.GetTypeName(theme.ThemeName) + "*.*"))
                    {
                        System.IO.File.Delete(asset);
                    }
                    _logger.Log(LogLevel.Warning, this, LogFunction.Delete, "Theme Assets Removed For {ThemeName}. Please Note That Some Assets May Have Been Missed Due To A Missing Asset Manifest. An Asset Manifest Is Only Created If A Theme Is Installed From A Nuget Package.", theme.ThemeName);
                }

                // clean up theme static resource folder
                string folder = Path.Combine(_environment.WebRootPath, "Themes", Utilities.GetTypeName(theme.ThemeName));
                if (Directory.Exists(folder))
                {
                    Directory.Delete(folder, true);
                    _logger.Log(LogLevel.Information, this, LogFunction.Delete, "Theme Static Resource Folder Removed For {ThemeName}", theme.ThemeName);
                }

                // remove theme
                _themes.DeleteTheme(theme.ThemeName);
                _logger.Log(LogLevel.Information, this, LogFunction.Delete, "Theme Removed For {ThemeName}", theme.ThemeName);
            }
        }