Ejemplo n.º 1
0
        public ActionResult Search(string searchedValue, string sortOrder)
        {
            if (string.IsNullOrEmpty(searchedValue))
            {
                return(RedirectToAction("Index"));
            }

            List <DetailsParkingSpotVM> foundParkingSpots      = new List <DetailsParkingSpotVM>();
            ParkingSpotsController      parkingSpotsController = new ParkingSpotsController();

            foreach (ParkingSpot foundParkingSpot in parkingSpotsController.Sort(parkingSpots.ParkingSpotsByIdentifiant(searchedValue), sortOrder))
            {
                CheckIn checkIn = checkIns.CheckInByParkingSpot(foundParkingSpot.ID);

                foundParkingSpots.Add(new DetailsParkingSpotVM
                {
                    Availability = new CheckInsParkingSpots().Availability(checkIn),
                    ParkingSpot  = foundParkingSpot,
                    CheckIn      = checkIn
                });
            }

            Dictionary <int, CheckIn> dicParkingSpotsVehicles = new Dictionary <int, CheckIn>();

            IEnumerable <Vehicle> foundVehicles = Sort(vehicles.VehiclesByRegistrationPlate(searchedValue), sortOrder);

            foreach (Vehicle vehicle in foundVehicles)
            {
                dicParkingSpotsVehicles.Add(vehicle.ID, checkIns.CheckInByVehicle(vehicle.ID));
            }

            return(View(new SearchResultsVM
            {
                SearchedValue = searchedValue,
                FoundVehicles = new DisplayVehiclesVM
                {
                    ViewName = "Search",
                    Vehicles = foundVehicles,
                    ParkingSpotsVehicles = dicParkingSpotsVehicles
                },
                FoundParkingSpots = foundParkingSpots
            }));
        }