public async Task <IActionResult> Create([Bind("Id,Item,Price,Quantity,DateAndTime,Cart,Store,Customer")] Orders orders) { Products prod = _pcontext.FindByName(orders.Item); Customers cust = _ccontext.FindByName(orders.Customer); if (prod.Stock < orders.Quantity) { return(View("OutOfStock")); } if (ModelState.IsValid) { orders.Cart = 1; prod.Stock -= orders.Quantity; _pcontext.Update(prod); orders.Store = cust.Store; orders.Price = prod.Price; orders.Total = orders.Price * orders.Quantity; _context.Add(orders); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Cart))); } ViewData["Customer"] = new SelectList(_context.Customers, "FirstName", "FirstName", orders.Customer); return(View("Cart")); }