コード例 #1
0
        public async Task <IActionResult> Delete(Guid userId)
        {
            if (!ProjectId.HasValue)
            {
                return(new NotFoundResult());
            }

            var project = await projectsRepository
                          .GetAsync(ProjectId.Value)
                          .ConfigureAwait(false);

            var user = project?.Users?.FirstOrDefault(u => u.Id == userId);

            if (user is null)
            {
                return(new NotFoundResult());
            }

            var command = new ProjectUserDeleteCommand(currentUser, user, ProjectId.Value);

            var commandResult = await orchestrator
                                .InvokeAsync <Project>(command)
                                .ConfigureAwait(false);

            if (commandResult.Links.TryGetValue("status", out var statusUrl))
            {
                return(new AcceptedResult(statusUrl, commandResult));
            }
            else
            {
                return(new OkObjectResult(commandResult));
            }
        }
コード例 #2
0
    public async Task <ICommandResult> HandleAsync(ProjectUserDeleteCommand command, IAsyncCollector <ICommand> commandQueue, IDurableOrchestrationContext orchestrationContext, ILogger log)
    {
        if (command is null)
        {
            throw new ArgumentNullException(nameof(command));
        }

        if (commandQueue is null)
        {
            throw new ArgumentNullException(nameof(commandQueue));
        }

        var commandResult = command.CreateResult();

        try
        {
            commandResult.Result = await userRepository
                                   .RemoveAsync(command.Payload)
                                   .ConfigureAwait(false);

            commandResult.RuntimeStatus = CommandRuntimeStatus.Completed;
        }
        catch (Exception exc)
        {
            commandResult.Errors.Add(exc);
        }
        finally
        {
            await UpdateComponentsAsync(command.User, command.ProjectId, commandQueue)
            .ConfigureAwait(false);
        }

        return(commandResult);
    }