public ActionResult SaveC(BuyConsole buyconsole) { buyconsole.DateAdded = DateTime.Now; _context.BuyConsoles.Add(buyconsole); var console = _context.Consoles.SingleOrDefault(x => x.Id == buyconsole.ConsoleId); if (console.Stock != 0) { console.Stock = console.Stock - buyconsole.Stock; } _context.SaveChanges(); return(RedirectToAction("Index", "Customers")); }
public ActionResult MakeBuyC(BuyConsole buyconsole) { if (!ModelState.IsValid) { return(View("Manager", buyconsole)); } var viewModel = new BuyConsoleViewModel { BuyConsole = new BuyConsole(), Console = _context.Consoles.Single(c => c.Id == buyconsole.ConsoleId), Customer = _context.Customers.Single(c => c.Id == buyconsole.CustomerId), MembershipTypes = _context.MembershipTypes.ToList() }; return(View(viewModel)); }