public ActionResult EditLocation(int?id) { if (!SessionManager.checkCurrentUserType(UserType.MAINTENANCE_PERSON)) { return(new HttpStatusCodeResult(403)); } BL.Location l = MainClass.Instance.getLocations().Find(v => v.id == id); if (l != null) { return(View(new LocationModel() { name = l.name, point = new List <LatLongModel>() { new LatLongModel() { latitude = (double)l.point.latitude, longitude = (double)l.point.longitude } } })); } return(new HttpNotFoundResult()); }
public ActionResult EditLocation(LocationModel model) { if (!SessionManager.checkCurrentUserType(UserType.MAINTENANCE_PERSON)) { return(new HttpStatusCodeResult(403)); } if (ModelState.IsValid) { BL.Location l = MainClass.Instance.getLocations().Find(v => v.id == model.id); if (l != null) { l.name = model.name; l.point.latitude = (decimal)System.Web.HttpContext.Current.Session["mapLatitude"]; l.point.longitude = (decimal)System.Web.HttpContext.Current.Session["mapLongitude"]; l.point.saveInDB(); if (l.saveInDB() != null) { return(RedirectToAction("ViewLocation", "Boat")); } } } ViewBag.Status = false; ViewBag.Message = "Could not edit location"; return(View()); }
public ActionResult GetBoatList(int locationId) { if (!SessionManager.userIsLoggedIn()) { return(new HttpStatusCodeResult(403)); } BL.Location location = BL.MainClass.Instance.getLocations().Find(v => v.id == locationId); ViewBag.boatList = new SelectList(location.getBoats(), "id", "name"); return(PartialView("DisplayBoatInLocation")); }
public bool CheckLocation(int locationId) { BL.Location l = MainClass.Instance.getLocations().Find(v => v.id == locationId); if (l != null) { return(true); } else { return(false); } }
public ActionResult ViewBoat(int?locationId) { if (!SessionManager.checkCurrentUserType(UserType.MAINTENANCE_PERSON)) { return(new HttpStatusCodeResult(403)); } if (locationId != null) { BL.Location l = MainClass.Instance.getLocations().Find(v => v.id == locationId); if (l != null) { ViewBag.locationId = locationId; return(View(l.getBoats())); } } 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() })); }
public ActionResult AddBoat(BoatModel boatModel) { if (!SessionManager.checkCurrentUserType(UserType.MAINTENANCE_PERSON)) { return(new HttpStatusCodeResult(403)); } boatModel.locationList = BL.MainClass.Instance.getLocations(); boatModel.file.SaveAs(Server.MapPath("~/Public/Images/") + boatModel.file.FileName); boatModel.imagePath = boatModel.file.FileName; // string path = Path.Combine(Server.MapPath("~/Public/Images"), Path.GetFileName(boatModel.file.FileName)); //boatModel.ImageFile.SaveAs(path); string fileName = boatModel.file.FileName; //string extension = Path.GetExtension(boatModel.file.FileName); //fileName = fileName + extension; string imagePath = "Public/Images/" + fileName; if (ModelState.IsValid) { BL.Location location = MainClass.Instance.getLocations().Find(v => v.id == boatModel.locationId); if (location != null) { if (location.addBoat(new BL.Boat(boatModel.name, boatModel.capacity, boatModel.pricePerHour, boatModel.seasonId, imagePath))) { ViewBag.Status = true; ViewBag.Message = "Boat added successfully"; return(View(boatModel)); } } } ViewBag.Status = false; ViewBag.Message = "Boat could not be added. Please make sure that you select a location."; return(View(boatModel)); }
public ActionResult PaymentWithPaypal() { if (!SessionManager.userIsLoggedIn()) { return(new HttpStatusCodeResult(403)); } BL.User user = (BL.User)System.Web.HttpContext.Current.Session["user"]; if (user == null) { ViewBag.Status = false; ViewBag.Message = "User is not logged in"; return(View("Payment")); } BoatRentModel boatRentModel = (BoatRentModel)System.Web.HttpContext.Current.Session["boatRental"]; GroupTripModel groupTripModel = (GroupTripModel)System.Web.HttpContext.Current.Session["groupTrip"]; if (boatRentModel == null && groupTripModel == null) { ViewBag.Status = false; ViewBag.Message = "Neither the BoatRentModel nor the GroupTripModel exists"; return(View("Payment")); } //getting the apiContext as earlier APIContext apiContext = PaypalConfiguration.GetAPIContext(); try { string payerId = Request.Params["PayerID"]; if (string.IsNullOrEmpty(payerId)) { //this section will be executed first because PayerID doesn't exist //it is returned by the create function call of the payment class // Creating a payment // baseURL is the url on which paypal sendsback the data. // So we have provided URL of this controller only string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority + "/PayPal/PaymentWithPayPal?"; //guid we are generating for storing the paymentID received in session //after calling the create function and it is used in the payment execution var guid = Convert.ToString((new Random()).Next(100000)); //CreatePayment function gives us the payment approval url //on which payer is redirected for paypal account payment Payment createdPayment = null; if (boatRentModel != null) { createdPayment = this.CreateBoatRentalPayment(apiContext, baseURI + "guid=" + guid, boatRentModel); } else if (groupTripModel != null) { createdPayment = this.CreateGroupTripPayment(apiContext, baseURI + "guid=" + guid, groupTripModel); } //get links returned from paypal in response to Create function call var links = createdPayment.links.GetEnumerator(); string paypalRedirectUrl = null; while (links.MoveNext()) { Links lnk = links.Current; if (lnk.rel.ToLower().Trim().Equals("approval_url")) { //saving the payapalredirect URL to which user will be redirected for payment paypalRedirectUrl = lnk.href; } } // saving the paymentID in the key guid Session.Add(guid, createdPayment.id); return(Redirect(paypalRedirectUrl)); } else { // This section is executed when we have received all the payments parameters // from the previous call to the function Create // Executing a payment var guid = Request.Params["guid"]; var executedPayment = ExecutePayment(apiContext, payerId, Session[guid] as string); if (executedPayment.state.ToLower() != "approved") { ViewBag.Status = false; ViewBag.Message = "Payment with PayPal is not approved."; return(View("Payment")); } if (boatRentModel != null) { BL.Location location = MainClass.Instance.getLocations().Find(v => v.id == boatRentModel.locationId); if (location == null) { ViewBag.Status = false; ViewBag.Message = "Location could not be found"; return(View("Payment")); } BL.BoatRental br = location.rentBoat(boatRentModel.boat, boatRentModel.startTime, boatRentModel.endTime, boatRentModel.numPersons); if (br == null) { ViewBag.Status = false; ViewBag.Message = "Boat could not be rented"; return(View("Payment")); } if (MainClass.Instance.orderBoatRental(br, PaymentType.PAYPAL, user.userAddress, user) == null) { ViewBag.Status = false; ViewBag.Message = "Boat could not be rented"; return(View("Payment")); } System.Web.HttpContext.Current.Session.Remove("boatRental"); } else if (groupTripModel != null) { if (MainClass.Instance.orderGroupTrip(groupTripModel.finalGroupTrip, PaymentType.PAYPAL, user.userAddress, user) == null) { ViewBag.Status = false; ViewBag.Message = "Group trip could not be ordered"; return(View("Payment")); } System.Web.HttpContext.Current.Session.Remove("groupTrip"); } } } catch (Exception e) { ViewBag.Status = false; ViewBag.Message = e.Message; return(View("Payment")); } ViewBag.Status = true; ViewBag.Message = "Payment with PayPal was successful."; return(View("Payment")); }
public List <BL.Boat> GetBoatsByLocationId(int locationId, int popularity) { BL.Location l = MainClass.Instance.getLocations().Find(v => v.id == locationId); if (l != null) { switch (popularity) { case 1: return(like.getBoatsFromDB().Where(x => x.seasonId == popularity).Where(x => x.locationId == locationId).ToList()); break; case 2: return(like.getBoatsFromDB().Where(x => x.seasonId == popularity).Where(x => x.locationId == locationId).ToList()); break; case 3: return(like.getBoatsFromDB().OrderByDescending(b => b.pricePerHour).Where(x => x.locationId == locationId).ToList()); break; case 4: return(like.getBoatsFromDB().OrderBy(b => b.pricePerHour).Where(x => x.locationId == locationId).ToList()); break; case 5: return(like.getBoatsFromDB().OrderBy(b => b.capacity).Where(x => x.locationId == locationId).ToList()); break; case 6: return(like.getBoatsFromDB().OrderByDescending(b => b.capacity).Where(x => x.locationId == locationId).ToList()); break; case 7: return(like.getBoatsFromDB().OrderByDescending(b => b.likeCount).Where(x => x.locationId == locationId).ToList()); break; case 8: return(like.getBoatsFromDB().OrderBy(b => b.disLikeCount).Where(x => x.locationId == locationId).ToList()); break; default: return(like.getBoatsFromDB().Where(x => x.locationId == locationId).ToList()); } } else { List <BL.Boat> boat = MainClass.Instance.getBoats(); if (boat != null) { switch (popularity) { case 1: return(like.getBoatsFromDB().Where(x => x.seasonId == popularity).ToList()); break; case 2: return(like.getBoatsFromDB().Where(x => x.seasonId == popularity).ToList()); break; case 3: return(like.getBoatsFromDB().OrderByDescending(b => b.pricePerHour).ToList()); break; case 4: return(like.getBoatsFromDB().OrderBy(b => b.pricePerHour).ToList()); break; case 5: return(like.getBoatsFromDB().OrderBy(b => b.capacity).ToList()); break; case 6: return(like.getBoatsFromDB().OrderByDescending(b => b.capacity).ToList()); break; case 7: return(like.getBoatsFromDB().OrderByDescending(b => b.likeCount).ToList()); break; case 8: return(like.getBoatsFromDB().OrderBy(b => b.disLikeCount).ToList()); break; default: return(like.getBoatsFromDB()); } } } throw new HttpResponseException(HttpStatusCode.NotFound); }