public async Task <Guid?> CreateDeployment(
            DeploymentCreation deployment,
            Uri storageUri,
            ClaimsPrincipal user,
            CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var doc = await this.RetrieveDatasetDocument(deployment.DatasetId, cancellationToken);

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

            var userId = GetUserId(user);

            if (!userId.HasValue)
            {
                throw new InvalidOperationException("Invalid user information.");
            }
            var name  = GetUserName(user);
            var email = GetUserEmail(user);

            var options = new RequestOptions
            {
                PartitionKey = new PartitionKey(deployment.DatasetId.ToString())
            };
            var uri    = this.UserDataDocumentCollectionUri;
            var record = new DeploymentStorage
            {
                Id           = Guid.NewGuid(),
                DatasetId    = deployment.DatasetId,
                DeploymentId = deployment.DeploymentId,
                StorageUri   = storageUri.ToString(),
                UserId       = userId.Value,
                UserEmail    = email,
                UserName     = name,
            };

            await this.Client.UpsertDocumentAsync(uri, record, options).ConfigureAwait(false);

            return(record.Id);
        }
        public async Task <IActionResult> CreateDeployment([FromBody] DeploymentCreation deployment, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var storageUri = await this.DatasetStorage.GetDownloadUriAsync(deployment.DatasetId, cancellationToken).ConfigureAwait(false);

            if (storageUri == null)
            {
                return(this.NotFound());
            }

            var deploymentId = await this.UserStorage.CreateDeployment(deployment, storageUri, User, cancellationToken).ConfigureAwait(false);

            if (deploymentId == null)
            {
                return(this.NotFound());
            }

            var templateUrl = $"{WebServerConfiguration.URL}azure-deploy/{deployment.DatasetId}/{deploymentId}/azuredeploy.json";
            var importUrl   = WebServerConfiguration.AzureImportURL;

            return(Json($"{importUrl}{Uri.EscapeDataString(templateUrl)}"));
        }