public async Task <string> OpenLimitedAccess(string documentId, ClaimsPrincipal owner, string guestEmail)
        {
            string ownerId = _userRepo.GetUserId(owner);

            if (!(await _documentRepo.IsUserDocumentOwner(documentId, ownerId)))
            {
                throw new UnauthorizedAccessException($"The user {ownerId} is not the owner of the document");
            }

            var document = await _documentRepo.GetDocumentByIdAsync(documentId);

            if (!document.IsPublic)
            {
                var userDocumentLink = Guid.NewGuid().ToString();
                var user             = await _userRepo.GetUserByNameAsync(guestEmail);

                if (ownerId == user.Id)
                {
                    return(null);
                }

                await _userDocumentRepo.AddUserDocumentAsync(user.Id, documentId, userDocumentLink);

                return(userDocumentLink);
            }

            return(document.DocumentLink);
        }
        public async Task CreateDocumentRelatedAsync(IFormFileCollection uploadedFile, ClaimsPrincipal owner, string parentId, string fdName = null)
        {
            string storagePath      = Path.Combine(_pProvider.ContentPath());
            string combinedFilePath = "";
            string ownerId          = _userRepo.GetUserId(owner);

            if (uploadedFile != null)
            {
                foreach (var file in uploadedFile)
                {
                    if (_documentRepo.GetDocumentByIdAsync(parentId).Result.Length <= _userRepo.GetUserByIdAsync(ownerId).Result.StorageSize)
                    {
                        string docId = Guid.NewGuid().ToString();
                        foreach (var str in GetPathPartsBypId(parentId))
                        {
                            combinedFilePath += str + "\\";
                        }
                        combinedFilePath.Substring(combinedFilePath.Length - 2);
                        var filePath = Path.Combine(storagePath, combinedFilePath, docId);
                        var doc      = new DocumentEntity
                        {
                            Name       = file.FileName,
                            Length     = file.Length,
                            IsFile     = true,
                            DocumentId = docId,
                            OwnerId    = ownerId,
                            ParentId   = parentId,
                            Path       = filePath,
                            ChangeDate = DateTime.Now
                        };

                        await _documentRepo.CreateDocumentAsync(doc);

                        await _userDocumentRepo.AddUserDocumentAsync(ownerId, docId);

                        await _pProvider.CreateFile(file, Path.Combine(storagePath, _userRepo.GetUserId(owner), docId));
                        await UpdateFolderLength(doc.ParentId);
                    }
                }
            }
            else if (fdName != null)
            {
                string docId = Guid.NewGuid().ToString();
                foreach (var str in GetPathPartsBypId(parentId))
                {
                    combinedFilePath += str + "\\";
                }
                combinedFilePath.Substring(combinedFilePath.Length - 2);
                var filePath = Path.Combine(storagePath, combinedFilePath, docId);
                var doc      = new DocumentEntity
                {
                    Name       = fdName,
                    Length     = 0,
                    IsFile     = false,
                    DocumentId = docId,
                    OwnerId    = ownerId,
                    ParentId   = parentId,
                    Path       = filePath,
                    ChangeDate = DateTime.Now
                };

                await _documentRepo.CreateDocumentAsync(doc);

                await _userDocumentRepo.AddUserDocumentAsync(ownerId, docId);
            }
        }