Esempio n. 1
0
        public CityUpdateResponse UpdateCity(CityUpdateRequest request)
        {
            if (request.City.CurrentCityStorage != null)
                UpdateCityStorage(request.City.CurrentCityStorage);
            var repoRequest = new RepositoryRequest<BuildingUpgrade>
            {
                Expression = GetBuildingUpgradeExpression()
            };
            var result = _cityUpdateUnitOfWork.BuildingUpgradeRepository.Get(repoRequest);
            foreach (var dUpgrade in result)
            {
                if (request.City.BuildingUpgrades.Any(x=>x.Id == dUpgrade.Id))
                    continue;
                dUpgrade.Completed = true;
            }
            foreach (var upgrade in request.City.BuildingUpgrades)
            {

                var domainUpgrade = result.FirstOrDefault(x=> x.Id==upgrade.Id);

                if (domainUpgrade == null)
                {
                    domainUpgrade = Mapper.Map<BuildingUpgrade>(upgrade);
                    _cityUpdateUnitOfWork.BuildingUpgradeRepository.Add(domainUpgrade);
                }
                else
                {
                    var changedUpgrade = Mapper.Map<BuildingUpgrade>(upgrade);
                    _cityUpdateUnitOfWork.EntityContext.SetValues(domainUpgrade, changedUpgrade);
                }

                if (domainUpgrade.Products == null)
                    domainUpgrade.Products = new List<Product>();
                DataCollectionMapper.MapCollection(upgrade.Products.Select(Mapper.Map<Product>).ToList(), domainUpgrade.Products, new CollectionMapperOptions
                {
                    Context = _cityUpdateUnitOfWork.EntityContext
                });
            }

            _cityUpdateUnitOfWork.Commit();

            return new CityUpdateResponse();
        }
 public CityUpdateResponse UpdateCity(CityUpdateRequest request)
 {
     throw new System.NotImplementedException();
 }
Esempio n. 3
0
        // POST api/city
        public City Post([FromBody]City value)
        {
            var ret = LogHelper.StartLog("CityController Post", Logger);
            if (value==null)
                throw new ApplicationException("Null Data passed to save city.");
            var mappedCity = Mapper.Map<Handler.Entities.City>(value);
            var request = new HandlerEntities.CityUpdateRequest
            {
                City = mappedCity
            };
            _cityUpdateHandler.UpdateCity(request);
            LogHelper.EndLog(ret);
            var city = Get();

            UpdateIncludeInBuildingUpgradesFlag(value, city);
            CalculateBuildQueue(mappedCity, city);

            return LogHelper.EndLog(ret, city);
        }