public async Task <IActionResult> Post([FromBody] TeamCloudInstance teamCloudInstance) { if (teamCloudInstance is null) { throw new ArgumentNullException(nameof(teamCloudInstance)); } var validation = new TeamCloudInstanceValidaor().Validate(teamCloudInstance); if (!validation.IsValid) { return(ErrorResult .BadRequest(validation) .ActionResult()); } var existingTeamCloudInstance = await teamCloudRepository .GetAsync() .ConfigureAwait(false); if (existingTeamCloudInstance is null) { return(ErrorResult .NotFound("The TeamCloud instance could not be found.") .ActionResult()); } if (existingTeamCloudInstance.ResourceGroup != null || existingTeamCloudInstance.Version != null || (existingTeamCloudInstance.Tags?.Any() ?? false)) { return(ErrorResult .Conflict($"The TeamCloud instance already exists. Call PUT to update the existing instance.") .ActionResult()); } existingTeamCloudInstance.Version = teamCloudInstance.Version; existingTeamCloudInstance.ResourceGroup = teamCloudInstance.ResourceGroup; existingTeamCloudInstance.Tags = teamCloudInstance.Tags; var setResult = await orchestrator .SetAsync(existingTeamCloudInstance) .ConfigureAwait(false); var baseUrl = HttpContext.GetApplicationBaseUrl(); var location = new Uri(baseUrl, $"api/admin/teamCloudInstance").ToString(); var returnSetResult = setResult.PopulateExternalModel(); return(DataResult <TeamCloudInstance> .Created(returnSetResult, location) .ActionResult()); }
public async Task <IActionResult> Put([FromBody] TeamCloudInstance teamCloudInstance) { if (teamCloudInstance is null) { throw new ArgumentNullException(nameof(teamCloudInstance)); } var validation = new TeamCloudInstanceValidaor().Validate(teamCloudInstance); if (!validation.IsValid) { return(ErrorResult .BadRequest(validation) .ActionResult()); } var existingTeamCloudInstance = await teamCloudRepository .GetAsync() .ConfigureAwait(false); if (existingTeamCloudInstance is null) { return(ErrorResult .NotFound("The TeamCloud instance could not be found.") .ActionResult()); } if (!string.IsNullOrEmpty(teamCloudInstance.Version)) { existingTeamCloudInstance.Version = teamCloudInstance.Version; } if (!(teamCloudInstance.ResourceGroup is null)) { existingTeamCloudInstance.ResourceGroup = teamCloudInstance.ResourceGroup; } if (teamCloudInstance.Tags?.Any() ?? false) { existingTeamCloudInstance.MergeTags(teamCloudInstance.Tags); } var setResult = await orchestrator .SetAsync(existingTeamCloudInstance) .ConfigureAwait(false); var returnSetResult = setResult.PopulateExternalModel(); return(DataResult <TeamCloudInstance> .Ok(returnSetResult) .ActionResult()); }