public ProductStock(ProductStockFromViewModel viewModel) { AvailableQuantity = viewModel.AvailableQuantity; ActualQuantity = viewModel.ActualQuantity; SectorID = viewModel.SectorID; ProductID = viewModel.ProductID; BottlingID = viewModel.BottlingID; IsLow = viewModel.CheckQuantity(); OrderProducts = new Collection <OrderProducts>(); }
public ActionResult Create(ProductStockFromViewModel viewmodel) { if (!ModelState.IsValid) { viewmodel.Bottlings = _context.Bottlings; viewmodel.Products = _context.Products; viewmodel.Sectors = _context.Sectors; return(View(viewmodel)); } viewmodel.Bottling = _context.Bottlings.Find(viewmodel.BottlingID); viewmodel.CalculateExpirationDate(); viewmodel.CheckQuantity(); var productStock = new ProductStock(viewmodel); _context.ProductStocks.Add(productStock); _context.SaveChanges(); return(RedirectToAction("Index")); }