예제 #1
0
        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);
        }
예제 #2
0
        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());
        }
예제 #3
0
        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
                })
            }));
        }
예제 #4
0
        public IActionResult Get()
        {
            var pizzas = pizzaService.Get();

            return(Ok(pizzas)); // kod 200
        }
예제 #5
0
        public IActionResult Get()
        {
            var pizzas = _pizzaService.Get();

            return(Ok(pizzas));
        }