public string InsertMotorbike(Motorbike motorbike, int s, int p, DateTime t)
        {
            if (s > this.layout.sectors)
            {
                return(string.Format("There is no sector {0} in the park", s));
            }

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

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

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

            this.data.AllCarsInPark[motorbike] = string.Format("({0},{1})", s, p);
            this.data.ParkPlace[string.Format("({0},{1})", s, p)] = motorbike;
            this.data.LicensePlate[motorbike.LicensePlate]        = motorbike;
            this.data.D[motorbike] = t;
            this.data.Owner[motorbike.Owner].Add(motorbike);
            this.data.count[s - 1]++;
            return(string.Format("{0} parked successfully at place ({1},{2})", motorbike.GetType().Name, s, p));
        }
Пример #2
0
        public string InsertMotorbike(Motorbike motorbike, int sector, int place, DateTime time)
        {
            if (sector > this.layout.Sectors)
            {
                return($"There is no sector {sector} in the park");
            }

            if (place > this.layout.PlacesSec)
            {
                return($"There is no place {place} in sector {sector}");
            }

            if (this.repository.Park.ContainsKey($"({sector},{place})"))
            {
                return($"The place ({sector},{place}) is occupied");
            }

            if (this.repository.Numbers.ContainsKey(motorbike.LicensePlate))
            {
                return($"There is already a vehicle with license plate {motorbike.LicensePlate} in the park");
            }

            this.repository.CarsInPark[motorbike]           = $"({sector},{place})";
            this.repository.Park[$"({sector},{place})"]     = motorbike;
            this.repository.Numbers[motorbike.LicensePlate] = motorbike;
            this.repository.DateParkDictionary[motorbike]   = time;
            this.repository.OwnersMultiDictionary[motorbike.Owner].Add(motorbike);
            this.repository.Count[sector - 1]++;
            return($"{motorbike.GetType().Name} parked successfully at place ({sector},{place})");
        }
Пример #3
0
        public string InsertMotorbike(Motorbike motorbike, int sector, int place, DateTime time)
        {
            if (sector > this.parkSize.NumberOfSectors)
            {
                return(string.Format("There is no sector {0} in the park", sector));
            }

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

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

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

            this.vehicleDatabase.VehiclesPark[motorbike] = string.Format("({0},{1})", sector, place);
            this.vehicleDatabase.Park[string.Format("({0},{1})", sector, place)]    = motorbike;
            this.vehicleDatabase.VehiclesRegistrationNumber[motorbike.LicensePlate] = motorbike;
            this.vehicleDatabase.DateAndTime[motorbike] = time;
            this.vehicleDatabase.VehicleOwner[motorbike.Owner].Add(motorbike);
            this.vehicleDatabase.VehiclesCount[sector - 1]++;

            return(string.Format("{0} parked successfully at place ({1},{2})", motorbike.GetType().Name, sector, place));
        }
Пример #4
0
        /// <summary>
        /// The method corespond the Parking a motorbike in the VehiclePark.
        /// It also is responsible for the managing the application data.
        /// </summary>
        /// <param name="moto">A Motorbike object which was generated with a specific data</param>
        /// <param name="sector">The secor the motorbike may be parked.</param>
        /// <param name="place">The place in the sector where the motorbike may be parked</param>
        /// <param name="time">The time the motorbike is parking</param>
        /// <returns></returns>
        public string InsertMotorbike(Motorbike moto, string sector, string place, string time)
        {
            int      rawSector = 0;
            int      rawPlace  = 0;
            DateTime rawtime   = DateTime.MinValue;

            // PERFORMANCE: Making so many checks in the data collection, would hit the performance hard if there are a lot of entires(spaces in the park)
            // theoretically speaking i doubt there is a vehicle park with more than 1000 park spaces, but i might be wrong.
            if (moto == null)
            {
                return("There is a problem with your variables, please check your sector,place or time.");
            }

            if (!int.TryParse(sector, out rawSector) || !int.TryParse(place, out rawPlace) || !DateTime.TryParse(time, out rawtime))
            {
                return("There is a problem with your variables, please check your sector,place or time.");
            }

            if (rawSector > StaticData.ApplicationData.VehicleParkslots.Keys.Count())
            {
                return(string.Format("There is no sector {0} in the park", rawSector));
            }

            if (rawPlace > StaticData.ApplicationData.VehicleParkslots.FirstOrDefault().Value.Keys.Count())
            {
                return(string.Format("There is no place {0} in sector {1}", rawPlace, rawSector));
            }

            if (StaticData.ApplicationData.VehicleParkslots[rawSector][rawPlace] != null)
            {
                return(string.Format("The place ({0},{1}) is occupied", rawSector, rawPlace));
            }

            if (StaticData.ApplicationData.Vehicles.FirstOrDefault(v => v.LicensePlate.Equals(moto.LicensePlate)) != null)
            {
                return(string.Format("There is already a vehicle with license plate {0} in the park", moto.LicensePlate));
            }

            StaticData.ApplicationData.Vehicles.Add(moto);
            moto.RegistrationDate = rawtime;
            moto.ParkedSector     = rawSector;
            moto.ParkedPlace      = rawPlace;
            StaticData.ApplicationData.VehicleParkslots[rawSector][rawPlace] = moto;

            return(string.Format("{0} parked successfully at place ({1},{2})", moto.GetType().Name, rawSector, rawPlace));
        }