I have a API method on a .net 7.0 API. I have the following method for completing some batch operations and on the return need to rely a number of success/failures;
public async Task<IActionResult> BatchFail([FromBody] JobBatchSignatureModel model)
{
var results = new List<(string JobId, string Message, bool HasError)>();
foreach (var job in model.Jobs)
{
try
{
/*Removed for Brevity*/
results.Add((JobId: job.JobId.ToString(), Message: "Success", HasError: false));
}
catch (Exception ex)
{
results.Add((JobId: job.JobId.ToString(), Message: ex.Message, HasError: true));
}
}
if (results.Any(x => x.HasError == true))
{
return BadRequest(results);
}
else
{
return Ok(results);
}
}
As the output I am expecting is:
[
{
"JobId": "13",
"Message": "User does not match the one trying to start the job (Parameter 'userId')",
"IsError": true
}
]
however I get:
[
{
"Item1": "13",
"Item2": "User does not match the one trying to start the job (Parameter 'userId')",
"Item3": true
}
]
How can I resolve this please without putting concrete classes in place?