diff --git a/Oqtane.Server/Controllers/FolderController.cs b/Oqtane.Server/Controllers/FolderController.cs index 12a9c3fa..e456c61f 100644 --- a/Oqtane.Server/Controllers/FolderController.cs +++ b/Oqtane.Server/Controllers/FolderController.cs @@ -43,7 +43,7 @@ namespace Oqtane.Controllers int SiteId; if (int.TryParse(siteid, out SiteId) && SiteId == _alias.SiteId) { - var hierarchy = GetFoldersHierarchy(_folders.GetFolders(SiteId).ToList()); + var hierarchy = _folders.GetFolders(SiteId).ToList(); foreach (Folder folder in hierarchy) { // note that Browse permission is used for this method @@ -281,47 +281,5 @@ namespace Oqtane.Controllers HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden; } } - - private static List GetFoldersHierarchy(List folders) - { - List hierarchy = new List(); - Action, Folder> getPath = null; - getPath = (folderList, folder) => - { - IEnumerable children; - int level; - if (folder == null) - { - level = -1; - children = folders.Where(item => item.ParentId == null); - } - else - { - level = folder.Level; - children = folders.Where(item => item.ParentId == folder.FolderId); - } - - foreach (Folder child in children) - { - child.Level = level + 1; - child.HasChildren = folders.Any(item => item.ParentId == child.FolderId); - hierarchy.Add(child); - getPath(folderList, child); - } - }; - folders = folders.OrderBy(item => item.Name).ToList(); - getPath(folders, null); - - // add any non-hierarchical items to the end of the list - foreach (Folder folder in folders) - { - if (hierarchy.Find(item => item.FolderId == folder.FolderId) == null) - { - hierarchy.Add(folder); - } - } - - return hierarchy; - } } } diff --git a/Oqtane.Server/Repository/FolderRepository.cs b/Oqtane.Server/Repository/FolderRepository.cs index fb68033f..d7f1c43e 100644 --- a/Oqtane.Server/Repository/FolderRepository.cs +++ b/Oqtane.Server/Repository/FolderRepository.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Hosting; @@ -45,7 +46,49 @@ namespace Oqtane.Repository { folder.PermissionList = permissions.Where(item => item.EntityId == folder.FolderId).ToList(); } - return folders; + return GetFoldersHierarchy(folders); + } + + private static List GetFoldersHierarchy(List folders) + { + List hierarchy = new List(); + Action, Folder> getPath = null; + getPath = (folderList, folder) => + { + IEnumerable children; + int level; + if (folder == null) + { + level = -1; + children = folders.Where(item => item.ParentId == null); + } + else + { + level = folder.Level; + children = folders.Where(item => item.ParentId == folder.FolderId); + } + + foreach (Folder child in children) + { + child.Level = level + 1; + child.HasChildren = folders.Any(item => item.ParentId == child.FolderId); + hierarchy.Add(child); + getPath(folderList, child); + } + }; + folders = folders.OrderBy(item => item.Name).ToList(); + getPath(folders, null); + + // add any non-hierarchical items to the end of the list + foreach (Folder folder in folders) + { + if (hierarchy.Find(item => item.FolderId == folder.FolderId) == null) + { + hierarchy.Add(folder); + } + } + + return hierarchy; } public Folder AddFolder(Folder folder)