intro-to-dotnet-web-dev icon indicating copy to clipboard operation
intro-to-dotnet-web-dev copied to clipboard

RemovePizza endpoint not working correctly

Open SeriesOfTubez opened this issue 2 years ago • 1 comments

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

SeriesOfTubez avatar Aug 28 '22 17:08 SeriesOfTubez

If _pizzas is a List<T>, why not use List<T>.RemoveAll(Predicate<T>) instead of the expensing LINQ operator (ToList())?

paulomorgado avatar Aug 28 '22 20:08 paulomorgado