Example #1
0
 public string InsertTruck(Truck truck, int sector, int placeNumber, DateTime startTime)
 {
     return this.InsertVehicle(truck, sector, placeNumber, startTime);
 }
        public string InsertTruck(Truck truck, int sector, int place, DateTime time)
        {
            if (sector > this.layout.Sectors)
            {
                return string.Format("There is no sector {0} in the park", sector);
            }

            if (place > this.layout.PlacesPerSector)
            {
                return string.Format("There is no place {0} in sector {1}", place, sector);
            }

            if (this.data.VehiclesBySectorAndPlace.ContainsKey(string.Format("({0},{1})", sector, place)))
            {
                return string.Format("The place ({0},{1}) is occupied", sector, place);
            }

            if (this.data.VehiclesByLicensePlate.ContainsKey(truck.LicensePlate))
            {
                return string.Format(
                    "There is already a vehicle with license plate {0} in the park",
                    truck.LicensePlate);
            }

            this.data.SectorAndPlaceByVehicle[truck] = string.Format("({0},{1})", sector, place);
            this.data.VehiclesBySectorAndPlace[string.Format("({0},{1})", sector, place)] = truck;
            this.data.VehiclesByLicensePlate[truck.LicensePlate] = truck;
            this.data.TimesByVehicles[truck] = time;
            this.data.VehiclesByOwner[truck.Owner].Add(truck);
            this.data.PlacesTakenInSectors[sector - 1]++;
            // TODO: available places ++
            return string.Format("{0} parked successfully at place ({1},{2})", truck.GetType().Name, sector, place);
        }
 public string InsertTruck(Truck truck, int sector, int placeNumber, DateTime startTime)
 {
     return(this.InsertVehicle(truck, sector, placeNumber, startTime));
 }