Пример #1
0
        public async Task <IActionResult> Create(int[] Allergenen, [Bind("Id,Naam,Beschrijving,Prijs,CategoryId")] Consumptie consumptie)
        {
            List <ConsumptieAllergenen> lijst = new List <ConsumptieAllergenen>();

            foreach (var item in Allergenen)
            {
                ConsumptieAllergenen Consaller = new ConsumptieAllergenen();
                Consaller.AllergenenId = item;
                Consaller.ConsumptieId = consumptie.Id;
                lijst.Add(Consaller);
            }

            consumptie.ConsumptieAllergenen = lijst;

            if (ModelState.IsValid)
            {
                _context.Add(consumptie);
                Console.WriteLine("MENU ID : " + consumptie.Id);

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            //ViewData["ConsumptieId"] = new SelectList(_context.Consumpties, "Id", "Id", consumptieMenu.ConsumptieId);
            //ViewData["MenuId"] = new SelectList(_context.Menus, "Id", "Id", consumptieMenu.MenuId);
            return(View(consumptie));
        }
Пример #2
0
        public static async Task KoppelAllergeen(ApplicationDbContext _context)
        {
            List <ConsumptieAllergenen> lijst     = new List <ConsumptieAllergenen>();
            ConsumptieAllergenen        Consaller = new ConsumptieAllergenen();

            Consaller.AllergenenId = 4;
            Consaller.ConsumptieId = 1;
            //aller.Allergenen = _context.Allergenen.FirstOrDefault();
            //aller.Consumptie = _context.Consumpties.FirstOrDefault();
            lijst.Add(Consaller);

            Consumptie cons = new Consumptie();

            cons.Naam = "Spaghetti";
            cons.ConsumptieAllergenen = lijst;
            cons.Beschrijving         = "Spaghetti Bolgnese";
            cons.Prijs      = 6.50;
            cons.CategoryId = 4;
            _context.AddRange(cons);
            _context.SaveChanges();
        }