Beispiel #1
0
        public void Initialize(Language language)
        {
            var territoryList = _territoryTypeRepository.GetAll();

            foreach (var territoryType in territoryList)
            {
                PlaceName regionPlaceName;
                try
                {
                    var regionPlaceNameKey = territoryType.RegionPlaceNameId;
                    var regionNameValue    = _placeNameRepository.Find(pn => pn.Id == territoryType.RegionPlaceNameId)
                                             .First()?.Localized[language.Index].Name;
                    regionPlaceName = new PlaceName(regionPlaceNameKey, regionNameValue);
                }
                catch (Exception)
                {
                    regionPlaceName = null;
                }

                PlaceName zonePlaceName;
                try
                {
                    var zonePlaceNameKey = territoryType.ZonePlaceNameId;
                    var zoneNameValue    = _placeNameRepository.Find(pn => pn.Id == territoryType.ZonePlaceNameId).First()
                                           ?.Localized[language.Index].Name;
                    zonePlaceName = new PlaceName(zonePlaceNameKey, zoneNameValue);
                }
                catch (Exception)
                {
                    zonePlaceName = null;
                }


                PlaceName mapPlaceName;
                try
                {
                    var map               = _mapRepository.Find(m => m.Id == territoryType.MapId).First();
                    var mapPlaceNameKey   = map.MapPlaceNameId;
                    var mapPlaceNameValue = _placeNameRepository.Find(pn => pn.Id == mapPlaceNameKey).First()
                                            ?.Localized[language.Index].Name;
                    mapPlaceName = new PlaceName(mapPlaceNameKey, mapPlaceNameValue);
                }
                catch (Exception)
                {
                    mapPlaceName = null;
                }

                PlaceName territoryPlaceName;
                try
                {
                    var territoryPlaceNameKey = territoryType.TerritoryPlaceNameId;
                    var territoryNameValue    = _placeNameRepository
                                                .Find(pn => pn.Id == territoryType.TerritoryPlaceNameId)
                                                .First()?.Localized[language.Index].Name;
                    territoryPlaceName = new PlaceName(territoryPlaceNameKey, territoryNameValue);
                }
                catch (Exception)
                {
                    territoryPlaceName = null;
                }

                var location = new Location
                {
                    TerritoryTypeId = territoryType.Id,
                    Region          = regionPlaceName,
                    Zone            = zonePlaceName,
                    Territory       = territoryPlaceName,
                    Map             = mapPlaceName
                };

                if (location.Region == null && location.Zone == null)
                {
                    continue;
                }
                _locations.Add(location);
            }
        }