public JsonResult AddLabour(int equipmentId, int moduleId, string name, string description, Nullable <int> supplierId, float quantity, int quantityUnit) { Equipment e = db.Equipments.Find(equipmentId); if (e != null) { EquipmentModule em = e.EquipmentModules.SingleOrDefault(x => x.Id == moduleId); if (em != null) { EquipmentLabour el = new EquipmentLabour() { Name = name, Description = description, SupplierId = supplierId, Quantity = quantity, QuantityUnit = (TemporalUnit)quantityUnit }; em.EquipmentLabours.Add(el); db.SaveChanges(); el = db.EquipmentLabours.Include(x => x.Supplier).Single(x => x.Id == el.Id); return(Json(new { result = true, id = el.Id, name = el.Name, description = el.Description, supplierId = el.SupplierId, supplierName = el.SupplierId != null ? el.Supplier.Name : string.Empty, quantity = Math.Round(el.Quantity, 2).ToString() + " " + el.QuantityUnit.Name() }, JsonRequestBehavior.AllowGet)); } } return(Json(new { result = false }, JsonRequestBehavior.AllowGet)); }
public ActionResult DeleteConfirmed(int id) { EquipmentLabour equipmentLabour = db.EquipmentLabours.Find(id); db.EquipmentLabours.Remove(equipmentLabour); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,EquipmentModuleId,Name,Description,SupplierId,Quantity,QuantityUnit")] EquipmentLabour equipmentLabour) { if (ModelState.IsValid) { db.Entry(equipmentLabour).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.EquipmentModuleId = equipmentLabour.EquipmentModule.Equipment.ModuleList(equipmentLabour.EquipmentModuleId); ViewBag.SupplierId = new SelectList(db.Suppliers, "Id", "Name", equipmentLabour.SupplierId); return(View(equipmentLabour)); }
// GET: EquipmentLabours/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } EquipmentLabour equipmentLabour = db.EquipmentLabours.Find(id); if (equipmentLabour == null) { return(HttpNotFound()); } return(View(equipmentLabour)); }
// GET: EquipmentLabours/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } EquipmentLabour equipmentLabour = db.EquipmentLabours.Find(id); if (equipmentLabour == null) { return(HttpNotFound()); } ViewBag.EquipmentModuleId = equipmentLabour.EquipmentModule.Equipment.ModuleList(equipmentLabour.EquipmentModuleId); ViewBag.SupplierId = new SelectList(db.Suppliers, "Id", "Name", equipmentLabour.SupplierId); return(View(equipmentLabour)); }
public JsonResult RemoveLabour(int labourId) { EquipmentLabour el = db.EquipmentLabours.Find(labourId); if (el != null) { try { db.EquipmentLabours.Remove(el); db.SaveChanges(); return(Json(new { result = true }, JsonRequestBehavior.AllowGet)); } catch (Exception) { } } return(Json(new { result = false }, JsonRequestBehavior.AllowGet)); }