public async Task <IActionResult> Create([Bind("DeliveryPouchID,DeliveryID,PouchID,OrderQuantity,Delivered")] DeliveryPouch deliveryPouch) { if (ModelState.IsValid) { _context.Add(deliveryPouch); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["DeliveryID"] = new SelectList(_context.Delivery, "DeliveryID", "DeliveryID", deliveryPouch.DeliveryID); ViewData["PouchID"] = new SelectList(_context.Pouch, "PouchID", "PouchID", deliveryPouch.PouchID); return(View(deliveryPouch)); }
public async Task <IActionResult> Edit(int id, [Bind("DeliveryPouchID,DeliveryID,PouchID,OrderQuantity,Delivered")] DeliveryPouch deliveryPouch) { if (id != deliveryPouch.DeliveryPouchID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(deliveryPouch); await _context.SaveChangesAsync(); if (deliveryPouch.Delivered) { Pouch pouch = _context.Pouch.First(p => p.PouchID == deliveryPouch.PouchID); pouch.StockOut += deliveryPouch.OrderQuantity; await _context.SaveChangesAsync(); } } catch (DbUpdateConcurrencyException) { if (!DeliveryPouchExists(deliveryPouch.DeliveryPouchID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["DeliveryID"] = new SelectList(_context.Delivery, "DeliveryID", "DeliveryID", deliveryPouch.DeliveryID); ViewData["PouchID"] = new SelectList(_context.Pouch, "PouchID", "PouchID", deliveryPouch.PouchID); return(View(deliveryPouch)); }