public IActionResult CreatePizza(CreatePizzaCommand command) { var newPizza = new Pizza { Size = command.Size }; newPizza.Id = _pizzas.Select(p => p.Id).Max() + 1; _pizzas.Add(newPizza); return(Created($"api/pizzas/{newPizza.Id}", newPizza)); }
public IActionResult CreatePizza(CreatePizzaCommand command) { var newPizza = new Pizza { Size = command.Size }; //to set the id to the next id after the greatest id currently on a pizza: //take the pizzas collection > transform it into a collection of just ids > and then use .Max() to give me the biggest id and then add 1 to create the id of the new pizza. newPizza.Id = _pizzas.Select(p => p.Id).Max() + 1; _pizzas.Add(newPizza); return(Created($"api/pizzas/{newPizza.Id}", newPizza)); }