fix min web API todo /2 (#23820)
* fix min web API todo /2 * fix min web API todo /2pull/23821/head
parent
dc0bb05c3e
commit
243d9a82dc
|
@ -419,7 +419,7 @@ A DTO may be used to:
|
|||
|
||||
To demonstrate the DTO approach, update the `Todo` class to include a secret field:
|
||||
|
||||
[!code-csharp[](min-web-api/samples/6.x/todoDTO/Program.cs?name=snippet_secret&highlight=7)]
|
||||
[!code-csharp[](min-web-api/samples/6.x/todoDTO/Program.cs?name=snippet_secret&highlight=6)]
|
||||
|
||||
The secret field needs to be hidden from this app, but an administrative app could choose to expose it.
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ app.MapPost("/todoitems", async (TodoItemDTO todoItemDTO, TodoDb db) =>
|
|||
db.Todos.Add(todoItem);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
return Results.Created($"/todoitems/{todoItem.Id}", todoItem);
|
||||
return Results.Created($"/todoitems/{todoItem.Id}", new TodoItemDTO(todoItem));
|
||||
});
|
||||
|
||||
#region snippet_put
|
||||
|
@ -53,7 +53,7 @@ app.MapDelete("/todoitems/{id}", async (int id, TodoDb db) =>
|
|||
{
|
||||
db.Todos.Remove(todo);
|
||||
await db.SaveChangesAsync();
|
||||
return Results.Ok(todo);
|
||||
return Results.Ok(new TodoItemDTO(todo));
|
||||
}
|
||||
|
||||
return Results.NotFound();
|
||||
|
@ -74,6 +74,7 @@ public class Todo
|
|||
#region snippet_DTO
|
||||
public class TodoItemDTO
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public bool IsComplete { get; set; }
|
||||
|
||||
|
|
Loading…
Reference in New Issue