public ActionResult Create(EquipmentRental equipmentRental) { var eqId = equipmentRental.EquipmentId; var eq = _context.Equipments.Single(e => e.Id == eqId); if (eq.InStock <= 0) { return(View("Error")); } if (!ModelState.IsValid) { var equipments = _context.Equipments.Where(e => e.InStock > 0).ToList(); var customers = _context.Customers.ToList(); var viewModel = new EquipmentRentalFormViewModel { Equipments = equipments, Customers = customers, EquipmentRental = equipmentRental }; return(View("EquipmentRentalForm", viewModel)); } eq.InStock--; equipmentRental.RentDate = DateTime.Now; _context.EquipmentRentals.Add(equipmentRental); _context.SaveChanges(); return(RedirectToAction("Index", "Home")); }
public ActionResult Create([Bind(Include = "EquipmentRentalID,EquipmentID,WarehouseID,lifeguard_id,ReturnDate,DateOfLoan,Return")] EquipmentRental equipmentRental) { if (ModelState.IsValid) { var a = db.Equipments.Find(equipmentRental.EquipmentID); a.Status = "onloan"; db.Entry(a).State = EntityState.Modified; equipmentRental.DateOfLoan = DateTime.Now; db.EquipmentRentals.Add(equipmentRental); db.SaveChanges(); return(RedirectToAction("Index")); } //List<Warehouse>warehouses = db.Warehouses.ToList(); //ViewBag.WarehouseID = new SelectList(warehouses, "WarehouseID", "WarehouseName", equipmentRental.WarehouseID); ViewBag.EquipmentID = new SelectList(db.Equipments, "EquipmentID", "itemName", equipmentRental.EquipmentID); ViewBag.lifeguard_id = new SelectList(db.Lifeguards, "lifeguard_id", "lifeguard_name", equipmentRental.lifeguard_id); ViewBag.WarehouseID = new SelectList(db.Warehouses, "WarehouseID", "WarehouseName", equipmentRental.WarehouseID); return(View(equipmentRental)); }
public ActionResult DeleteConfirmed(int id) { EquipmentRental equipmentRental = db.EquipmentRentals.Find(id); db.EquipmentRentals.Remove(equipmentRental); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: EquipmentRentals/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } EquipmentRental equipmentRental = db.EquipmentRentals.Find(id); if (equipmentRental == null) { return(HttpNotFound()); } return(View(equipmentRental)); }
public ActionResult Edit([Bind(Include = "EquipmentRentalID,EquipmentID,WarehouseID,lifeguard_id,ReturnDate,DateOfLoan,Return")] EquipmentRental equipmentRental) { if (ModelState.IsValid) { equipmentRental.DateOfLoan = DateTime.Now; db.Entry(equipmentRental).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.EquipmentID = new SelectList(db.Equipments, "EquipmentID", "itemName", equipmentRental.EquipmentID); ViewBag.lifeguard_id = new SelectList(db.Lifeguards, "lifeguard_id", "lifeguard_name", equipmentRental.lifeguard_id); ViewBag.WarehouseID = new SelectList(db.Warehouses, "WarehouseID", "WarehouseName", equipmentRental.WarehouseID); return(View(equipmentRental)); }
// GET: EquipmentRentals/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } EquipmentRental equipmentRental = db.EquipmentRentals.Find(id); if (equipmentRental == null) { return(HttpNotFound()); } ViewBag.EquipmentID = new SelectList(db.Equipments, "EquipmentID", "itemName", equipmentRental.EquipmentID); ViewBag.lifeguard_id = new SelectList(db.Lifeguards, "lifeguard_id", "lifeguard_name", equipmentRental.lifeguard_id); ViewBag.WarehouseID = new SelectList(db.Warehouses, "WarehouseID", "WarehouseName", equipmentRental.WarehouseID); return(View(equipmentRental)); }