private void InitializeParkSpots()
        {
            var vehicles = _context.ParkedVehicles.ToList();

            for (var i = 0; i < vehicles.Count(); i++)
            {
                if (vehicles[i].VehicleTypeId == _context.VehicleTypes.FirstOrDefault(v => v.Name == "Truck").Id)
                {
                    ParkOnMultipleSpots(vehicles[i], 3);
                }
                else
                {
                    if (vehicles[i].VehicleTypeId == _context.VehicleTypes.FirstOrDefault(v => v.Name == "Bus").Id)
                    {
                        ParkOnMultipleSpots(vehicles[i], 2);
                    }
                    else
                    {
                        var vehicleIsMotorcycle = vehicles[i].VehicleTypeId == _context.VehicleTypes.FirstOrDefault(v => v.Name == "Motorcycle").Id;
                        var spot = ParkingSpotContainer.GetAvailableSpot(parkSpots, vehicleIsMotorcycle);

                        spot.Park(vehicles[i]);
                        spot.VehicleCount  += 1;
                        spot.HasMotorcycles = vehicleIsMotorcycle;
                        parkSpots[spot.Id]  = spot;
                    }
                }
            }
            ParkingSpotContainer.IsInitialized = true;
        }
Example #2
0
        private async Task ParkVehicleInBackend(ParkSpot[] parkSpots, ParkedVehicle vehicle)
        {
            var vehicleType = await _context.VehicleTypes.Where(v => v.Id == vehicle.VehicleTypeId).FirstOrDefaultAsync();

            int numberRequired = GetRequiredNumberOfSpots(vehicleType);
            int startOfSpotSequence;

            if (vehicleType.Name == "Motorcycle")
            {
                {
                    var spot = ParkingSpotContainer.GetAvailableSpot(parkSpots, true);
                    if (spot != null)
                    {
                        spot.Park(vehicle);
                        spot.VehicleCount++;
                        spot.HasMotorcycles = true;
                    }
                }
            }
            else if (vehicleType.Name != "Motorcycle" && ParkingSpotContainer.FindConsecutiveSpots(numberRequired, out startOfSpotSequence))
            {
                ParkingSpotContainer.ParkOnMultipleSpots(startOfSpotSequence, numberRequired, vehicle);
            }
        }