public async Task <IActionResult> CloseOrder(int id, Order order) { if (order.OrderID != id) { return(NotFound()); } ApplicationUser user = await _userManager.GetUserAsync(User); var products = _context.CompositeProduct.Where(p => p.OrderID == id); ModelState.Remove("User"); if (ModelState.IsValid) { try { foreach (var product in products) { // update the qty of screenID and inkID if (product.ScreenID != null) { Screen screen = await _context.Screen.SingleOrDefaultAsync(s => s.ScreenID == product.ScreenID); screen.Quantity -= 1; Ink ink = await _context.Ink.SingleOrDefaultAsync(i => i.InkID == product.InkID); ink.Quantity -= 1; _context.Update(screen); _context.Update(ink); await _context.SaveChangesAsync(); } ProductType productType = await _context.ProductType.SingleOrDefaultAsync(p => p.ProductTypeID == product.ProductTypeID); productType.Quantity -= 1; _context.Update(productType); await _context.SaveChangesAsync(); } order.User = user; _context.Update(order); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OrderExists(order.OrderID)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Products", "Home")); } CloseOrderVM brokenModel = new CloseOrderVM(_context, (int)id, user); return(View(brokenModel)); }
// This action is authored by Jordan Dhaenens // This action presents the User with their default shipping and billing addresses, payment option, and cart items // GET: Order/CloseOrder/3 public async Task <IActionResult> CloseOrder(int?id) { if (id == null) { return(NotFound()); } ApplicationUser user = await _userManager.GetUserAsync(User); CloseOrderVM model = new CloseOrderVM(_context, (int)id, user); return(View(model)); }