Skip to content

Commit

Permalink
Fix: Update not checking whether an item exists.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaliyaudagedara committed Jun 3, 2022
1 parent c0ddeb0 commit 3efbce4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Todo.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
// Map endpoint to update ToDo
app.MapPut("/Todos/{id}", async (ToDoDbContext dbContext, int id, ToDo toDo) =>
{
if (await dbContext.ToDos.FindAsync(id) == null)
{
return Results.NotFound();
}

toDo.Id = id;
dbContext.ToDos.Update(toDo);

Expand Down

0 comments on commit 3efbce4

Please sign in to comment.