//Get PseudoCityOrOfficeAddressCountryGlobalRegion for JSON public List <PseudoCityOrOfficeAddressCountryGlobalRegionJSON> GetPseudoCityOrOfficeAddressCountryGlobalRegion(int pseudoCityOrOfficeAddressId) { List <PseudoCityOrOfficeAddressCountryGlobalRegionJSON> pseudoCityOrOfficeAddressCountryGlobalRegionJSONs = new List <PseudoCityOrOfficeAddressCountryGlobalRegionJSON>(); PseudoCityOrOfficeAddress pseudoCityOrOfficeAddress = new PseudoCityOrOfficeAddress(); pseudoCityOrOfficeAddress = GetPseudoCityOrOfficeAddress(pseudoCityOrOfficeAddressId); if (pseudoCityOrOfficeAddress != null) { string globalSubRegionCode = pseudoCityOrOfficeAddress.Country.GlobalSubRegionCode; GlobalSubRegion globalSubRegion = hierarchyRepository.GetGlobalSubRegion(globalSubRegionCode); if (globalSubRegion != null) { GlobalRegion globalRegion = hierarchyRepository.GetGlobalRegion(globalSubRegion.GlobalRegionCode); if (globalRegion != null) { PseudoCityOrOfficeAddressCountryGlobalRegionJSON pseudoCityOrOfficeAddressCountryGlobalRegionJSON = new PseudoCityOrOfficeAddressCountryGlobalRegionJSON() { CountryCode = pseudoCityOrOfficeAddress.Country.CountryCode, CountryName = pseudoCityOrOfficeAddress.Country.CountryName, GlobalRegionCode = globalRegion.GlobalRegionCode, GlobalRegionName = globalRegion.GlobalRegionName }; pseudoCityOrOfficeAddressCountryGlobalRegionJSONs.Add(pseudoCityOrOfficeAddressCountryGlobalRegionJSON); } } } return(pseudoCityOrOfficeAddressCountryGlobalRegionJSONs); }
//Get single item public PolicyLocation GetPolicyLocation(int policyLocationId) { HierarchyRepository hierarchyRepository = new HierarchyRepository(); CountryRepository countryRepository = new CountryRepository(); CityRepository cityRepository = new CityRepository(); PolicyLocation policyLocation = new PolicyLocation(); policyLocation = db.PolicyLocations.SingleOrDefault(c => c.PolicyLocationId == policyLocationId); if (policyLocation != null) { if (policyLocation.GlobalFlag) { policyLocation.LocationType = "Global"; } else if (policyLocation.CityCode != null) { policyLocation.LocationType = "City"; City city = cityRepository.GetCity(policyLocation.CityCode); Country country = countryRepository.GetCountry(city.CountryCode); policyLocation.ParentName = country.CountryName; } else if (policyLocation.CountryCode != null) { policyLocation.LocationType = "Country"; Country country = countryRepository.GetCountry(policyLocation.CountryCode); GlobalSubRegion globalSubRegion = hierarchyRepository.GetGlobalSubRegion(country.GlobalSubRegionCode); policyLocation.ParentName = globalSubRegion.GlobalSubRegionName; } else if (policyLocation.GlobalSubRegionCode != null) { policyLocation.ParentName = "GlobalSubRegion"; GlobalSubRegion globalSubRegion = hierarchyRepository.GetGlobalSubRegion(policyLocation.GlobalSubRegionCode); GlobalRegion globalRegion = hierarchyRepository.GetGlobalRegion(globalSubRegion.GlobalRegionCode); policyLocation.ParentName = globalRegion.GlobalRegionName; } else if (policyLocation.GlobalRegionCode != null) { policyLocation.LocationType = "GlobalRegion"; GlobalRegion globalRegion = hierarchyRepository.GetGlobalRegion(policyLocation.GlobalRegionCode); policyLocation.ParentName = globalRegion.Global.GlobalName; } } return(policyLocation); }
//Add Data From Linked Tables for Display public void EditForDisplay(PolicyLocation policyLocation) { if (policyLocation.TravelPortCode != null) { TravelPortRepository travelPortRepository = new TravelPortRepository(); TravelPort travelPort = new TravelPort(); travelPort = travelPortRepository.GetTravelPort(policyLocation.TravelPortCode); if (travelPort != null) { policyLocation.TravelPortName = travelPort.TravelportName; policyLocation.LocationCode = travelPort.TravelPortCode; policyLocation.LocationName = travelPort.TravelportName; } } if (policyLocation.TravelPortTypeId != null) { int travelPortTypeId = (int)policyLocation.TravelPortTypeId; TravelPortTypeRepository travelPortTypeRepository = new TravelPortTypeRepository(); TravelPortType travelPortType = new TravelPortType(); travelPortType = travelPortTypeRepository.GetTravelPortType(travelPortTypeId); if (travelPortType != null) { policyLocation.TravelPortType = travelPortType.TravelPortTypeDescription; } } HierarchyRepository hierarchyRepository = new HierarchyRepository(); string globalRegionCode = policyLocation.GlobalRegionCode; if (globalRegionCode != null) { GlobalRegion globalRegion = new GlobalRegion(); globalRegion = hierarchyRepository.GetGlobalRegion(globalRegionCode); policyLocation.LocationCode = globalRegion.GlobalRegionCode; policyLocation.LocationName = globalRegion.GlobalRegionName; } string globalSubRegionCode = policyLocation.GlobalSubRegionCode; if (globalSubRegionCode != null) { GlobalSubRegion globalSubRegion = new GlobalSubRegion(); globalSubRegion = hierarchyRepository.GetGlobalSubRegion(globalSubRegionCode); policyLocation.LocationCode = globalSubRegion.GlobalSubRegionCode; policyLocation.LocationName = globalSubRegion.GlobalSubRegionName; } string countryCode = policyLocation.CountryCode; if (countryCode != null) { Country country = new Country(); country = hierarchyRepository.GetCountry(countryCode); policyLocation.LocationCode = country.CountryCode; policyLocation.LocationName = country.CountryName; } string cityCode = policyLocation.CityCode; if (cityCode != null) { CityRepository cityRepository = new CityRepository(); City city = new City(); city = cityRepository.GetCity(cityCode); policyLocation.LocationCode = city.CityCode; policyLocation.LocationName = city.Name; } if (policyLocation.GlobalFlag) { policyLocation.LocationName = "Global"; policyLocation.LocationCode = "Global"; } }
//adds data from linked tables public void EditForDisplay(PolicyRouting policyRouting) { if (policyRouting.FromCityCode != null) { CityRepository cityRepository = new CityRepository(); City city = new City(); city = cityRepository.GetCity(policyRouting.FromCityCode); policyRouting.FromName = city.Name; } if (policyRouting.FromCountryCode != null) { CountryRepository countryRepository = new CountryRepository(); Country country = new Country(); country = countryRepository.GetCountry(policyRouting.FromCountryCode); policyRouting.FromName = country.CountryName; } if (policyRouting.FromGlobalSubRegionCode != null) { HierarchyRepository hierarchyRepository = new HierarchyRepository(); GlobalSubRegion globalSubRegion = new GlobalSubRegion(); globalSubRegion = hierarchyRepository.GetGlobalSubRegion(policyRouting.FromGlobalSubRegionCode); policyRouting.FromName = globalSubRegion.GlobalSubRegionName; } if (policyRouting.FromGlobalRegionCode != null) { HierarchyRepository hierarchyRepository = new HierarchyRepository(); GlobalRegion globalRegion = new GlobalRegion(); globalRegion = hierarchyRepository.GetGlobalRegion(policyRouting.FromGlobalRegionCode); policyRouting.FromName = globalRegion.GlobalRegionName; } if (policyRouting.FromGlobalFlag) { policyRouting.FromName = "Global"; } if (policyRouting.ToCityCode != null) { CityRepository cityRepository = new CityRepository(); City city = new City(); city = cityRepository.GetCity(policyRouting.ToCityCode); policyRouting.ToName = city.Name; } if (policyRouting.ToCountryCode != null) { CountryRepository countryRepository = new CountryRepository(); Country country = new Country(); country = countryRepository.GetCountry(policyRouting.ToCountryCode); policyRouting.ToName = country.CountryName; } if (policyRouting.ToGlobalSubRegionCode != null) { HierarchyRepository hierarchyRepository = new HierarchyRepository(); GlobalSubRegion globalSubRegion = new GlobalSubRegion(); globalSubRegion = hierarchyRepository.GetGlobalSubRegion(policyRouting.ToGlobalSubRegionCode); policyRouting.ToName = globalSubRegion.GlobalSubRegionName; } if (policyRouting.ToGlobalRegionCode != null) { HierarchyRepository hierarchyRepository = new HierarchyRepository(); GlobalRegion globalRegion = new GlobalRegion(); globalRegion = hierarchyRepository.GetGlobalRegion(policyRouting.ToGlobalRegionCode); policyRouting.ToName = globalRegion.GlobalRegionName; } if (policyRouting.ToGlobalFlag) { policyRouting.ToName = "Global"; } }