When I do a HTTPGet[By ID], I want it to return an error code of Not Found if the ID is not found in the database however I am getting this code 200 and the response value of "{}".
What am I doing wrong?
[HttpGet("{SessionID}")]
[ProducesResponseType(typeof(CaseInformation), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<ActionResult<List<CaseInformation>>> GetCaseInformationByID(string SessionID)
{
using var connection = new SqlConnection(_config.GetConnectionString("SQlServer"));
var caseInfo = await connection.QueryAsync<CaseInformation>("GetCaseInformationByIDSP", new { SessionID = SessionID }, commandType: CommandType.StoredProcedure);
return caseInfo == null ? NotFound() : Ok(caseInfo);
}
2条答案
按热度按时间b4qexyjb1#
You are checking
caseInfo
is null or not.caseInfo
is not null even when the ID is not found in the database. You need to check whether thecaseInfo
list is empty or not.nimxete22#