Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] What would be a good way to return CreatedAtAction 201 result? #99

Closed
philipp985 opened this issue Aug 18, 2022 · 2 comments
Closed

Comments

@philipp985
Copy link

Hello,
thank you for the good library and good ideas from concepts!

What would be an elegant / good way to solve this problem. I could not find anything in the calculation.

[HttpPost]
[ProducesResponseType(StatusCodes.Status201Created)]
public async Task<ActionResult<InventoryInspectionDoneDTO>> Create([FromBody] InventoryInspectionDoneCreateDTO dto)
{
       var resp = (await _inventoryInspectionsDoneService.CreateAsync(dto)).Map(x => 
       _mapper.Map<InventoryInspectionDoneDTO>(x));
       if (resp.IsSuccess)
          {
              return CreatedAtAction(nameof(GetById), new { id = resp.Value.Id }, resp.Value);
          }

   return this.ToActionResult(resp);
}

One idea would be write a custom extension but maybe there is chance to include it in this library.

Thanks for any ideas!

@ardalis
Copy link
Owner

ardalis commented Jan 31, 2023

I think some of what is in this PR could be applied: #92.

@ardalis
Copy link
Owner

ardalis commented May 16, 2024

We now have a Created result.

@ardalis ardalis closed this as completed May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants