public async Task <IActionResult> CreateWizardPage(WizardPageResource wizardPageResource) { if (wizardPageResource == null) { ProblemDetails problem = new ProblemDetails { Title = "Failed creating the wizard page.", Detail = "The wizard page resource is null.", Instance = "9EDA7F00-BA1E-4DD2-808D-093853FC5534" }; return(BadRequest(problem)); } WizardPage wizardPage = mapper.Map <WizardPageResource, WizardPage>(wizardPageResource); try { await wizardPageService.AddAsync(wizardPage); wizardPageService.Save(); WizardPageResourceResult createdPage = mapper.Map <WizardPage, WizardPageResourceResult>(wizardPage); return(Created(nameof(CreateWizardPage), createdPage)); } catch (DbUpdateException e) { Log.Logger.Error(e, "Database exception"); ProblemDetails problem = new ProblemDetails { Title = "Failed saving wizard page.", Detail = "Failed saving the wizard page to the database.", Instance = "09BCA75E-7615-4E30-9379-61A0C9DC05B8" }; return(BadRequest(problem)); } }
public async Task <IActionResult> UpdatedWizardPage(int id, [FromBody] WizardPageResource wizardPageResource) { if (id <= 0) { ProblemDetails problem = new ProblemDetails { Title = "Invalid id specified.", Detail = "The specified id is invalid.", Instance = "EC827999-28A5-42EF-A160-F8729F26DB13" }; return(BadRequest(problem)); } WizardPage wizardPage = await wizardPageService.FindAsync(id); if (wizardPage == null) { ProblemDetails problem = new ProblemDetails { Title = "Failed getting the wizard page.", Detail = "The database does not contain a wizard page with the specified id.", Instance = "ED11431F-AE28-43EE-A1E4-780354217A1E" }; return(NotFound(problem)); } mapper.Map(wizardPageResource, wizardPage); wizardPageService.Update(wizardPage); wizardPageService.Save(); WizardPageResourceResult model = mapper.Map <WizardPage, WizardPageResourceResult>(wizardPage); return(Ok(model)); }