public Ride(RideRequest rideRequest, Taxi taxi)
 {
     RideRequest = rideRequest ?? throw new ArgumentNullException(nameof(rideRequest));
     Taxi        = taxi ?? throw new ArgumentNullException(nameof(taxi));
 }
Esempio n. 2
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);
        }