public ParkingInfo GetTotalCountOfParkingTypeSlots() { if (_cache.Contains(TotalCountKey)) { return((ParkingInfo)_cache.Get(TotalCountKey)); } else { Dictionary <string, int> slotTypes = new Dictionary <string, int> { { "Small", 50 }, { "Medium", 30 }, { "Large", 10 } }; ParkingInfo parkingInfo = new ParkingInfo { TotalParkingSlots = 100, SlotTypes = slotTypes }; _cache.Add(TotalCountKey, parkingInfo, _cacheItemPolicy); return(parkingInfo); } }
public void UpdateParkingInfo(ParkingInfo parkingInfo) { _cache.Add(TotalCountKey, parkingInfo, _cacheItemPolicy); }
public ParkingInfoRepository() { _parkingInfo = GetTotalCountOfParkingTypeSlots(); }
public CarsInfo AssignParkingSlotToCar(CarsInfo carsInfo) { int slotCount = 0; double percentSlotAvailable; ParkingInfo parkingInfo = _parkingInfoRepository.GetTotalCountOfParkingTypeSlots(); List <int> lstParkingSlots = new List <int>(); Dictionary <string, Dictionary <string, int> > dctCarWiseslots; Dictionary <string, int> dctSlotType = new Dictionary <string, int>(); Dictionary <string, int> initialSlotCounts; if (parkingInfo.SlotTypes != null) { carsInfo.IsParkingSlotAvailable = false; dctCarWiseslots = _parkingInfoRepository.GetSetCarWiseSlotTypes(carsInfo.CarType); if (dctCarWiseslots != null && dctCarWiseslots.Count > 0) { if (dctCarWiseslots.ContainsKey(carsInfo.CarType)) { dctCarWiseslots.TryGetValue(carsInfo.CarType, out dctSlotType); if (dctSlotType != null && dctSlotType.Count > 0) { initialSlotCounts = _parkingInfoRepository.GetInitialSlotCount(); foreach (string slotNamekey in dctSlotType.Keys) { parkingInfo.SlotTypes.TryGetValue(slotNamekey, out slotCount); percentSlotAvailable = (Convert.ToDouble(slotCount) / initialSlotCounts[slotNamekey]) * 100; if (percentSlotAvailable > 0 && percentSlotAvailable >= dctSlotType[slotNamekey]) { carsInfo.CarParkingSlotType = slotNamekey; lstParkingSlots = _parkingInfoRepository.GetParkingSlotsList(slotNamekey); carsInfo.CarParkingSlotNumber = lstParkingSlots[rnd.Next(lstParkingSlots.Count)]; carsInfo.IsParkingSlotAvailable = true; } return(carsInfo); } } } } carsInfo.IsParkingSlotAvailable = false; return(carsInfo); //percentSmallSlotAvailable = (Convert.ToDouble(smallSlotCount) / 50) * 100; //percentMediumSlotAvailable = (Convert.ToDouble(mediumSlotCount) / 30) * 100; //percentLargeSlotAvailable = (Convert.ToDouble(largeSlotCount) / 10) * 100; //if (carsInfo.CarType.Equals("Hatchback", StringComparison.InvariantCultureIgnoreCase) || carsInfo.CarType.Equals("Two Wheeler", StringComparison.InvariantCultureIgnoreCase)) //{ // if (percentSmallSlotAvailable > 0) // { // carsInfo.CarParkingSlotType = "Small"; // lstParkingSlots = _parkingInfoRepository.GetParkingSlotsList("Small"); // carsInfo.CarParkingSlotNumber = lstParkingSlots[rnd.Next(lstParkingSlots.Count)]; // //carsInfo.CarParkingSlotNumber = (50 - smallSlotCount); // } // else if(percentMediumSlotAvailable > 0) // { // carsInfo.CarParkingSlotType = "Medium"; // lstParkingSlots = _parkingInfoRepository.GetParkingSlotsList("Medium"); // carsInfo.CarParkingSlotNumber = lstParkingSlots[rnd.Next(lstParkingSlots.Count)]; // //carsInfo.CarParkingSlotNumber = (30 - mediumSlotCount); // } // else if(percentLargeSlotAvailable > 10) // { // carsInfo.CarParkingSlotType = "Large"; // lstParkingSlots = _parkingInfoRepository.GetParkingSlotsList("Large"); // carsInfo.CarParkingSlotNumber = lstParkingSlots[rnd.Next(lstParkingSlots.Count)]; // //carsInfo.CarParkingSlotNumber = (20 - largeSlotCount); // } // else // { // carsInfo.IsParkingSlotAvailable = false; // } //} //else if(carsInfo.CarType.Equals("Sedan/Compact SUV", StringComparison.InvariantCultureIgnoreCase)) //{ // if (percentMediumSlotAvailable > 0) // { // carsInfo.CarParkingSlotType = "Medium"; // lstParkingSlots = _parkingInfoRepository.GetParkingSlotsList("Medium"); // carsInfo.CarParkingSlotNumber = lstParkingSlots[rnd.Next(lstParkingSlots.Count)]; // //carsInfo.CarParkingSlotNumber = (30 - mediumSlotCount); // } // else if (percentLargeSlotAvailable > 10) // { // carsInfo.CarParkingSlotType = "Large"; // lstParkingSlots = _parkingInfoRepository.GetParkingSlotsList("Large"); // carsInfo.CarParkingSlotNumber = lstParkingSlots[rnd.Next(lstParkingSlots.Count)]; // //carsInfo.CarParkingSlotNumber = (20 - largeSlotCount); // } // else // { // carsInfo.IsParkingSlotAvailable = false; // } //} //else if (carsInfo.CarType.Equals("SUV or Large cars", StringComparison.InvariantCultureIgnoreCase) || carsInfo.CarType.Equals("Truck", StringComparison.InvariantCultureIgnoreCase)) //{ // if (percentLargeSlotAvailable > 0) // { // carsInfo.CarParkingSlotType = "Large"; // lstParkingSlots = _parkingInfoRepository.GetParkingSlotsList("Large"); // carsInfo.CarParkingSlotNumber = lstParkingSlots[rnd.Next(lstParkingSlots.Count)]; // //carsInfo.CarParkingSlotNumber = (20 - largeSlotCount); // } // else // { // carsInfo.IsParkingSlotAvailable = false; // } //} //else //{ // carsInfo.IsParkingSlotAvailable = false; //} } if (carsInfo.IsParkingSlotAvailable) { // carsInfo.CarParkingSlotNumber += 1; } return(carsInfo); }