private string findFolder(string parentFolderId, string folderName)
    {
        if (string.IsNullOrEmpty(folderName) || string.IsNullOrEmpty(parentFolderId))
        {
            return(null);
        }
        try
        {
            const string FOLDER_CARD_TYPE = "{DA86FABF-4DD7-4A86-B6FF-C58C24D12DE2}";
            FolderCard   folderCard       = (FolderCard)Session.CardManager.GetDictionary(new Guid(FOLDER_CARD_TYPE));

            Folder rootFolder = folderCard.GetFolder(new Guid(parentFolderId.ToString()));
            if (rootFolder != null)
            {
                foreach (var item in rootFolder.Folders.Where(s => s.Name.ToLower() == folderName.ToLower()))
                {
                    return(item.Id.ToString());
                }
            }
            return(null);
        }
        catch
        {
            return(null);
        }

        return(null);
    }
    private string CreateFolderDelegate(string parentFolderId, string childrenFolderId, bool withSubfolders)
    {
        if (string.IsNullOrEmpty(parentFolderId) || string.IsNullOrEmpty(childrenFolderId))
        {
            return(null);
        }

        Folder childrenFolder = folderCard.GetFolder(new Guid(childrenFolderId));

        if (childrenFolder == null)
        {
            return(null);
        }

        // Если папка там уже создана, то ничего не делаем
        string insideFolderId = findFolder(parentFolderId.ToString(), childrenFolder.Name);

        if (insideFolderId != null)
        {
            return(null);
        }

        Folder folderDelegate = folderCard.CreateFolder(new Guid(parentFolderId.ToString()), childrenFolder.Name);

        folderDelegate.Type          = FolderTypes.Delegate;
        folderDelegate.RefId         = new Guid(childrenFolder.Id.ToString());
        folderDelegate.DefaultViewId = childrenFolder.DefaultViewId;
        if (withSubfolders)
        {
            folderDelegate.Flags = FolderFlags.VirtualWithSubfolders;
        }
        return(folderDelegate.Id.ToString());
    }
    private bool setRightsFoFolder(RowData newEmployeeDocsvision, string folderId)
    {
        if (folderId != null)
        {
            CardData    refStaffData = Session.CardManager.GetDictionaryData(RefStaff.ID);
            SectionData unitsSection = refStaffData.Sections[RefStaff.Units.ID];

            //Права
            var accountName = newEmployeeDocsvision.GetString(RefStaff.Employees.AccountName);
            if (string.IsNullOrEmpty(accountName))
            {
                return(false);
            }


            var profileCardId = Session.ProfileManager.GetProfileId(accountName);
            var profileCard   = (UserProfileCard)Session.CardManager.GetCard(profileCardId);
            if (profileCard.DefaultFolderId == new Guid(folderId))
            {
                return(false);
            }

            profileCard.DefaultFolderId = new Guid(folderId);

            var employee = objectContext.GetObject <StaffEmployee>(newEmployeeDocsvision.Id);
            if (employee.PersonalFolder == null)
            {
                return(false);
            }

            var staffService = objectContext.GetService <IStaffService>();
            staffService.SetFoldersRights(employee.PersonalFolder, employee.AccountName);


            //logger.Info("Права на папку созданы.");
            //Ограничения

            FolderCard folderCard = (FolderCard)Session.CardManager.GetDictionary(new Guid("DA86FABF-4DD7-4A86-B6FF-C58C24D12DE2"));

            Folder folder = folderCard.GetFolder(new Guid(folderId.ToString()));
            if ((folder.Restrictions & FolderRestrictions.Types) == 0)
            {
                folder.Restrictions |= FolderRestrictions.Types;
            }


            //logger.Info("Ограничения на папку созданы.");
            //Разрешения

            if ((folder.Restrictions & FolderRestrictions.Types) == 0)
            {
                folder.Restrictions = folder.Restrictions | FolderRestrictions.Types;
                folder.AllowedCardTypes.AddNew(new Guid("6D76D0A7-5434-40F2-912E-6370D33C3151"));
            }
        }
        return(true);
    }