private async Task <DocumentUpdateResultDto> CreateDocumentByPartitionAsync <T>(T document, string paritionKey) where T : AuditedDocumentBase, new()
        {
            if (!string.IsNullOrEmpty(document.GroupId) && document.GroupId != GetGroupId())
            {
                throw new UnauthorizedAccessException("GroupId context mismatch.");
            }

            document.PartitionKey  = paritionKey;
            document.GroupId       = GetGroupId();
            document.CreatedById   = document.UpdatedById = _requestContext.UserId;
            document.CreatedByName = document.UpdatedByName = _requestContext.UserDisplayName;
            document.CreatedOnUtc  = document.UpdatedOnUtc = DateTime.UtcNow;

            var result = await _documentDbService.CreateDocumentAsync(_collectionId, document.PartitionKey, document);

            //Update the in-memory object with the id and etag generated from the db.
            document.Id   = result.Id;
            document.ETag = result.ETag;

            result.UpdatedById   = document.UpdatedById;
            result.UpdatedByName = document.UpdatedByName;
            result.UpdatedOnUtc  = document.UpdatedOnUtc;

            return(result);
        }
        public virtual async Task InsertEventAsync <T>(T document, string partitionKey) where T : EventDocumentBase, new()
        {
            if (!string.IsNullOrEmpty(document.GroupId) && document.GroupId != GetGroupId())
            {
                throw new UnauthorizedAccessException("GroupId context mismatch.");
            }

            document.PartitionKey = partitionKey;
            document.GroupId      = GetGroupId();

            var result = await _documentDbService.CreateDocumentAsync(_collectionId, document.PartitionKey, document);

            //Update the in-memory object with the id generated from the db.
            document.Id = result.Id;
        }