public void OrderRide(RideRequest rideRequest)
        {
            if (rideRequest == null)
            {
                throw new ArgumentNullException(nameof(rideRequest));
            }

            _logger.Log($"Ordering ride from {rideRequest.FromLocation} to {rideRequest.ToLocation}...");

            var closestVechicle = _taxiRepository.VechicleClosestTo(rideRequest.FromLocation, AcceptableDistance);
            var ride            = new Ride(rideRequest, closestVechicle);

            _logger.Log($"Ride ordered, price: {ride.Price}");

            AcceptRide(ride);
        }
示例#2
0
        public static List <Ride> GetRideList(int driverId)
        {
            List <Ride> rides = new List <Ride>();
            List <int>  ids   = GetRideIds();

            foreach (int id in ids)
            {
                Ride ride = GetRide(id);
                if (ride.Taxi.Driver.Id == driverId)
                {
                    rides.Add(ride);
                }
            }

            return(rides);
        }
        public static void SaveRide(Ride ride)
        {
            var idList = GetRideIds();

            if (idList.Count > 0)
            {
                idList.Sort((x, y) => x > y ? -1 : 1);
                ride.Id = idList[0] + 1;
            }
            else
            {
                ride.Id = 1;
            }

            Rides.Add(ride);
        }
示例#4
0
        private List <Ride> GetRideList(int driverId)
        {
            List <Ride> rides = new List <Ride>();
            List <int>  ids   = InMemoryRideDataBase.GetRideIds();

            foreach (int id in ids)
            {
                Ride ride = InMemoryRideDataBase.GetRide(id);
                if (ride != null && ride.TaxiInfo.DriverId == driverId)
                {
                    rides.Add(ride);
                }
            }

            return(rides);
        }
示例#5
0
        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);
        }
示例#6
0
        /// <summary>
        /// Order a ride with the closest taxi to the destination.
        /// </summary>
        /// <param name="locationFrom">Location of the customer</param>
        /// <param name="locationTo">Location of the destination</param>
        /// <param name="rideType">Within city or between cities</param>
        /// <param name="time">Time of the order</param>
        /// <returns></returns>
        public Ride OrderRide(int locationFrom, int locationTo, RideType rideType, DateTime time)
        {
            Taxi closestTaxi = GetClosestTaxi(locationFrom, locationTo);

            if (closestTaxi == null || Math.Abs(closestTaxi.Location - locationFrom) > DISTANCE_THRESHOLD)
            {
                throw new Exception("There are no available taxi vehicles!");
            }

            Ride ride = new Ride {
                Taxi = closestTaxi, LocationFrom = locationFrom, LocationTo = locationTo, RideType = rideType, Time = time
            };

            Console.WriteLine("Ride ordered, price: " + ride.Price.ToString());

            return(ride);
        }
 public static void SaveRide(Ride ride)
 {
     Rides.Add(getNextRideId(), ride);
 }
示例#8
0
        public Ride OrderRide(int locationFrom, int locationTo, int rideType, DateTime time)
        {
            #region FindingTheBestVehicle

            if (locationFrom == locationTo)
            {
                throw new Exception("Cannot order ride to the same location!");
            }

            Taxi minTaxi = Taxis.OrderBy(x => Math.Abs(x.Location - locationFrom)).FirstOrDefault();
            if (minTaxi == null)
            {
                throw new Exception("There are no available taxi vehicles!");
            }

            if (Math.Abs(minTaxi.Location - locationFrom) > 15)
            {
                throw new Exception("There are no available taxi vehicles!");
            }

            #endregion

            #region CreatingRide

            Ride ride = new Ride
            {
                TaxiDriverId   = minTaxi.TaxiDriverId,
                LocationFrom   = locationFrom,
                LocationTo     = locationTo,
                TaxiDriverName = minTaxi.TaxiDriverName
            };

            #endregion

            #region CalculatingPrice

            var distance = Math.Abs(locationFrom - locationTo);
            switch (minTaxi.TaxiCompany)
            {
            case "Naxi":
            {
                ride.Price = 10 * distance;
                break;
            }

            case "Alfa":
            {
                ride.Price = 15 * distance;
                break;
            }

            case "Gold":
            {
                ride.Price = 13 * distance;
                break;
            }

            default:
            {
                throw new Exception("Ilegal company");
            }
            }

            if (rideType == Constants.InterCity)
            {
                ride.Price *= 2;
            }

            if (time.Hour < 6 || time.Hour > 22)
            {
                ride.Price *= 2;
            }

            #endregion

            Console.WriteLine("Ride ordered, price: " + ride.Price);
            return(ride);
        }