Beispiel #1
0
 public IHttpActionResult BookRide([FromUri] long id, [FromUri] int vehicleTypeId, [FromBody] Ride.RideBookingDetails rideDetails)
 {
     try
     {
         Rider rider = new Rider(id);
         rideDetails.VehicleType = new VehicleType(vehicleTypeId);
         Ride ride = rider.BookRide(rideDetails);
         return(Ok(ride));
     }
     catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
 }
Beispiel #2
0
 public ActionResult RiderDetails(BookRideViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     try
     {
         //create rider
         Rider rider = new Rider(new User.NameFormat {
             FirstName = model.RiderFirstName, LastName = model.RidierLastName
         }, new User.ContactNumberFormat(model.CountryCode, model.CompanyCode, model.Number));
         //Book Ride
         var ride = rider.BookRide(new Ride.RideBookingDetails
         {
             Destination = new Location {
                 Latitude = model.DLat, Longitude = model.Dlng
             },
             PickUpLocation = new Location {
                 Latitude = model.PLat, Longitude = model.Plng
             },
             VehicleType = new VehicleType(model.VehicleType)
         });
         //Add Promo
         if (model.PromoCode != null || model.PromoCode == String.Empty)
         {
             ride.AddPromo(PromoCode.GetPromoCode(model.PromoCode));
         }
         return(RedirectToAction("BookRide"));
     }
     catch (UniqueKeyViolationException ex)
     {
         ModelState.AddModelError(String.Empty, ex.Message);
         return(View(model));
     }
     catch (UnsuccessfullProcessException)
     {
         ModelState.AddModelError(String.Empty, "Seems like no driver is available near the pick-up point.");
         return(View(model));
     }
     catch (Exception ex)
     {
         return(RedirectToAction("ErrorPage", "Error", ex));
     }
 }