示例#1
0
 private void UpdateModIDFromParent(int parentID, int moduleID)
 {
     FileController ctrlFiles = new FileController();
     foreach (File file in ctrlFiles.GetItems(parentID))
     {
         file.ModuleID = moduleID;
         ctrlFiles.Update(file);
         UpdateModIDFromParent(file.ID, moduleID);
     }
 }
        private void DeleteChildren(File file)
        {
            //delete ALL children items where user has delete permission

            FileController fileCtrl = new FileController();
            List<File> files = fileCtrl.GetItems(file.ID) as List<File>;
            foreach (File childFile in files)
            {
                if (file.ItemType == 0)
                {
                    DeleteChildren(childFile);
                }
            }
                //send to trash if not folder
                if (file.ItemType != 0 && file.CanDelete(UserId, PortalId, PortalSettings.AdministratorRoleId, false))
                {
                    //send to trash if not there already
                    if (!file.IsInTrash)
                    {
                        file.IsInTrash = true;
                        fileCtrl.Update(file);
                        #region "Audit"
                        //Audit: Create Item
                        AuditController ctrlAudit = new AuditController();
                        Audit deleteAudit = new Audit() { EventDate = file.LastModifiedDate, EventDetails = "", EventName = "Deleted", FileID = file.ID, UserID = UserId };
                        ctrlAudit.Create(deleteAudit);
                        #endregion
                        _deletedFilesCount++;
                        return;
                    }

                    //if file is in trash, delete permissions and file
                    if (file.IsInTrash)
                    {
                        PermissionController permCtrl = new PermissionController();

                        //delete versions and version permissions
                        List<File> versions = fileCtrl.GetItems(file.ID) as List<File>;
                        foreach (File version in versions)
                        {
                            List<Permission> versionPermissions = permCtrl.GetItems(version.ID) as List<Permission>;
                            for (int i = 0; versionPermissions.Count - 1 > i; i++)
                            {
                                permCtrl.Delete(versionPermissions[i]);
                            }
                            fileCtrl.Delete(version);
                        }

                        //delete file permissions
                        List<Permission> folderPermissions = permCtrl.GetItems(file.ID) as List<Permission>;
                        for (int i = 0; folderPermissions.Count - 1 >= i; i++)
                        {
                            permCtrl.Delete(folderPermissions[i]);
                        }

                        //delete file instead of sending to trash
                        _filesToDelete.Add(file);
                        //fileCtrl.Delete(file);

                        _permanentlyDeletedFilesCount++;
                        return;
                    }
                }

                //check if any items exist under folder and delete permission before deleting
                if (file.ItemType == 0 && file.CanDelete(UserId, PortalId, PortalSettings.AdministratorRoleId, false))
                {
                    //get current child count
                    List<File> childFiles = fileCtrl.GetItems(file.ID) as List<File>;
                    int childFilesCount = 0;

                    //count child items not in trash
                    foreach (File childFileCount in childFiles)
                    {
                        if (!childFileCount.IsInTrash)
                        {
                            childFilesCount++;
                        }
                    }

                    //no child items, permanently delete folder
                    if (childFilesCount == 0)
                    {
                        //delete folder permissions
                        PermissionController permCtrl = new PermissionController();
                        List<Permission> folderPermissions = permCtrl.GetItems(file.ID) as List<Permission>;
                        for (int i = 0; folderPermissions.Count - 1 >=  i; i++)
                        {
                            permCtrl.Delete(folderPermissions[i]);
                        }

                        //delete folder instead of sending to trash
                        _filesToDelete.Add(file);
                        //fileCtrl.Delete(file);

                        _deletedFilesCount++;
                        return;
                    }
                    else
                    {
                        _notDeletedFilesCount++;
                        return;
                    }
                }
                _notDeletedFilesCount++;
        }
        private void ApplyPermissionsToDirectChildren(File file, List<Permission> filePermissions)
        {
            FileController fileCtrl = new FileController();
            PermissionController permCtrl = new PermissionController();
            //List<File> childFiles = fileCtrl.GetItemsByParent(file.ID, UserId, PortalId, PortalSettings.AdministratorRoleId, "");
            List<File> childFiles = fileCtrl.GetItems(file.ID) as List<File>;
            foreach (File childFile in childFiles)
            {
                //check edit permission
                if (childFile.CanEditPermissions(UserId, PortalId, PortalSettings.AdministratorRoleId, false))
                {
                    //delete existing permissions
                    List<Permission> deletePermissions = permCtrl.GetItems(childFile.ID) as List<Permission>;
                    foreach (Permission deletePermission in deletePermissions)
                    {
                        Permission permissionToDelete = permCtrl.Get(deletePermission.ID, childFile.ID);
                        permCtrl.Delete(permissionToDelete);
                    }

                    //add file permissions
                    foreach (Permission filePermission in filePermissions)
                    {
                        Permission newPermission = new Permission();
                        newPermission.ID = filePermission.ID;
                        newPermission.ModuleID = filePermission.ModuleID;
                        newPermission.PortalID = filePermission.PortalID;
                        newPermission.CanSee = filePermission.CanSee;
                        newPermission.CanModify = filePermission.CanModify;
                        newPermission.CanAddFiles = filePermission.CanAddFiles;
                        newPermission.CanAddFolders = filePermission.CanAddFolders;
                        newPermission.CanDelete = filePermission.CanDelete;
                        newPermission.CanModifyPermission = filePermission.CanModifyPermission;
                        newPermission.IsOwner = filePermission.IsOwner;
                        newPermission.RoleID = filePermission.RoleID;
                        newPermission.RoleName = filePermission.RoleName;
                        newPermission.UserID = filePermission.UserID;
                        newPermission.UserName = filePermission.UserName;

                        //assign new permission to child item
                        newPermission.FileID = childFile.ID;
                        permCtrl.Create(newPermission);
                    }

                    //report updated file
                    _updatedPermissionFiles.Add(childFile);
                }
                else
                {
                    //report non-updated file
                    _notUpdatedPermissionFiles.Add(childFile);
                }

                //do child files
                ApplyPermissionsToDirectChildren(childFile, filePermissions);
            }
        }