public ActionResult NewBooking(HomeBookingModel model) { model.PickUpTime = DateTime.Now; Tuple <string, string> result = CalculateDistanceDuration(model.LocationFrom, model.LocationTo); model.DistanceKm = float.Parse(result.Item1) / 1000; return(View(model)); }
public ActionResult BookingDetails(HomeBookingModel model) { using (TaxiServiceEntities context = new TaxiServiceEntities()) { Tuple <string, string> result = CalculateDistanceDuration(model.LocationFrom, model.LocationTo); model.DistanceKm = float.Parse(result.Item1) / 1000; model.DurationMin = Int32.Parse(result.Item2); #region getVehicleAndLocation //List<Vehicle> getVehicleAndLocation = context.Vehicles.Where(x => x.IsAvailable == "YES" && x.VehicleTypeID == model.VehicleType).ToList(); //if (getVehicleAndLocation == null) //{ // ViewBag.MessageResponse = "No Vehicles available"; // return View(); //} //foreach (var item in getVehicleAndLocation) //{ // Tuple<string, string> res = CalculateDistanceDuration(model.LocationFrom, item.CurrentLocation); // if (float.Parse(res.Item1) < 50000) // { // ViewBag.MessageResponse = "Confirmed the vehicle"; // model.VehicleID = item.VehicleID; // break; // } // else // { // ViewBag.MessageResponse = "No Vehicles available"; // continue; // } //} #endregion if (model.VehicleID == 0) { return(View()); } #region Hire Fares if ((model.DistanceKm <= 1 && (model.VehicleType == 1 || model.VehicleType == 2)) || (model.DistanceKm <= 8 && model.VehicleType == 3)) { switch (model.VehicleType) { case 1: model.HirePrice = 150; break; case 2: model.HirePrice = 200; break; case 3: model.HirePrice = 1000; break; } } else { switch (model.VehicleType) { case 1: model.HirePrice = (model.DistanceKm - 1) * 50 + 150; break; case 2: model.HirePrice = (model.DistanceKm - 1) * 50 + 200; break; case 3: model.HirePrice = (model.DistanceKm - 8) * 50 + 1000; break; } } #endregion ` #region Assign Model values //UserDetail user = context.UserDetails.Where(o => o.UserLoginID == Int32.Parse(Session["LoginUserID"].ToString())).FirstOrDefault(); //HireDetail hireDetail = new HireDetail(); //hireDetail.PickupLocation = model.LocationFrom; //hireDetail.DropLocation = model.LocationTo; //hireDetail.DistanceKm = model.DistanceKm; //hireDetail.PickupDateTime = model.PickUpTime; //hireDetail.EstimatedFare = model.HirePrice; //hireDetail.UserID = user.UserID; //hireDetail.VehicleID = model.VehicleID; //hireDetail.VehicleTypeID = model.VehicleType; //hireDetail.HireStatusID = 1; //context.HireDetails.Add(hireDetail); //context.SaveChanges(); ConfirmedDetailViewModel viewModel = new ConfirmedDetailViewModel(); //viewModel.PickupLocation = hireDetail.PickupLocation; //viewModel.PickupDateTime = hireDetail.PickupDateTime; //viewModel.DropLocation = hireDetail.DropLocation; //viewModel.EstimatedFare = hireDetail.EstimatedFare; //viewModel.VehicleNumber = hireDetail.Vehicle.VehicleNumber; //viewModel.VehicleBrand = hireDetail.Vehicle.VehicleBrand; viewModel.ContactNo = 12346666; //viewModel.Image = hireDetail.Vehicle.Driver.DriverCode; #endregion return(View("ConfirmedDetails", viewModel)); } }