コード例 #1
0
        public ActionResult Index()
        {
            var model = new IndexModel();

            var parkingAreasInformation = _availabilityService.GetResponse(CacheBehavior.Ignore);

            var parkingAreasWithAvailableSpaces =
                parkingAreasInformation.ParkingAreaNewList.Where(
                    parkingArea => parkingArea.ParkingSpacesAvailable > 0);

            foreach (var parkingArea in parkingAreasWithAvailableSpaces)
            {
                AddParkingAreaToDisplay(parkingArea, model);
            }

            return View("Index", model);
        }
コード例 #2
0
        private void AddParkingAreaToDisplay(Parkingareanewlist parkingList, IndexModel model)
        {
            // This code suffers from SELECT N+1 issues. Now you know that I know that you know that we know.
            var priceInfo = _proxyService.GetPrice(parkingList.Id);

            model.ParkingAreas.Add(
                new ParkingArea()
                {
                    Name = parkingList.Name,
                    ParkingAreaId = parkingList.Id,
                    IsPriceUnknown = priceInfo == null,
                    PricePerHour = priceInfo ?? 0,
                    AvailableSpaces = Enumerable.Repeat(new Parkingspace(), parkingList.ParkingSpacesAvailable).ToList(),
                });
        }