public async Task <IActionResult> Post([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 existingProvider = await providersRepository .GetAsync(provider.Id) .ConfigureAwait(false); if (existingProvider != null) { return(ErrorResult .Conflict($"A Provider with the ID '{provider.Id}' already exists on this TeamCloud Instance. Please try your request again with a unique ID or call PUT to update the existing Provider.") .ActionResult()); } var currentUserForCommand = await userService .CurrentUserAsync() .ConfigureAwait(false); var commandProvider = new TeamCloud.Model.Internal.Data.Provider(); commandProvider.PopulateFromExternalModel(provider); var command = new OrchestratorProviderCreateCommand(currentUserForCommand, commandProvider); return(await orchestrator .InvokeAndReturnAccepted(command) .ConfigureAwait(false)); }
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)); }