public ActionResult Create(VoorraadViewModel voorraadViewModel) { Voorraad newVoorraad = new Voorraad(); ProductLocatie_regel newLocatie = new ProductLocatie_regel(voorraadViewModel.Aantal); ProductLocatie_regel newProductLocatieRegel = new ProductLocatie_regel(voorraadViewModel.Aantal); if (voorraadViewModel.ProductId != null) { foreach (int item in voorraadViewModel.ProductId) { Product foundProduct = db.ProductDbSet.Find(item); ProductVoorraad_regel productVoorraad = new ProductVoorraad_regel { Product = foundProduct, Voorraad = newVoorraad }; //maak een nieuwe productvoorraadregel aan met het id van product en id van voorraad newVoorraad.VoorraadProduct.Add(productVoorraad); } } if (voorraadViewModel.LocatieId != null) { foreach (int item in voorraadViewModel.LocatieId) { Locatie foundLocatie = db.LocatieDbSet.Find(item); ProductLocatie_regel productLocatie = new ProductLocatie_regel { Locatie = foundLocatie, Voorraad = newVoorraad, Aantal = newProductLocatieRegel.Aantal }; //maak een nieuwe productlocatie regel aan in de db met productid van product en locatieid van loatie en het aantal (stuks) producten dat is meegegeven newVoorraad.LocatieProduct.Add(productLocatie); } db.VoorraadDbSet.Add(newVoorraad); db.SaveChanges(); } return(this.RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "VoorraadItemId,Aantal,LocatieId")] ProductLocatie_regel voorraad) { if (ModelState.IsValid) { db.Entry(voorraad).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(voorraad)); }
// GET: Voorraad/Edit/5 public ActionResult Edit(int?id) { ProductLocatie_regel productLocatie_Regel = new ProductLocatie_regel(); Voorraad foundVoorraad = db.VoorraadDbSet.Find(id); productLocatie_Regel.Aantal = db.ProductLocatieDbSet.Where(pl => pl.VoorraadItemId == id).Select(pl => pl.Aantal).FirstOrDefault(); //om aantal te tonen op de view productLocatie_Regel.LocatieId = db.ProductLocatieDbSet.Where(pl => pl.VoorraadItemId == id).Select(pl => pl.LocatieId).FirstOrDefault(); // om locatie id te tonen op de view if (foundVoorraad == null) { return(this.RedirectToAction("Index")); } productLocatie_Regel.VoorraadItemId = foundVoorraad.VoorraadItemId; return(View(productLocatie_Regel)); }