public ActionResult SelectAParkingSpot(SelectAParkingSpotVM viewModel) { Vehicle vehicle = new GarageController().Vehicle(viewModel.VehicleID); if (vehicle == null) { return(RedirectToAction("BookAParkingSpot", "Vehicles", new { checkIn = viewModel.CheckIn, errorMessage = "You must select a vehicle!" })); } ParkingSpot parkingSpot = db.ParkingSpot(viewModel.ParkingSpotID); if (parkingSpot == null) { return(RedirectToAction("SelectAParkingSpot", new { vehicleId = viewModel.VehicleID, checkIn = viewModel.CheckIn, errorMessage = "You must select a parking spot!" })); } if (viewModel.CheckIn) { return(RedirectToAction("VehicleCheckedIn", "CheckIns", new SelectAParkingSpotVM { CheckIn = true, ParkingSpotID = viewModel.ParkingSpotID, VehicleID = viewModel.VehicleID })); } else { return(RedirectToAction("ParkingSpotBooked", "CheckIns", new SelectAParkingSpotVM { ParkingSpotID = viewModel.ParkingSpotID, VehicleID = viewModel.VehicleID })); } }
public ActionResult VehicleCheckedIn(SelectAParkingSpotVM viewModel) { // Check that the vehicle isn't already parked/hasn't booked a place if (db.CheckInByVehicle(viewModel.VehicleID) != null) { return(RedirectToAction("Index", "Garage")); } Vehicle vehicle = new GarageController().Vehicle(viewModel.VehicleID); if (vehicle == null) { return(RedirectToAction("BookAParkingSpot", "Vehicles", new { checkIn = viewModel.CheckIn, errorMessage = "You must select a vehicle!" })); } // Check in the vehicle ID to the parking spot ParkingSpot parkingSpot = new GarageController().ParkingSpot(viewModel.ParkingSpotID); if (parkingSpot == null) { return(RedirectToAction("CheckInAVehicle", new { vehicleId = viewModel.VehicleID, errorMessage = "You must select a parking spot!" })); } CheckIn checkIn = db.CheckIn(viewModel.VehicleID, viewModel.ParkingSpotID); checkIn.Vehicle = vehicle; checkIn.ParkingSpot = parkingSpot; // Displays the chosen parking spot return(View(checkIn)); }
public ActionResult SelectAParkingSpot(int?vehicleId, bool checkIn, string errorMessage) { if (vehicleId == null) { return(RedirectToAction("BookAParkingSpot", "Vehicles", new { errorMessage = "You must select a vehicle!" })); } Vehicle vehicle = new GarageController().Vehicle(vehicleId); if (vehicle == null) { return(RedirectToAction("BookAParkingSpot", "Vehicles", new { errorMessage = "You must select a vehicle!" })); } // Allows the user to select an available parking spot (if any), depending on the type of vehicle return(View(new SelectAParkingSpotVM { VehicleID = (int)vehicleId, SelectedVehicle = vehicle, CheckIn = checkIn, ErrorMessage = errorMessage, ParkingSpots = new CheckInsParkingSpots().AvailableParkingSpots(vehicle.VehicleTypeID) })); }