예제 #1
0
        public static SearchRideRequest GetBooking()
        {
            SearchRideRequest booking = new SearchRideRequest();

            Console.Write(Constant.TravellingDate);
            booking.TravelDate = Helper.ValidDate();

            Console.Write(Constant.From);
            booking.From = Helper.GetValidCity();
            float TravellingDistance = 0;

            while (true)
            {
                Console.Write(Constant.To);
                booking.To = Helper.GetValidCity();

                if (booking.From != booking.To)
                {
                    break;
                }
                else
                {
                    Console.WriteLine(Constant.InValidInput);
                }
            }

            Console.WriteLine(Constant.Distance + TravellingDistance);
            Console.ReadKey();
            return(booking);
        }
        public List <Ride> GetRidesOffer(SearchRideRequest booking)
        {
            var from = ViaPointsInfo.Points?.FirstOrDefault(via => via.FromCity == booking.From.City);
            var to   = ViaPointsInfo.Points?.FirstOrDefault(via => via.ToCity == booking.To.City);

            return(AppDataService.Rides?.Where(ride => ride.TravelDate == booking.TravelDate &&
                                               ride.AvailableSeats > 0 && from.FromCity == booking.From.City && to.ToCity == booking.To.City).ToList());
        }
예제 #3
0
        public IActionResult GetOffers([FromBody] SearchRideRequest booking)
        {
            if (booking == null)
            {
                return(BadRequest());
            }

            return(Ok(this._rideServices.GetOffers(booking)));
        }
예제 #4
0
        public static SearchRideRequest GetBooking()
        {
            SearchRideRequest booking = new SearchRideRequest();

            Console.Write(Constant.TravellingDate);
            booking.TravelDate = Helper.ValidDate();

            Console.Write(Constant.From);
            string city = Helper.GetValidCity();

            booking.From = CitiesInfo.Cities.FirstOrDefault(a => a.City.Equals(city, StringComparison.InvariantCultureIgnoreCase));
            float TravellingDistance = 0;

            Console.Write(Constant.LandMark);
            booking.From.LandMark = Console.ReadLine();

            while (true)
            {
                Console.Write(Constant.To);
                city       = Helper.GetValidCity();
                booking.To = CitiesInfo.Cities.FirstOrDefault(a => a.City.Equals(city, StringComparison.InvariantCultureIgnoreCase));

                var fromCityIndex = ViaPointsInfo.Points.IndexOf(ViaPointsInfo.Points.FirstOrDefault(a => a.FromCity == booking.From.City));
                var toCityIndex   = ViaPointsInfo.Points.IndexOf(ViaPointsInfo.Points.FirstOrDefault(a => a.ToCity == booking.To.City));
                int viaPointCount = toCityIndex - fromCityIndex + 1;
                if (viaPointCount > 0)
                {
                    for (int viaPoint = 0; viaPoint < viaPointCount; viaPoint++)
                    {
                        Point via = new Point();
                        via = ViaPointsInfo.Points[fromCityIndex + viaPoint];
                        TravellingDistance = TravellingDistance + via.Distance;
                    }
                    break;
                }
                else
                {
                    Console.WriteLine(Constant.InValidInput);
                }
            }

            Console.WriteLine(Constant.Distance + TravellingDistance);
            Console.ReadKey();
            return(booking);
        }
예제 #5
0
        public void UserMainMenu()
        {
            Console.Write(Constant.UserMainMenuOptions);
            HomeMenu option = (HomeMenu)Helper.ValidInteger();
            var      user   = AppService.UserService.GetUser(AppService.CurrentUserId);

            if (user != null)
            {
                switch (option)
                {
                case HomeMenu.CreateRide:
                    var cars = AppService.CarServices.GetCarsByUser(AppService.CurrentUserId);
                    if (cars != null && cars.Any())
                    {
                        foreach (var car in cars)
                        {
                            Console.WriteLine((cars.IndexOf(car) + 1) + ". " + car.Model + " " + car.Number + "\n");
                        }
                        Console.WriteLine(Constant.CarSelection);
                        while (true)
                        {
                            int choice = Helper.ValidInteger();
                            if (choice <= cars.Count && choice != 0)
                            {
                                var ride = UserInput.GetRideDetails();
                                ride.CarId   = cars[choice - 1].Id;
                                ride.OwnerId = AppService.CurrentUserId;

                                Car carRecord = AppService.CarServices.GetCar(ride.CarId);
                                while (true)
                                {
                                    Console.Write(Constant.AvailableSeats);
                                    ride.AvailableSeats = Helper.ValidInteger();
                                    if (carRecord.NoofSeat >= ride.AvailableSeats)
                                    {
                                        break;
                                    }
                                }
                                AppService.RideServices.CreateRide(ride);
                                break;
                            }
                            else if (choice == 0)
                            {
                                break;
                            }
                            else
                            {
                                Console.WriteLine("Enter correct option");
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine(Constant.NoCarsAdded);
                        if (AppService.CarServices.AddNewCar(UserInput.GetCarDetails(), AppService.CurrentUserId))
                        {
                            Console.WriteLine(Constant.AllowRide);
                        }
                    }
                    Console.ReadLine();
                    UserMainMenu();

                    break;

                case HomeMenu.BookARide:
                    SearchRideRequest bookingRequest = UserInput.GetBooking();
                    List <Ride>       rides          = AppService.RideServices.GetRidesOffers(bookingRequest);
                    if (rides != null && rides.Count > 0)
                    {
                        foreach (var ride in rides)
                        {
                            Console.Write(rides.IndexOf(ride) + 1);
                            Display.OfferRide(ride);
                            Display.CarDetail(AppService.CarServices.GetCar(ride.CarId));
                        }
                        Console.WriteLine(Constant.RideSelection);

                        while (true)
                        {
                            int choice = Helper.ValidInteger();
                            if (choice <= rides.Count && choice != 0)
                            {
                                Booking booking = new Booking
                                {
                                    From       = bookingRequest.From,
                                    To         = bookingRequest.To,
                                    TravelDate = bookingRequest.TravelDate,
                                    Status     = Models.Client.BookingStatus.Pending,
                                    BookerId   = AppService.CurrentUserId
                                };
                                if (AppService.CurrentUserId != rides[choice - 1].OwnerId)
                                {
                                    AppService.BookingService.CreateBooking(booking, rides[choice - 1].Id);
                                    Console.WriteLine(Constant.RequestSentToOwner);
                                }
                                else
                                {
                                    Console.WriteLine(Constant.InvalidBookingRequest);
                                }

                                break;
                            }
                            else if (choice == 0)
                            {
                                Console.WriteLine("Ok select another time");
                                break;
                            }
                            else
                            {
                                Console.WriteLine(Constant.CorrectSelection);
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine(Constant.NoRequests);
                    }

                    Console.ReadKey();
                    UserMainMenu();

                    break;

                case HomeMenu.ViewStatus:
                    BookingStatus();
                    UserMainMenu();

                    break;

                case HomeMenu.AddNewCar:
                    if (AppService.CarServices.AddNewCar(UserInput.GetCarDetails(), AppService.CurrentUserId))
                    {
                        Console.Write("Car added");
                    }
                    else
                    {
                        Console.WriteLine("Sorry car not added right now");
                    }

                    UserMainMenu();

                    break;

                case HomeMenu.ModifyRide:
                    rides = AppService.RideServices.GetRides(AppService.CurrentUserId);
                    foreach (var ride in rides)
                    {
                        Console.Write(rides.IndexOf(ride));
                        Display.OfferRide(ride);
                    }
                    Console.Write("Select ride offer or for exit press 0");

                    while (true)
                    {
                        int choice = Helper.ValidInteger();
                        if (choice <= rides.Count && choice != 0)
                        {
                            Display.OfferRide(rides[choice - 1]);
                            Ride newRide = UserInput.GetRideDetails();
                            if (UserInput.Confirmation() == ConfirmationResponse.Yes && AppService.BookingService.GetBookingsByRideId(AppService.CurrentUserId).Count == 0)
                            {
                                AppService.RideServices.ModifyRide(newRide, rides[choice - 1].Id);
                                break;
                            }
                        }
                        else if (choice == 0)
                        {
                            break;
                        }
                    }

                    break;

                case HomeMenu.DeleteRide:
                    rides = AppService.RideServices.GetRides(AppService.CurrentUserId);
                    foreach (var ride in rides)
                    {
                        Console.Write(rides.IndexOf(ride) + 1);
                        Display.OfferRide(ride);
                    }
                    while (true)
                    {
                        int choice = Helper.ValidInteger();
                        Display.OfferRide(rides[choice - 1]);
                        if (choice <= rides.Count && choice != 0)
                        {
                            Console.WriteLine(Constant.Confirmation);
                            if (UserInput.Confirmation() == ConfirmationResponse.Yes)
                            {
                                AppService.RideServices.CancelRide(rides[choice - 1].Id);
                            }
                        }
                        else if (choice == 0)
                        {
                            break;
                        }
                    }
                    Console.ReadKey();
                    UserMainMenu();

                    break;

                case HomeMenu.UpdateAccountDetail:
                    if (!AppService.UserService.UpdateUser(UserInput.NewUser(AppService.UserService), AppService.CurrentUserId))
                    {
                        Console.WriteLine("Updatation Done");
                    }

                    break;

                case HomeMenu.DeleteUserAccount:
                    Console.WriteLine(Constant.Confirmation);
                    if (UserInput.Confirmation() == ConfirmationResponse.Yes)
                    {
                        if (AppService.UserService.DeleteUser(AppService.CurrentUserId))
                        {
                            Console.WriteLine(Constant.DeleteAccoutResponse);
                        }
                    }

                    break;

                case HomeMenu.SignOut:

                    break;

                case HomeMenu.Exit:
                    Environment.Exit(0);

                    break;
                }
            }
        }
예제 #6
0
 public IActionResult GetRidesOffers(SearchRideRequest booking)
 {
     return(Ok(_RideServices.GetRidesOffers(booking)));
 }