public City Get(SupplyChainRequest request)
        {
            var logStart = LogHelper.StartLog("Begin Supply Chain Get", Logger);
            //Get the current city from the database.
            var currentCity = ConvertRequestToHandlerCity(request);
            var prodTypes = _dbContext.ProductTypes
                                    .AsQueryable()
                                    .Include(x=>x.RequiredProducts)
                                    .Include(y=>y.ManufacturerType.ProductTypes)
                                    .ToArray();

            var calcRequest = new BuildingUpgradeHandlerRequest
            {
                ReturnInventory = true,
                ReturnFaciltiyAssignment = request.ReturnFacilityAssignment,
                City = Mapper.Map<Handler.Entities.City>(currentCity),
                ProductTypes = prodTypes
            };
            var strgResults = CalculateNewCityStorageAmounts(request, calcRequest, prodTypes);

            var ret = _buldingUpgradeHandler.CalculateBuildQueue(calcRequest);

            var city = new City
            {
                CurrentCityStorage = Mapper.Map<CityStorage>(strgResults.CityStorage),
                RequiredProducts = ret.RequiredProductQueue.Select(Mapper.Map<Product>).ToArray(),
                RequiredProductsInCityStorage = ret.RequiredProductsInCityStorageQueue.Select(Mapper.Map<Product>).ToArray(),
                TotalProducts = ret.TotalProductQueue.Select(Mapper.Map<Product>).ToArray(),
                AvailableStorage = ret.AvailableStorage.Select(Mapper.Map<Product>).ToArray(),
                BuildingUpgrades = ret.OrderedUpgrades.Select(Mapper.Map<BuildingUpgrade>).ToArray().OrderBy(x=>x.Name).ToArray()
            };
            UpdateBuildingUpgradeUiInfo(prodTypes, city);
            return LogHelper.EndLog(logStart, city);
        }
 private CalculateStorageResponse CalculateNewCityStorageAmounts(SupplyChainRequest request, BuildingUpgradeHandlerRequest calcRequest, ProductType[] productTypes)
 {
     var strgResults = new CalculateStorageResponse
     {
         CityStorage = calcRequest.City.CurrentCityStorage
     };
     //If we have products queued for production then calculate the new city storage.
     if (request.RequiredProductUpdates == null) return strgResults;
     var calculateStorageRequest = new CalculateStorageRequest
     {
         ProductTypes = productTypes,
         NewProductQuantities = request.RequiredProductUpdates.Select(Mapper.Map<Handler.Entities.Product>).ToArray(),
         CityStorage = calcRequest.City.CurrentCityStorage
     };
     return _cityStorageCalculator.CalculateNewStorageAmounts(calculateStorageRequest);
 }
        private static City ConvertRequestToHandlerCity(SupplyChainRequest request)
        {
            var buildingUpgrades = request.BuildingUpgrades ?? new BuildingUpgrade[0];
            var cityStorageUpgrade = buildingUpgrades.FirstOrDefault(x => x.Name.Equals("City Storage"));
            var currentCityStorage = request.CurrentCityStorage ?? new CityStorage
            {
                CurrentInventory = cityStorageUpgrade == null ? new Product[0] : cityStorageUpgrade.Products
            };

            return new City
            {
                Manufacturers = new Manufacturer[0],
                BuildingUpgrades = buildingUpgrades.Where(x => x.Name != "City Storage").ToArray(),
                CurrentCityStorage = currentCityStorage
            };
        }