/// <summary> /// Populates the folder with folders. /// </summary> /// <param name="folder">The folder.</param> /// <param name="children">The children.</param> private void PopulateFolderWithFolders(UmbracoFolderModel folder, ConcurrentBag <IMedia> children) { if (children.Any(p => p.ContentType.Alias == MediaTypeAlias.Folder)) { var childrenFolders = children.BuildFolderModels(UserService); folder.Folders.AddRange(childrenFolders); } }
/// <summary> /// Populates the folder with images. /// </summary> /// <param name="folder">The folder.</param> /// <param name="children">The children.</param> private void PopulateFolderWithImages(UmbracoFolderModel folder, IEnumerable <IMedia> children) { if (children.Any(p => p.ContentType.Alias == MediaTypeAlias.Image)) { var childrenImages = children.BuildImageModels(UserService); folder.Images.AddRange(childrenImages); } }
/// <summary> /// Builds the root folder. /// </summary> /// <param name="rootMedia">The root media.</param> /// <returns></returns> private UmbracoFolderModel BuildRootFolder(ConcurrentBag <IMedia> rootMedia) { var images = rootMedia.BuildImageModels(UserService); var folders = rootMedia.BuildFolderModels(UserService); var rootFolder = new UmbracoFolderModel(folders.ToList(), images.ToList()); return(rootFolder); }
/// <summary> /// Builds the folder structure. /// </summary> /// <param name="currentFolder">The current folder.</param> /// <param name="isRootFolder">if set to <c>true</c> [is root folder].</param> private void BuildFolderStructure(UmbracoFolderModel currentFolder, bool isRootFolder = false) { if (!isRootFolder) { var currentFolderChildren = GetFolderChildren(currentFolder); var concurrentFolderChildren = new ConcurrentBag <IMedia>(currentFolderChildren); PopulateFolderWithFolders(currentFolder, concurrentFolderChildren); PopulateFolderWithImages(currentFolder, currentFolderChildren); } foreach (var folder in currentFolder.Folders) { BuildFolderStructure(folder); } }
/// <summary> /// Gets the folder children. /// </summary> /// <param name="folder">The folder.</param> /// <returns></returns> private IEnumerable <IMedia> GetFolderChildren(UmbracoFolderModel folder) { var children = MediaService.GetChildren(folder.Id); return(children); }