예제 #1
0
        public void ScheduleCab(BookingService bookingService)
        {
            Console.WriteLine("Do You Want to Book a Cab (y/n)...");
            var answer = Console.ReadKey();

            if (answer.Key != ConsoleKey.Y)
            {
                return;
            }

            ConsoleKeyInfo moreCab;

            do
            {
                var     bookingDetails = InputBookingDetails();
                BookCab bookCab        = new BookCab(bookingDetails);
                bookingService.ScheduleCab(bookCab);
                Console.WriteLine("Do You Want to Book More Cab (y/n)...");
                moreCab = Console.ReadKey();
            } while (moreCab.Key == ConsoleKey.Y);

            Console.WriteLine("\n***********************************");
            Console.WriteLine("\nConfirm Booking (y/n)...");
            var confirmed = Console.ReadKey();

            Console.WriteLine("***********************************");
            if (confirmed.Key == ConsoleKey.Y)
            {
                bookingService.ConfirmService(true);
            }
            Console.WriteLine("\n***********************************");
        }
예제 #2
0
        // POST api/BookCabController

        /// <summary>
        /// To Book a cab for the Passenger
        /// </summary>
        /// <param name="passangerId"></param>
        /// <param name="current_Lat"></param>
        /// <param name="current_Lon"></param>
        /// <param name="cab_Type"></param>
        /// <param name="destination_lat"></param>
        /// <param name="destination_Lon"></param>
        /// <returns>
        ///     <param name="status">Status of the API request</param>
        ///     <param name="message">Response message</param>
        /// </returns>
        public Response Post([FromBody] BookCab value)
        {
            AppDao          dbobj          = new AppDao();
            Response        responseobj    = new Response();
            Identifier      resultObj      = new Identifier();
            SelectedDriver  selectedCabObj = new SelectedDriver();
            Person          selectedDriver = new Person();
            BookCabResponse returnObj      = new BookCabResponse();

            try
            {
                //To Fetch the vehicle_Type id for the cab type
                string query = "SELECT Id FROM Vehicle_Type WHERE type = '" + value.cab_Type + "'";
                resultObj = dbobj.GetVehicleTypeId(query);

                //To Fetch the cab details if available
                query          = "SELECT person_id as id, id AS vehicle_id , registration_number,ideal_location_lat AS driver_lat,ideal_location_lon AS driver_lon,passenger_capacity  FROM Vehicle WHERE is_active = 1 AND person_id != " + value.passangerId + " AND ride_in_progress = 0 ORDER BY ((" + value.current_Lat + " - ideal_location_lat) * (" + value.current_Lat + " - ideal_location_lat) + (" + value.current_Lon + " - ideal_location_lon) * (" + value.current_Lon + " - ideal_location_lon)) LIMIT 1; ";
                selectedCabObj = dbobj.GetCab(query);

                //Insert the vehicle details in the vehicle location table as the cab has been booked
                query = "INSERT INTO Vehicle_Location Values(" + selectedCabObj.driver_lat + "," + selectedCabObj.driver_lon + "," + value.current_Lat + "," + value.current_Lon + "," + (selectedCabObj.passenger_capacity - 1) + "," + selectedCabObj.vehicle_id + "," + resultObj.Id + ")";
                dbobj.Execute(query);

                //Update Ride in Progress status
                query = "UPDATE Vehicle SET ride_in_progress = 1 WHERE is_active = 1 AND person_id = " + selectedCabObj.Id + " AND id = " + selectedCabObj.vehicle_id + "";
                dbobj.Execute(query);

                //Get the driver Name and phone number for the passenger
                query          = "SELECT first_name,last_name,primary_phone_number FROM Person WHERE  Id = " + selectedCabObj.Id + "";
                selectedDriver = dbobj.GetDriverDetails(query);

                //Get the estimated Fare
                double estimatedFare = dbobj.EstimatedFare(value.current_Lat, value.current_Lon, value.destination_lat, value.destination_Lon, value.cab_Type);

                returnObj.first_name          = selectedDriver.first_name;
                returnObj.last_name           = selectedDriver.last_name;
                returnObj.driver_phone_number = selectedDriver.primary_phone_number;
                returnObj.estimated_fare      = estimatedFare;

                responseobj.status  = "Success";
                responseobj.message = JsonConvert.SerializeObject(returnObj);
            }
            catch (Exception ex)
            {
                responseobj.status  = "Failed";
                responseobj.message = "Booking a cab Failed with error -> " + ex.Message;
            }

            return(responseobj);
        }