public async Task <IActionResult> Edit(int id, [Bind("BestellingID,Artikel,Prijs,KlantID")] CreateBestellingViewModel viewModel) { if (id != viewModel.Bestelling.BestellingID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(viewModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BestellingExists(viewModel.Bestelling.BestellingID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } viewModel.Klanten = new SelectList(_context.Klanten, "KlantID", "Naam", viewModel.Bestelling.KlantID); return(View(viewModel)); }
// GET: Bestelling/Create public IActionResult Create() { var viewModel = new CreateBestellingViewModel(); viewModel.Bestelling = new Bestelling(); viewModel.Klanten = new SelectList(_context.Klanten, "KlantID", "Naam"); return(View(viewModel)); }
public async Task <IActionResult> Create(CreateBestellingViewModel viewModel) { if (ModelState.IsValid) { _context.Add(viewModel.Bestelling); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } viewModel.Klanten = new SelectList(_context.Klanten, "KlantID", "Naam", viewModel.Bestelling.KlantID); return(View(viewModel)); }
// GET: Bestelling/Create public IActionResult Create() { CreateBestellingViewModel viewModel = new CreateBestellingViewModel(); //viewModel.Persoon = _context.Personen.Find(id); //Hoe kan ik hier de ingelogde id vinden viewModel.Bestelling = new Bestelling(); viewModel.Bestelling.Datum = DateTime.Now.Date; viewModel.Productenlijst = _context.Producten.Include(x => x.ProductType).ToList(); //ViewData["PersoonID"] = new SelectList(_context.Personen, "Persoon_ID", "Achternaam"); return(View(viewModel)); }
public async Task <IActionResult> Create(CreateBestellingViewModel viewModel) { if (ModelState.IsValid) { _context.Add(viewModel.Bestelling); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } //viewModel.Persoon = _context.Personen.Find(id);// hoe kan ik hier de ingelogde id vinden viewModel.Bestelling = new Bestelling(); viewModel.Bestelling.Datum = DateTime.Now.Date; viewModel.Productenlijst = _context.Producten.Include(x => x.ProductType).ToList(); return(View(viewModel)); }
// GET: Bestelling/Edit/5 public async Task <IActionResult> Edit(int?id, CreateBestellingViewModel viewModel) { if (id == null) { return(NotFound()); } viewModel.Bestelling = await _context.Bestellingen.FindAsync(id); if (viewModel.Bestelling == null) { return(NotFound()); } viewModel.Klanten = new SelectList(_context.Klanten, "KlantID", "Naam"); return(View(viewModel)); }