public ActionResult EditBoat(int?id) { if (!SessionManager.checkCurrentUserType(UserType.MAINTENANCE_PERSON)) { return(new HttpStatusCodeResult(403)); } List <Location> locations = MainClass.Instance.getLocations(); foreach (Location l in locations) { BL.Boat b = l.getBoats().Find(v => v.id == id); if (b != null) { return(View(new BoatModel() { locationId = l.id, capacity = b.capacity, name = b.name, locationList = locations, pricePerHour = b.pricePerHour })); } } return(new HttpNotFoundResult()); }
public JsonResult GetBoatListByLocationIdAndPopularity(int boatId, string season) { foreach (Location l in MainClass.Instance.getLocations()) { BL.Boat b = l.getBoats().Find(v => v.id == boatId); if (b != null) { return(Json(b, JsonRequestBehavior.AllowGet)); } } return(Json(null, JsonRequestBehavior.AllowGet)); }
public ActionResult EditBoat(BoatModel model) { if (!SessionManager.checkCurrentUserType(UserType.MAINTENANCE_PERSON)) { return(new HttpStatusCodeResult(403)); } if (ModelState.IsValid) { Location newLocation = MainClass.Instance.getLocations().Find(v => v.id == model.locationId); if (newLocation != null) { foreach (Location l in MainClass.Instance.getLocations()) { BL.Boat b = l.getBoats().Find(v => v.id == model.id); if (b != null) { b.capacity = model.capacity; b.name = model.name; b.pricePerHour = model.pricePerHour; if (newLocation != l) { if (l.removeBoat(b) && newLocation.addBoat(b) && b.saveInDB() != null) { return(Redirect("/Boat/ViewBoat?locationId=" + l.id)); } else { return(View(model)); } } if (b.saveInDB() != null) { return(Redirect("/Boat/ViewBoat?locationId=" + l.id)); } } } } } ViewBag.Status = false; ViewBag.Message = "Could not edit boat"; return(View(model)); }
public JsonResult GetBoatDetail(int boatId) { if (!SessionManager.userIsLoggedIn()) { return(Json(null, JsonRequestBehavior.AllowGet)); } foreach (Location l in MainClass.Instance.getLocations()) { BL.Boat b = l.getBoats().Find(v => v.id == boatId); if (b != null) { return(Json(b, JsonRequestBehavior.AllowGet)); } } return(Json(null, JsonRequestBehavior.AllowGet)); }
public ActionResult DeleteBoat(int?id) { if (!SessionManager.checkCurrentUserType(UserType.MAINTENANCE_PERSON)) { return(new HttpStatusCodeResult(403)); } foreach (Location l in MainClass.Instance.getLocations()) { BL.Boat b = l.getBoats().Find(v => v.id == id); if (b != null && l.removeBoat(b)) { return(Redirect("/Boat/ViewBoat?locationId=" + l.id)); } } return(new HttpNotFoundResult()); }
public ActionResult RentBoat(BoatRentModel boatRentModel) { if (!SessionManager.userIsLoggedIn()) { return(new HttpStatusCodeResult(403)); } if (ModelState.IsValid) { BL.Location location = MainClass.Instance.getLocations().Find(v => v.id == boatRentModel.locationId); if (location != null) { BL.Boat boat = location.getBoats().Find(v => v.id == boatRentModel.boatId); if (boat != null) { if (location.canRentBoat(boat, boatRentModel.startTime, boatRentModel.endTime, boatRentModel.numPersons)) { BL.BoatRental rental = new BL.BoatRental(boatRentModel.startTime, boatRentModel.endTime, boat, boatRentModel.numPersons); boatRentModel.totalPrice = rental.getTotalPrice(); boatRentModel.locationName = location.name; boatRentModel.boat = boat; System.Web.HttpContext.Current.Session["boatRental"] = boatRentModel; return(RedirectToAction("OrderBoatRental", "Boat")); } } } } ViewBag.Status = false; ViewBag.Message = "Boat can not be rented. Please make sure you enter the correct date and time slot " + "and number of persons not bigger than the capacity."; return(View(new BoatRentModel() { locationList = BL.MainClass.Instance.getLocations() })); }