public async Task <IActionResult> Put([FromRoute] string providerId, [FromBody] Provider provider)
        {
            if (provider is null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            if (string.IsNullOrWhiteSpace(providerId))
            {
                return(ErrorResult
                       .BadRequest($"The identifier '{providerId}' provided in the url path is invalid.  Must be a valid provider ID.", ResultErrorCode.ValidationError)
                       .ActionResult());
            }

            var validation = new ProviderValidator().Validate(provider);

            if (!validation.IsValid)
            {
                return(ErrorResult
                       .BadRequest(validation)
                       .ActionResult());
            }

            if (!providerId.Equals(provider.Id, StringComparison.OrdinalIgnoreCase))
            {
                return(ErrorResult
                       .BadRequest(new ValidationError {
                    Field = "id", Message = $"Provider's id does match the identifier provided in the path."
                })
                       .ActionResult());
            }

            var oldProvider = await providersRepository
                              .GetAsync(provider.Id)
                              .ConfigureAwait(false);

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

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

            oldProvider.PopulateFromExternalModel(provider);

            var command = new OrchestratorProviderUpdateCommand(currentUserForCommand, oldProvider);

            return(await orchestrator
                   .InvokeAndReturnAccepted(command)
                   .ConfigureAwait(false));
        }
Exemple #2
0
        public async Task <IActionResult> Put([FromBody] Provider provider)
        {
            if (provider is null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            var validation = new ProviderValidator().Validate(provider);

            if (!validation.IsValid)
            {
                return(ErrorResult
                       .BadRequest(validation)
                       .ActionResult());
            }

            var teamCloudInstance = await teamCloudRepository
                                    .GetAsync()
                                    .ConfigureAwait(false);

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

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

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

            var command = new OrchestratorProviderUpdateCommand(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.");
        }
Exemple #3
0
        public async Task <IActionResult> Put([FromBody] Provider provider)
        {
            if (provider is null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            var validation = new ProviderValidator().Validate(provider);

            if (!validation.IsValid)
            {
                return(ErrorResult
                       .BadRequest(validation)
                       .ActionResult());
            }

            var oldProvider = await providersRepository
                              .GetAsync(provider.Id)
                              .ConfigureAwait(false);

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

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

            oldProvider.PopulateFromExternalModel(provider);

            var command = new OrchestratorProviderUpdateCommand(currentUserForCommand, oldProvider);

            return(await orchestrator
                   .InvokeAndReturnAccepted(command)
                   .ConfigureAwait(false));
        }