//Add Data From Linked Tables for Display public void EditForDisplay(Address address) { if (address.CountryCode != null) { Country country = new Country(); country = db.Countries.SingleOrDefault(c => c.CountryCode == address.CountryCode); address.CountryName = country.CountryName; } if (address.MappingQualityCode != null) { MappingQuality mappingQuality = new MappingQuality(); mappingQuality = db.MappingQualities.SingleOrDefault(c => c.MappingQualityCode == address.MappingQualityCode); address.MappingQualityDescription = mappingQuality.MappingQualityDescription; } //StateProvince Code is saved as StateProvinceName in the database StateProvinceRepository stateProvinceRepository = new StateProvinceRepository(); StateProvince stateProvince = new StateProvince(); if (address.StateProvinceName != null) { stateProvince = stateProvinceRepository.GetStateProvinceByCountry(address.CountryCode, address.StateProvinceName); } else if (address.StateProvinceCode != null) { stateProvince = stateProvinceRepository.GetStateProvinceByCountry(address.CountryCode, address.StateProvinceCode); } if (stateProvince != null) { address.StateProvinceCode = stateProvince.StateProvinceCode; address.StateProvinceName = stateProvince.Name; } }
public ClientTopUnitClientLocation GetAddress(int addressId) { ClientTopUnitClientLocation clientTopUnitClientLocation = new ClientTopUnitClientLocation(); Address address = db.Addresses.SingleOrDefault(c => c.AddressId == addressId); if (address != null) { clientTopUnitClientLocation.AddressId = address.AddressId; clientTopUnitClientLocation.AddressLocationName = address.AddressLocationName; clientTopUnitClientLocation.FirstAddressLine = address.FirstAddressLine; clientTopUnitClientLocation.SecondAddressLine = address.SecondAddressLine; clientTopUnitClientLocation.CityName = address.CityName; clientTopUnitClientLocation.StateProvinceName = address.StateProvinceName; clientTopUnitClientLocation.PostalCode = address.PostalCode; clientTopUnitClientLocation.Ranking = address.Ranking; if (address.CountryCode != null) { Country country = new Country(); country = db.Countries.SingleOrDefault(c => c.CountryCode == address.CountryCode); clientTopUnitClientLocation.Country = country; clientTopUnitClientLocation.CountryName = country.CountryName; clientTopUnitClientLocation.CountryCode = country.CountryCode; } if (address.MappingQualityCode != null) { MappingQuality mappingQuality = new MappingQuality(); mappingQuality = db.MappingQualities.SingleOrDefault(c => c.MappingQualityCode == address.MappingQualityCode); clientTopUnitClientLocation.MappingQualityDescription = mappingQuality.MappingQualityDescription; } clientTopUnitClientLocation.LatitudeDecimal = address.LatitudeDecimal; clientTopUnitClientLocation.LongitudeDecimal = address.LongitudeDecimal; clientTopUnitClientLocation.VersionNumber = clientTopUnitClientLocation.VersionNumber; } return(clientTopUnitClientLocation); }