public async Task <IActionResult> Delete(string projectNameOrId) { if (string.IsNullOrWhiteSpace(projectNameOrId)) { return(ErrorResult .BadRequest($"The identifier '{projectNameOrId}' provided in the url path is invalid. Must be a valid project name or GUID.", ResultErrorCode.ValidationError) .ActionResult()); } var project = await projectsRepository .GetAsync(projectNameOrId) .ConfigureAwait(false); if (project is null) { return(ErrorResult .NotFound($"A Project with the identifier '{projectNameOrId}' could not be found in this TeamCloud Instance") .ActionResult()); } var currentUserForCommand = await userService .CurrentUserAsync() .ConfigureAwait(false); var command = new OrchestratorProjectDeleteCommand(currentUserForCommand, project); return(await orchestrator .InvokeAndReturnAccepted(command) .ConfigureAwait(false)); }
public Task <IActionResult> Delete([FromRoute] string projectNameOrId) => EnsureProjectAsync(async project => { var currentUser = await UserService .CurrentUserAsync() .ConfigureAwait(false); var command = new OrchestratorProjectDeleteCommand(currentUser, project); return(await Orchestrator .InvokeAndReturnActionResultAsync <ProjectDocument, Project>(command, Request) .ConfigureAwait(false)); });
private static async Task RollbackAsync(IDurableOrchestrationContext functionContext, OrchestratorProjectCreateCommand command) { var systemUser = await functionContext .CallActivityWithRetryAsync <User>(nameof(TeamCloudUserActivity), null) .ConfigureAwait(true); var deleteCommand = new OrchestratorProjectDeleteCommand(systemUser, command.Payload); var deleteCommandMessage = new OrchestratorCommandMessage(deleteCommand); functionContext .StartNewOrchestration(nameof(OrchestratorProjectDeleteCommandOrchestration), deleteCommandMessage); }
public async Task <IActionResult> Delete(string projectNameOrId) { if (string.IsNullOrWhiteSpace(projectNameOrId)) { return(ErrorResult .BadRequest($"The identifier '{projectNameOrId}' provided in the url path is invalid. Must be a valid project name or GUID.", ResultErrorCode.ValidationError) .ActionResult()); } Project project; if (Guid.TryParse(projectNameOrId, out var projectId)) { project = await projectsRepository .GetAsync(projectId) .ConfigureAwait(false); } else { project = await projectsRepository .GetAsync(projectNameOrId) .ConfigureAwait(false); } if (project is null) { return(ErrorResult .NotFound($"A Project with the identifier '{projectNameOrId}' could not be found in this TeamCloud Instance") .ActionResult()); } var command = new OrchestratorProjectDeleteCommand(CurrentUser, project); var commandResult = await orchestrator .InvokeAsync(command) .ConfigureAwait(false); if (commandResult.Links.TryGetValue("status", out var statusUrl)) { return(StatusResult .Accepted(commandResult.CommandId.ToString(), statusUrl, commandResult.RuntimeStatus.ToString(), commandResult.CustomStatus) .ActionResult()); } throw new Exception("This shouldn't happen, but we need to decide to do when it does."); }
private static async Task RollbackAsync(IDurableOrchestrationContext functionContext, OrchestratorProjectCreateCommand command, ILogger log) { functionContext.SetCustomStatus($"Refreshing project", log); var project = (await functionContext .GetProjectAsync(command.ProjectId, allowUnsafe: true) .ConfigureAwait(true)) ?? command.Payload; functionContext.SetCustomStatus($"Rolling back project", log); var systemUser = await functionContext .CallActivityWithRetryAsync <UserDocument>(nameof(TeamCloudSystemUserActivity), null) .ConfigureAwait(true); var deleteCommand = new OrchestratorProjectDeleteCommand(systemUser, project); await functionContext .CallSubOrchestratorWithRetryAsync(nameof(OrchestratorProjectDeleteCommandOrchestration), deleteCommand) .ConfigureAwait(true); }