Exemplo n.º 1
0
        public IActionResult Create([FromForm] Product newProduct)
        {
            newProduct.Energy *= 10;

            _ctx.Add(newProduct);
            _ctx.SaveChanges();

            var model = _ctx.Products.ToList();

            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 2
0
        public IActionResult DeleteIngredient(int modelId, int ingedientId)
        {
            var model = _ctx.Recipes
                        .Where(r => r.Id == modelId)
                        .Include(r => r.Ingredients)
                        .ThenInclude(i => i.Product)
                        .FirstOrDefault();

            var ingredientToRemove = model.Ingredients.FirstOrDefault(i => i.Id == ingedientId);

            model.Ingredients.Remove(ingredientToRemove);
            _ctx.Remove(ingredientToRemove);

            _ctx.Recipes.Update(model);
            _ctx.SaveChanges();

            return(RedirectToAction(nameof(Edit), new { id = modelId }));
        }