Fix DELETE operation in TodoController (#3898)
By using First(), there's the opportunity for an uncaught exception when the endpoint is called with an ID not present in the database.pull/3881/head^2
parent
f8ca011f8c
commit
3d79a4b545
|
@ -85,7 +85,7 @@ namespace TodoApi.Controllers
|
|||
[HttpDelete("{id}")]
|
||||
public IActionResult Delete(long id)
|
||||
{
|
||||
var todo = _context.TodoItems.First(t => t.Id == id);
|
||||
var todo = _context.TodoItems.FirstOrDefault(t => t.Id == id);
|
||||
if (todo == null)
|
||||
{
|
||||
return NotFound();
|
||||
|
|
Loading…
Reference in New Issue