public async Task <IActionResult> Create(CreateSignServiceUserModel createModel) { if (createModel.Configured) { if (string.IsNullOrWhiteSpace(createModel.KeyVaultUrl)) { ModelState.TryAddModelError(nameof(createModel.KeyVaultUrl), $"{nameof(createModel.KeyVaultUrl)} is required when Configured"); } if (string.IsNullOrWhiteSpace(createModel.KeyVaultUrl)) { ModelState.TryAddModelError(nameof(createModel.TimestampUrl), $"{nameof(createModel.TimestampUrl)} is required when Configured"); } if (string.IsNullOrWhiteSpace(createModel.KeyVaultUrl)) { ModelState.TryAddModelError(nameof(createModel.CertificateName), $"{nameof(createModel.CertificateName)} is required when Configured"); } } if (!ModelState.IsValid) { return(View(createModel)); } try { var res = await adminService.CreateUserAsync(createModel.DisplayName, createModel.Username, createModel.Configured, createModel.KeyVaultUrl, createModel.CertificateName, createModel.TimestampUrl); var user = res.Item1; // create the associated key vault if the vault isn't set if (string.IsNullOrWhiteSpace(user.KeyVaultUrl)) { var vault = await keyVaultAdminService.CreateVaultForUserAsync(user.ObjectId.Value.ToString(), user.UserPrincipalName, user.DisplayName); // Update the vault attribute await adminService.UpdateUserAsync(user.ObjectId.Value, user.DisplayName, user.SignServiceConfigured, vault.VaultUri, user.KeyVaultCertificateName, user.TimestampUrl); user.KeyVaultUrl = vault.VaultUri; } ViewBag.Password = res.Item2; var model = new UserDetailsModel { User = res.Item1 }; return(View(nameof(Details), model)); } catch (Exception e) { ModelState.AddModelError("", e.Message); return(View(createModel)); } }