public ActionResult <ItemResponse <Pizzas> > GetById(int id) { ItemResponse <Pizzas> response = null; ActionResult result = null; try { Pizzas pizza = _pizzaService.Get(id); if (pizza == null) { result = NotFound(); } else { response = new ItemResponse <Pizzas>(); response.Item = pizza; result = Ok(response); } } catch (Exception ex) { result = StatusCode(500, new ErrorResponse(ex.Message)); } return(result); }
public async Task <IActionResult> Put([FromRoute] int id, [FromBody] Ingredient ingredient) { if (id == 0 || ingredient == null || ingredient.Id == 0) { return(BadRequest()); } var pizza = await _pizzaService.Get(id); pizza.Ingredients.Add(new PizzaIngredients { IngredientId = ingredient.Id, PizzaId = id }); await _pizzaService.Update(pizza); return(Ok()); }
public async Task <IActionResult> Get(int id) { var pizza = await _pizzaService.Get(id); return(Ok(new { pizza.Id, pizza.Name, Ingredients = pizza.Ingredients.Select(i => new { Id = i.IngredientId, i.Ingredient.Name }) })); }
public IActionResult Get() { var pizzas = pizzaService.Get(); return(Ok(pizzas)); // kod 200 }
public IActionResult Get() { var pizzas = _pizzaService.Get(); return(Ok(pizzas)); }