// GET: Recive/Create public ActionResult Create( ) { var viewModel = new POSCreateViewModel { ProductsSelectList = db.Products?.Select(x => new SelectListItem { Text = x.Name, Value = x.ID.ToString() }).ToList() }; return(View(viewModel)); }
public ActionResult Create(POSCreateViewModel model) { if (ModelState.IsValid) { var recive = new Recive { ProductId = model.ProductId, Date = DateTime.UtcNow, Customer = model.ClientName, Quantity = model.Quantity }; var product = db.Products.Find(model.ProductId); product.Quantity = product.Quantity - recive.Quantity; db.Recives.Add(recive); db.SaveChanges(); return(RedirectToAction("Index")); } return(View()); }