public async Task <IActionResult> Get()
        {
            var teamCloudInstance = await teamCloudRepository
                                    .GetAsync()
                                    .ConfigureAwait(false);

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

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

            var config = new TeamCloudConfiguration
            {
                ProjectTypes = projectTypes,
                Providers    = teamCloudInstance.Providers,
                Users        = teamCloudInstance.Users,
                Tags         = teamCloudInstance.Tags,
                Properties   = teamCloudInstance.Properties,
            };

            return(DataResult <TeamCloudConfiguration>
                   .Ok(config)
                   .ActionResult());
        }
        public async Task <IActionResult> Get()
        {
            var projectTypes = await projectTypesRepository
                               .ListAsync()
                               .ToListAsync()
                               .ConfigureAwait(false);

            return(DataResult <List <ProjectType> >
                   .Ok(projectTypes)
                   .ActionResult());
        }
Esempio n. 3
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.");
        }