public ActionResult Create([Bind(Include = "Id,Material,TechnicsUnit,DateOfUse,QuantityOfMaterial")] UsedMaterial usedMaterial) { if (ModelState.IsValid) { Materials materials = db.Materials.Find(usedMaterial.Material); if (usedMaterial.QuantityOfMaterial <= materials.Quantity & usedMaterial.QuantityOfMaterial > 0) { db.UsedMaterial.Add(usedMaterial); materials.Quantity = materials.Quantity - usedMaterial.QuantityOfMaterial; db.Entry(materials).State = EntityState.Modified; db.SaveChanges(); } else if (usedMaterial.QuantityOfMaterial > materials.Quantity) { return(RedirectToAction("MaterialError")); } else if (usedMaterial.QuantityOfMaterial <= 0) { return(RedirectToAction("QuantityError")); } return(RedirectToAction("Index")); } ViewBag.Material = new SelectList(db.Materials, "Id", "Name", usedMaterial.Material); ViewBag.TechnicsUnit = new SelectList(db.Technics, "Id", "Name", usedMaterial.TechnicsUnit); return(View(usedMaterial)); }
public ActionResult Edit([Bind(Include = "Id,Name")] Technics technics) { if (ModelState.IsValid) { db.Entry(technics).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(technics)); }
public ActionResult Edit([Bind(Include = "Id,Name,Quantity")] Materials materials) { if (ModelState.IsValid) { db.Entry(materials).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(materials)); }