public IActionResult CreateOrderItem([Bind("Id,OrderId,ProductId,Quantity")] OrderItems orderItems) { if (ModelState.IsValid) { if (ShoppingCart != null) { orderItems.OrderId = ShoppingCart.Id; var inv = _context.Inventory.FirstOrDefault(i => i.ProductId == orderItems.ProductId && i.LocationId == ShoppingCart.LocationId); var item = ShoppingCart.AddToCart(orderItems); if (item.Quantity > inv.Stock) { item.Quantity = inv.Stock; } ShoppingCart.Total += item.Quantity * _context.Products.FirstOrDefault(p => p.Id == item.ProductId).Price; } ViewData["Total"] = ShoppingCart.Total.ToString("#.##"); return(RedirectToAction(nameof(Index))); } ViewData["Total"] = ShoppingCart.Total.ToString("#.##"); ViewData["OrderId"] = new SelectList(_context.Orders, "Id", "Id", orderItems.OrderId); ViewData["ProductId"] = new SelectList(_context.Products, "Id", "Name", orderItems.ProductId); return(View(orderItems)); }