コード例 #1
0
        public IActionResult AddRide(Ride ride)
        {
            if (ride != null)
            {
                var model = _IRideService.AddRide(ride);
            }

            return(RedirectToAction("GetRides"));
        }
コード例 #2
0
        public IActionResult CreateRide([FromBody] RidesRequestData RequestData)
        {
            if (!_service.IsAuthorizedRider(RequestData))
            {
                return(Unauthorized());
            }

            if (ModelState.IsValid)
            {
                // convert time back to local time,
                RequestData.RideStart = TimeZoneInfo.ConvertTimeFromUtc(RequestData.RideStart, TimeZoneInfo.Local);
                var ride = _service.AddRide(RequestData);
                return(Accepted(ride));
            }
            return(Unauthorized());
        }
コード例 #3
0
        public IActionResult Post([FromBody] EmployeeRideEditDto ride)
        {
            try
            {
                try
                {
                    return(Ok(rideService.AddRide(ride)));
                }
                catch
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(500));

                throw;
            }
        }
コード例 #4
0
        public async Task <IActionResult> OnPost(Ride ride)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Car car = carService.GetCar(ride.CarID);

            if (ride.SeatsAvailable <= car.NumberOfSeats)
            {
                rideService.AddRide(ride);
                return(RedirectToPage("GetRides"));
            }
            else
            {
                var user = await userManager.GetUserAsync(User);

                registeredCars = new SelectList(rideService.GetRegisteredCars(user.Id), "CarID", "NumberPlate");
                Message        = "The seats available cannot exceed the number of seats in your car.";
                return(Page());
            }
        }
コード例 #5
0
ファイル: dotSettings.cshtml.cs プロジェクト: Gradu5nik/Zuber
 public IActionResult OnPost()
 {
     if (!ModelState.IsValid)
     {
         return(Page());
     }
     userDot.ZuberUserID = User.User.Id;
     if (User.User.DotId.HasValue)
     {
         dService.UpdateDot(userDot);
     }
     else
     {
         dService.AddDot(userDot);
         Dot d = dService.GetDotByUserId(User.User.Id);
         uService.GiveUserDot(User.User, d.Id);
         User.Login(uService.GetZuberUserById(User.User.Id));
     }
     if (User.IsDriver)
     {
         userRide.DriverId = User.User.Id;
         if (User.User.RideId.HasValue)
         {
             rService.UpdateRide(userRide);
         }
         else
         {
             rService.AddRide(userRide);
             Ride r = rService.GetRideByUserId(User.User.Id);
             User.User.RideId = r.Id;
             uService.UpdateZuberUser(User.User);
             User.Login(uService.GetZuberUserById(User.User.Id));
         }
     }
     return(RedirectToPage("Index"));
 }
コード例 #6
0
        public void OfferRide()
        {
            int choice = commonMethods.ReadInt("Are you sure you want to offer a ride? >> 1. Yes 2. No : ");

            choice = commonMethods.IsValidChoice(choice);
            if (choice == 2)
            {
                commonMethods.FurtherAction(1);
            }
            Ride ride = new Ride();

            ride.Id          = Guid.NewGuid().ToString();
            ride.PickUp      = commonMethods.ReadString("Enter your source of ride : ");
            ride.Drop        = commonMethods.ReadString("Enter your destination of ride : ");
            ride.Date        = ReadDateTime();
            ride.PublisherId = LoginActions.currentUser.Id;

            List <VehicleType> vehicleTypes = vehicleTypeService.GetAllTypes();
            int count = 0;

            Console.WriteLine("Serial Number | Type \t | Maximum Fare | Maximum Seats");
            foreach (VehicleType vehicleType in vehicleTypes)
            {
                ++count;
                Console.WriteLine(count + "\t" + vehicleType.Type + "" + vehicleType.MaximumFare + "\t" + vehicleType.MaximumSeats);
            }

            int vehicleTypeChoice = commonMethods.ReadInt("Choose your vehicle type from above types : ");

            while (vehicleTypeChoice < 0 || vehicleTypeChoice > count)
            {
                vehicleTypeChoice = commonMethods.ReadInt("Please enter a valid choice : ");
            }
            ride.VehicleType   = vehicleTypes[vehicleTypeChoice - 1];
            ride.NumberOfSeats = commonMethods.ReadInt("Enter the number of seats available for the ride : ");
            while (ride.NumberOfSeats > ride.VehicleType.MaximumSeats || ride.NumberOfSeats < 1)
            {
                if (ride.NumberOfSeats < 1)
                {
                    Console.WriteLine("There should be atleast one seat in the ride");
                }
                else
                {
                    Console.WriteLine("You cannot have more than " + ride.VehicleType.MaximumSeats + " seats");
                }
                ride.NumberOfSeats = commonMethods.ReadInt(" Please enter valid number of seats : ");
            }
            ride.AvailableSeats = ride.NumberOfSeats;
            int autoApprove = commonMethods.ReadInt("Auto-approve the bookings ? 1. Yes 2. No >> ");

            autoApprove          = commonMethods.IsValidChoice(autoApprove);
            ride.AutoApproveRide = (autoApprove == 1) ? true : false;

            ride.Price = commonMethods.ReadDouble("Enter the price of the ride : ");
            while (ride.Price > ride.VehicleType.MaximumFare)
            {
                Console.WriteLine("Fare for the ride should not be greater than " + ride.VehicleType.MaximumFare);
                ride.Price = commonMethods.ReadDouble("Please enter a valid price : ");
            }

            ride.Status = (RideStatus)0;

            List <Vehicle> vehicles = vehicleService.GetVehiclesByUserId(LoginActions.currentUser.Id);

            if (vehicles.Count == 1)
            {
                Console.WriteLine(" Vehicle Model : " + vehicles[0].Model);
                choice = commonMethods.ReadInt("Do you want to offer ride with above vehicle : 1. Yes 2. No >> ");
                choice = commonMethods.IsValidChoice(choice);
                if (choice == 1)
                {
                    ride.Vehicle = vehicles[0];
                }
                else
                {
                    ride.Vehicle = vehicleActions.AddVehicle();
                }
            }
            else if (vehicles.Count == 0)
            {
                ride.Vehicle = vehicleActions.AddVehicle();
            }
            else
            {
                int optionNumber = 1;
                foreach (Vehicle vehicle in vehicles)
                {
                    Console.WriteLine(optionNumber + ". Vehicle Model : " + vehicle.Model);
                }
                choice = commonMethods.ReadInt("Do you want to use any of the above vehicles : 1. Yes 2. No >> ");
                choice = commonMethods.IsValidChoice(choice);
                if (choice == 1)
                {
                    int vehicleChoice = commonMethods.ReadInt("Enter the vehicle number you want to choose : ");
                    while (vehicleChoice < 1 || vehicleChoice > optionNumber)
                    {
                        vehicleChoice = commonMethods.ReadInt("Please enter a valid option : ");
                    }
                    ride.Vehicle.Id = vehicles[optionNumber - 1].Id;
                }
                else
                {
                    Console.WriteLine("Enter your new vehicle data");
                    ride.Vehicle = vehicleActions.AddVehicle();
                }
            }
            rideService.AddRide(ride);

            int viaPointsChoice = commonMethods.ReadInt("Do you want to add Via Points ? 1.Yes 2. No >> ");

            viaPointsChoice = commonMethods.IsValidChoice(viaPointsChoice);
            int    viaPointCount = 1;
            string viaPoint;

            ride.ViaPoints = new List <string>();

            while (viaPointsChoice == 1)
            {
                viaPoint = commonMethods.ReadString("Via Point " + viaPointCount + " : ");
                if (ride.ViaPoints.Contains(viaPoint))
                {
                    Console.WriteLine("You have already added this via point!!");
                }
                else
                {
                    ride.ViaPoints.Add(viaPoint);
                }
                viaPointsChoice = commonMethods.ReadInt("Add one more Via Point ? 1.Yes 2. No >> ");
                viaPointsChoice = commonMethods.IsValidChoice(viaPointsChoice);
                viaPointCount  += 1;
            }


            Console.WriteLine("Ride added successfully!!");
            commonMethods.FurtherAction(1);
        }