public async Task <IActionResult> UpdateCallToActionOption(int callToActionId, [FromBody] CallToActionOptionResource callToActionOptionResource) { CallToActionOption option = await callToActionOptionService.FindAsync(callToActionId); if (option == null) { ProblemDetails problem = new ProblemDetails { Title = "Failed getting the call to action option.", Detail = "The database does not contain a call to action option with that id.", Instance = "A939D6FA-4B85-4D3F-B3CC-86658713D76C" }; return(NotFound(problem)); } mapper.Map(callToActionOptionResource, option); if ((await callToActionOptionService.GetCallToActionOptionsFromTypeAsync(option.Type)).Any() && (await callToActionOptionService.GetCallToActionOptionFromValueAsync(option.Value)).Any()) { ProblemDetails problem = new ProblemDetails { Title = "Failed creating the call to action option.", Detail = "Identical call to action option already exists.", Instance = "1DA7B168-FAD1-41B6-A90F-3AAEB26147CE" }; return(BadRequest(problem)); } callToActionOptionService.Update(option); callToActionOptionService.Save(); return(Ok(mapper.Map <CallToActionOption, CallToActionOptionResourceResult>(option))); }
public async Task <IActionResult> CreateCallToActionOption(CallToActionOptionResource callToActionOptionResource) { if (callToActionOptionResource == null) { ProblemDetails problem = new ProblemDetails { Title = "Failed creating the call to action option.", Detail = "The institution resource is null.", Instance = "E2FD8F7B-96B1-4406-9E90-138AA36B570B" }; return(BadRequest(problem)); } CallToActionOption option = mapper.Map <CallToActionOptionResource, CallToActionOption>(callToActionOptionResource); if ((await callToActionOptionService.GetCallToActionOptionsFromTypeAsync(option.Type)).Any() && (await callToActionOptionService.GetCallToActionOptionFromValueAsync(option.Value)).Any()) { ProblemDetails problem = new ProblemDetails { Title = "Failed creating the call to action option.", Detail = "Identical call to action option already exists.", Instance = "1DA7B168-FAD1-41B6-A90F-3AAEB26147CE" }; return(BadRequest(problem)); } try { callToActionOptionService.Add(option); callToActionOptionService.Save(); CallToActionOptionResourceResult model = mapper.Map <CallToActionOption, CallToActionOptionResourceResult>(option); return(Created(nameof(CreateCallToActionOption), model)); } catch (DbUpdateException) { Log.Logger.Error("Database exception"); ProblemDetails problem = new ProblemDetails { Title = "Failed Saving the call to action option.", Detail = "Failed saving the call to action option to the database.", Instance = "5A1D2B14-E320-4FAE-84DF-BC02B996588B" }; return(BadRequest(problem)); } }