public PageViewModel GetFolderContent(int moduleId, int folderId, int startIndex, int numItems, string sortExpression) { var folder = GetFolderInfo(folderId); if (!FolderPermissionController.CanBrowseFolder((FolderInfo)folder)) { //The user cannot access the content return(new PageViewModel { Folder = GetFolderViewModel(folder), Items = new List <ItemViewModel>(), TotalCount = 0 }); } var sortProperties = SortProperties.Parse(sortExpression); List <IFolderInfo> folders; var subfolderFilter = SettingsRepository.GetSubfolderFilter(moduleId); if (subfolderFilter != SubfolderFilter.IncludeSubfoldersFolderStructure) { folders = new List <IFolderInfo>(); } else { folders = GetFolders(folder, sortProperties.Column == "ItemName" ? "FolderName" : sortProperties.Column, sortProperties.Ascending).ToList(); } var recursive = subfolderFilter == SubfolderFilter.IncludeSubfoldersFilesOnly; var files = GetFiles(folder, sortProperties, startIndex, recursive).ToList(); IEnumerable <ItemViewModel> content; if (startIndex + numItems <= folders.Count()) { content = folders.Skip(startIndex).Take(numItems).Select(GetItemViewModel); } else if (startIndex >= folders.Count()) { content = files.Skip(startIndex - folders.Count).Take(numItems).Select(GetItemViewModel); } else { var numFiles = numItems - (folders.Count - startIndex); content = folders.Skip(startIndex).Select(GetItemViewModel).Union(files.Take(numFiles).Select(GetItemViewModel)); } return(new PageViewModel { Folder = GetFolderViewModel(folder), Items = content.ToList(), TotalCount = folders.Count() + files.Count() }); }
public PageViewModel SearchFolderContent(int moduleId, int folderId, string pattern, int startIndex, int numItems, string sortExpression) { var recursive = SettingsRepository.GetSubfolderFilter(moduleId) != SubfolderFilter.ExcludeSubfolders; var folder = GetFolderInfo(folderId); var files = FolderManager.Instance.SearchFiles(folder, pattern, recursive); var sortProperties = SortProperties.Parse(sortExpression); var sortedFiles = SortFiles(files, sortProperties).ToList(); return(new PageViewModel { Folder = GetFolderViewModel(folder), Items = sortedFiles.Skip(startIndex).Take(numItems).Select(GetItemViewModel).ToList(), TotalCount = sortedFiles.Count() }); }
/// <inheritdoc/> public IList <IFileInfo> SearchFolderContent(int moduleId, IFolderInfo folder, bool recursive, string search, int pageIndex, int pageSize, string sorting, int moduleMode, out int totalCount) { var noPermissionMessage = Localization.GetExceptionMessage( "UserHasNoPermissionToBrowseFolder", Constants.UserHasNoPermissionToBrowseFolderDefaultMessage); if (!this.permissionsManager.HasFolderContentPermission(folder.FolderID, moduleMode)) { throw new FolderPermissionNotMetException(noPermissionMessage); } search = (search ?? string.Empty).Trim(); var files = FolderManager.Instance.SearchFiles(folder, search, recursive); var sortProperties = SortProperties.Parse(sorting); var sortedFiles = SortFiles(files, sortProperties).ToList(); totalCount = sortedFiles.Count; return(sortedFiles.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList()); }