public static IList <FolderRelation> ResourceFolderTree(IList <FolderRelation> movedFolders) { var user = UserService.CurrentUser; //用户所有的课程 IList <OC> ocs = UserService.User_OC_List(user); IList <FolderRelation> roots = new List <FolderRelation>(); FolderRelation fr = new FolderRelation(); fr.Id = 0; fr.Name = "个人资料"; fr.ParentID = 0; fr.RelationType = FileType.None; roots.Add(fr); foreach (var item in ocs) { fr = new FolderRelation(); fr.Id = item.OCID; fr.Name = item.Name; fr.ParentID = 0; fr.OCID = item.OCID; fr.RelationType = FileType.None; roots.Add(fr); } IList <FolderRelation> relationFolders = new List <FolderRelation>(); IList <Folder> folders = new FileBLL().Folder_ALL_Tree(user.UserID); foreach (var item in folders) { var exists = from v in movedFolders where item.FolderID == v.Id && v.RelationType == FileType.Folder select v; if (exists.Any()) { continue; } fr = new FolderRelation(); fr.Id = item.FolderID; fr.Name = item.FolderName; //fr.ParentID = item.ParentID == 0 ? item.OCID : item.ParentID; fr.ParentID = item.ParentID; fr.RelationType = FileType.Folder; fr.OCID = item.OCID; relationFolders.Add(fr); } var rootFolders = from v in relationFolders where v.ParentID == 0 select v; foreach (var rootFolder in rootFolders) { BuildRelationFolder(relationFolders, rootFolder); var root = from v in roots where v.OCID == rootFolder.OCID select v; if (root.Any()) { root.First().Children.Add(rootFolder); } } return(roots); }
private static void BuildRelationFolder(IList <FolderRelation> allFolders, FolderRelation root) { var children = from v in allFolders where v.ParentID == root.Id select v; foreach (var child in children) { root.Children.Add(child); if (child.RelationType == FileType.Folder) { BuildRelationFolder(allFolders, child); } } }
public static IList <FolderRelation> FolderRelation_List(Folder folder, File file) { //if (folder.ParentID == 0) folder.ParentID = -1; //IList<Folder> allFolders = new FileBLL().Folder_List(folder); folder.CreateUserID = IES.Service.UserService.CurrentUser.UserID; IList <Folder> allFolders = Folder_List(folder); if (file != null) { file.FolderID = folder.ParentID; //file.UploadTime = DateTime.Now.AddMonths(-1); } file.CreateUserID = IES.Service.UserService.CurrentUser.UserID; IList <File> allFiles = new FileBLL().File_Search(file); IList <FolderRelation> allFolderRelations = new List <FolderRelation>(); //TODO if (file.FileTitle == "") { foreach (var item in allFolders) { FolderRelation fr = new FolderRelation(); fr.Id = item.FolderID; fr.Name = item.FolderName; fr.OCID = item.OCID; fr.ParentID = item.ParentID; fr.RelationType = FileType.Folder; fr.CourseId = item.CourseID; //fr.CreateTime = new DateTime(); fr.CreateUserID = item.CreateUserID; fr.CreateTime = item.CreateTime; fr.ShareRange = item.ShareRange; allFolderRelations.Add(fr); } } foreach (var item in allFiles) { FolderRelation fr = new FolderRelation(); fr.Id = item.FileID; fr.Name = item.FileTitle; fr.OCID = item.OCID; fr.ParentID = item.FolderID; fr.RelationType = FileType.File; fr.CourseId = item.CourseID; fr.FileSize = item.FileSize; fr.Ext = item.Ext; fr.CreateTime = item.UploadTime; fr.FileType = item.FileType; fr.ShareRange = item.ShareRange; fr.Kens = item.Kens; fr.CreateUserID = item.CreateUserID; if (item.FileType == 1 || item.FileType == 2 || item.FileType == 4 || item.FileType == 6) { fr.DownURL = item.ViewURL; } else { fr.DownURL = item.DownURL; } fr.CreateUserName = item.CreateUserName; allFolderRelations.Add(fr); } IList <FolderRelation> roots = new List <FolderRelation>(); foreach (var root in allFolderRelations) { var parentId = folder.ParentID == -1 ? 0 : folder.ParentID; if (root.ParentID == parentId) { roots.Add(root); } } foreach (var root in roots) { if (root.RelationType == FileType.Folder) { BuildRelationFolder(allFolderRelations, root); } } return(roots.ToList()); }