Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("Id,BestellingId,GerechtId,Aantal,Opmerkingen")] BesteldGerecht besteldGerecht)
        {
            if (ModelState.IsValid)
            {
                _context.Add(besteldGerecht);
                await _context.SaveChangesAsync();

                // Terug naar de bestelling waarvan dit bestelde gerecht deel uitmaakt.
                return(RedirectToAction(
                           nameof(BestellingController.Edit),
                           nameof(BestellingController).Replace("Controller", ""),
                           new { id = besteldGerecht.BestellingId }));
            }
            else
            {
                ViewData["BestellingId"] = new SelectList(
                    _context.Bestellingen,
                    nameof(Bestelling.Id),
                    nameof(Bestelling.Id),
                    besteldGerecht.BestellingId);
                ViewData["GerechtId"] = new SelectList(
                    FilterEnSorteerGerechten(besteldGerecht.BestellingId, null).Select(g => new
                {
                    Id = g.Id,
                    SamengesteldeNaam = $"{g.Categorie} - {g.Naam}"
                }),
                    "Id",
                    "SamengesteldNaam",
                    besteldGerecht.GerechtId);
                return(View(besteldGerecht));
            }
        }
Esempio n. 2
0
        // GET: BesteldGerecht/Create
        public IActionResult Create(int bestellingId)
        {
            ViewData["BestellingId"] = new SelectList(
                _context.Bestellingen,
                nameof(Bestelling.Id),
                nameof(Bestelling.Id));
            ViewData["GerechtId"] = new SelectList(
                FilterEnSorteerGerechten(bestellingId, null).Select(g => new
            {
                Id = g.Id,
                SamengesteldeNaam = $"{g.Categorie} - {g.Naam}"
            }),
                "Id",
                "SamengesteldeNaam");

            // BestelGerecht object met 'defaults'
            BesteldGerecht bg = new BesteldGerecht()
            {
                BestellingId = bestellingId,
                Bestelling   = _context.Bestellingen.First(b => b.Id == bestellingId),
                Aantal       = 1
            };

            return(View(bg));
        }
Esempio n. 3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,BestellingId,GerechtId,Aantal,Opmerkingen")] BesteldGerecht besteldGerecht)
        {
            if (id != besteldGerecht.Id)
            {
                return(NotFound());
            }

            ControleerWijzigbaarheid(besteldGerecht);

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(besteldGerecht);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BesteldGerechtExists(besteldGerecht.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                // Terug naar de bestelling waarvan dit bestelde gerecht deel uitmaakt.
                return(RedirectToAction(
                           nameof(BestellingController.Edit),
                           nameof(BestellingController).Replace("Controller", ""),
                           new { id = besteldGerecht.BestellingId }));
            }
            else
            {
                ViewData["BestellingId"] = new SelectList(
                    _context.Bestellingen,
                    "Id",
                    "Id",
                    besteldGerecht.BestellingId);
                ViewData["GerechtId"] = new SelectList(
                    FilterEnSorteerGerechten(besteldGerecht.BestellingId, besteldGerecht.GerechtId).Select(g => new
                {
                    Id = g.Id,
                    SamengesteldeNaam = $"{g.Categorie} - {g.Naam}"
                }),
                    "Id",
                    "SamengesteldeNaam",
                    besteldGerecht.GerechtId);

                // Terug naar de bestelling waarvan dit bestelde gerecht deel uitmaakt.
                return(View(besteldGerecht));
            }
        }
Esempio n. 4
0
        private void ControleerWijzigbaarheid(BesteldGerecht besteldGerecht)
        {
            // Een (eventuele) vorige versie van de bestelling ophalen.
            Bestelling bestelling = _context.Bestellingen
                                    .AsNoTracking()
                                    .FirstOrDefault(b => b.Id == besteldGerecht.BestellingId);

            if (bestelling.Tijdslot != null && bestelling.Tijdslot.Value < DateTime.Now.AddHours(1))
            {
                ModelState.AddModelError(nameof(Bestelling.Tijdslot), $"De bestelling kan niet meer gewijzigd worden.");
            }
        }