I'm attempting to create an endpoint (POST) that accepts 1 or more models which will then be bulk inserted into the DB.
Everything is fine except when I attempt to call CreatedAtRoute
with lists of the created objects and routes.
When I call CreatedAtRoute
with multiple routes/models I get a runtime InvalidOperationException
, no matching routes.
Example
[HttpPost]
public async Task<ActionResult<IEnumerable<QaiStateModel>>> CreateQaiStateAsync(
IEnumerable<QaiStateCreationModel> inputQaiStates )
{
var qaiStates = _mapper.Map<IEnumerable<QaiState>>( inputQaiStates );
await _qaiService.AddQaiStatesAsync( qaiState ).ConfigureAwait( false );
var models = _mapper.Map<List<QaiStateModel>>( qaiState );
var ids = models.Select( m => new { qaiStateID = m.ID } );
return CreatedAtRoute( "GetQaiState", ids, models );
}
For reference I do have the following GET/{ID}
endpoint:
[HttpGet( "{qaiStateID}", Name = "GetQaiState" )]
public async Task<ActionResult<QaiStateModel>> GetQaiStateAsync( int qaiStateID )
Question
Is it possible to return both URI
's to access the newly added resources as well as a list of the model representation of those resources?
I'm also unsure if this is the correct way to handle this situation (in regards to what I should be returning).
Change
CreatedAtRoute
like below:Change
GetQaiStateAsync
method like below: