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
Péter Bozsó 2017-08-07 00:15:25 +02:00 committed by Rick Anderson
parent f8ca011f8c
commit 3d79a4b545
1 changed files with 1 additions and 1 deletions

View File

@ -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();