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); } }