Exemplo n.º 1
0
        public async Task <IActionResult> Delete(string providerId)
        {
            var provider = await providersRepository
                           .GetAsync(providerId)
                           .ConfigureAwait(false);

            if (provider is null)
            {
                return(ErrorResult
                       .NotFound($"A Provider with the ID '{providerId}' could not be found on this TeamCloud Instance.")
                       .ActionResult());
            }

            var projectTypes = await projectTypesRepository
                               .ListByProviderAsync(providerId)
                               .ToListAsync()
                               .ConfigureAwait(false);

            if (projectTypes.Any())
            {
                return(ErrorResult
                       .BadRequest("Cannot delete Providers referenced in existing ProjectType definitions", ResultErrorCode.ValidationError)
                       .ActionResult());
            }

            var projects = await projectsRepository
                           .ListByProviderAsync(providerId)
                           .ToListAsync()
                           .ConfigureAwait(false);

            if (projects.Any())
            {
                return(ErrorResult
                       .BadRequest("Cannot delete Providers being used by existing Projects", ResultErrorCode.ValidationError)
                       .ActionResult());
            }

            var currentUserForCommand = await userService
                                        .CurrentUserAsync()
                                        .ConfigureAwait(false);

            var command = new OrchestratorProviderDeleteCommand(currentUserForCommand, provider);

            return(await orchestrator
                   .InvokeAndReturnAccepted(command)
                   .ConfigureAwait(false));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Delete(string providerId)
        {
            var teamCloudInstance = await teamCloudRepository
                                    .GetAsync()
                                    .ConfigureAwait(false);

            if (teamCloudInstance is null)
            {
                return(ErrorResult
                       .NotFound($"No TeamCloud Instance was found.")
                       .ActionResult());
            }

            var provider = teamCloudInstance.Providers?.FirstOrDefault(p => p.Id == providerId);

            if (provider is null)
            {
                return(ErrorResult
                       .NotFound($"A Provider with the ID '{providerId}' could not be found on this TeamCloud Instance.")
                       .ActionResult());
            }

            // TODO: Query via the database query instead of getting all
            var projectTypes = await projectTypesRepository
                               .ListAsync()
                               .ToListAsync()
                               .ConfigureAwait(false);

            if (projectTypes.Any(pt => pt.Providers.Any(pr => pr.Id == providerId)))
            {
                return(ErrorResult
                       .BadRequest("Cannot delete Providers referenced in existing ProjectType definitions", ResultErrorCode.ValidationError)
                       .ActionResult());
            }

            // TODO: Query via the database query instead of getting all
            var projects = await projectsRepository
                           .ListAsync()
                           .ToListAsync()
                           .ConfigureAwait(false);

            if (projects.Any(p => p.Type.Providers.Any(pr => pr.Id == providerId)))
            {
                if (projectTypes.Any(pt => pt.Providers.Any(pr => pr.Id == providerId)))
                {
                    return(ErrorResult
                           .BadRequest("Cannot delete Providers being used by existing Projects", ResultErrorCode.ValidationError)
                           .ActionResult());
                }
            }

            var command = new OrchestratorProviderDeleteCommand(CurrentUser, provider);

            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 shoudn't happen, but we need to decide to do when it does.");
        }