public async Task <IActionResult> Edit(int id, [Bind("ShoppingbagID,Date,TotalPrice,CustomerID,Closed")] Shoppingbag shoppingbag) { if (id != shoppingbag.ShoppingbagID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(shoppingbag); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ShoppingbagExists(shoppingbag.ShoppingbagID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CustomerID"] = new SelectList(_context.Customers, "CustomerID", "FullName", shoppingbag.CustomerID); return(View(shoppingbag)); }
//GET: Products/Verkoop public async Task <IActionResult> Verkoop(int?id) { if (id != null) { var customer = await _context.Customers.Include(c => c.Bags).Where(c => c.CustomerID == id).FirstOrDefaultAsync(); Shoppingbag bag; if (customer.Bags.Count == 0) { bag = new Shoppingbag() { Date = DateTime.Now, Customer = customer, CustomerID = customer.CustomerID }; _context.Add(bag); await _context.SaveChangesAsync(); //customer.Bags.Add(bag); } else { bag = customer.Bags.FirstOrDefault(b => b.Closed == false); } ViewData["Customer"] = customer; ViewData["Shoppingbag"] = bag; } return(View(await _context.Products.ToListAsync())); }
public async Task <IActionResult> Create([Bind("ShoppingbagID,Date,TotalPrice,CustomerID,Closed")] Shoppingbag shoppingbag) { if (ModelState.IsValid) { _context.Add(shoppingbag); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CustomerID"] = new SelectList(_context.Customers, "CustomerID", "FullName", shoppingbag.CustomerID); return(View(shoppingbag)); }