public Ride(int locationFrom, int locationTo, RideTypeEnum rideType, DateTime time, Taxi taxi, int price) { LocationFrom = locationFrom; LocationTo = locationTo; RideType = rideType; Time = time; Taxi = taxi; Price = price; }
public int CalculatePrice(int locationFrom, int locationTo, RideTypeEnum rideType, DateTime time, TaxiCompany company) { var price = company.PricePerUnitOfDistance * Math.Abs(locationFrom - locationTo); if (rideType == RideTypeEnum.InnerCity) { price *= 2; } if (time.Hour < ExpensiveHoursEnd || time.Hour > ExpensiveHoursStart) { price *= 2; } return(price); }
private Ride OrderRide(int locationFrom, int locationTo, RideTypeEnum rideType, DateTime time) { var bestTaxi = FindBestTaxi(locationFrom); if (bestTaxi == null) { _logger.WriteLine("Could not find a suitable taxi (all are too far)"); return(null); } var price = _ridePriceCalculator.CalculatePrice(locationFrom, locationTo, rideType, time, bestTaxi.Company); var ride = new Ride(locationFrom, locationTo, rideType, time, bestTaxi, price); _logger.WriteLine("Ride ordered, price: " + ride.Price); return(ride); }
public async Task <RideResponse> PostRideAsync(Location startLocation, Location endLocation, RideTypeEnum rideType, string primetimeConfirmationToken = null) { string url = "rides"; var postData = new Ride { StartLocation = startLocation, EndLocation = endLocation, Type = rideType, PrimetimeConfirmationToken = primetimeConfirmationToken }; var content = new StringContent(JsonConvert.SerializeObject(postData), Encoding.UTF8, "application/json"); return(await PostToApiAsync <RideResponse>(url, content)); }