intro-to-dotnet-web-dev
intro-to-dotnet-web-dev copied to clipboard
RemovePizza endpoint not working correctly
When calling the RemovePizza endpoint, it's deleting all pizzas EXCEPT for the Id passed to the endpoint. It should be deleting only the pizza that matches the Id. I couldn't find anything obvious, but I'm a noob.
public static void RemovePizza(int id)
{
_pizzas = _pizzas.FindAll(pizza => pizza.Id == id).ToList();
}
In Swagger:
- Tested the Delete method
- Typed in a pizza Id
- Executed
- Then ran the Get method to list all Pizzas
- All pizzas are now gone except for the one matching the Id passed to the DELETE method
If _pizzas
is a List<T>
, why not use List<T>.RemoveAll(Predicate<T>)
instead of the expensing LINQ operator (ToList()
)?