Exemplo n.º 1
0
        public async Task <IActionResult> AddIngredient(GerechtIngredient gerechtIngredient)
        {
            if (ModelState.IsValid)
            {
                var existingGerechtIngredient =
                    await _context.GerechtIngredienten.FindAsync(
                        gerechtIngredient.GerechtId,
                        gerechtIngredient.IngredientId);

                if (existingGerechtIngredient != null)
                {
                    existingGerechtIngredient.Aantal += gerechtIngredient.Aantal;
                    _context.Update(existingGerechtIngredient);
                    await _context.SaveChangesAsync();
                }
                else
                {
                    _context.Add(gerechtIngredient);
                    await _context.SaveChangesAsync();
                }
                return(RedirectToAction(nameof(Edit), new { id = gerechtIngredient.GerechtId }));
            }
            ViewData["IngredientId"] = new SelectList(_context.Ingredienten, "Id", "DataTextField", gerechtIngredient.IngredientId);

            return(View(gerechtIngredient));
        }
Exemplo n.º 2
0
        // De rest van ingredienten toevoegen GET: gerechten/ingredients

        public async Task <IActionResult> AddIngredient(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var gerecht = await _context.Gerechten.FindAsync(id);

            if (gerecht == null)
            {
                return(NotFound());
            }

            var gerechtIngredient = new GerechtIngredient {
                GerechtId = gerecht.Id, IngredientId = 0
            };

            ViewData["IngredientId"] = new SelectList(_context.Ingredienten, "Id", "DataTextField", gerechtIngredient.IngredientId);

            return(View(gerechtIngredient));
        }