public PostalAddressViewModel GetPostalAddress(Guid customerid, int postaladdressid) { if (customerid != Guid.Empty) { using (var context = new ApplicationDbContext()) { var postalAddress = context.PostalAddresses.AsNoTracking() .Where(x => x.CustomerID == customerid && x.PostalAddressID == postaladdressid) .SingleOrDefault(); if (postalAddress != null) { var postalAddressVm = new PostalAddressViewModel() { CustomerID = postalAddress.CustomerID.ToString("D"), StreetAddress1 = postalAddress.StreetAddress1?.Trim(), StreetAddress2 = postalAddress.StreetAddress2?.Trim(), City = postalAddress.City?.Trim() }; var countriesRepo = new CountriesRepository(); postalAddressVm.CountryNameEnglish = countriesRepo.GetCountryNameEnglish(postalAddress.Iso3); var regionsRepo = new RegionsRepository(); postalAddressVm.RegionNameEnglish = regionsRepo.GetRegionNameEnglish(postalAddress.RegionCode); return(postalAddressVm); } } } return(null); }
public PostalAddressListViewModel GetPostalAddressList(Guid customerid) { if (customerid != Guid.Empty) { using (var context = new ApplicationDbContext()) { var postalAddresses = context.PostalAddresses.AsNoTracking() .Where(x => x.CustomerID == customerid) .OrderBy(x => x.PostalAddressID); if (postalAddresses != null) { var postalAddressListVm = new PostalAddressListViewModel(); foreach (var address in postalAddresses) { var postalAddressVm = new PostalAddressViewModel() { CustomerID = address.CustomerID.ToString("D"), PostalAddressID = address.PostalAddressID, StreetAddress1 = address.StreetAddress1, StreetAddress2 = address.StreetAddress2, City = address.City }; var regionsRepo = new RegionsRepository(); postalAddressVm.RegionNameEnglish = regionsRepo.GetRegionNameEnglish(address.RegionCode); var countryRepo = new CountriesRepository(); postalAddressVm.CountryNameEnglish = countryRepo.GetCountryNameEnglish(address.Iso3); postalAddressListVm.PostalAddresses.Add(postalAddressVm); } return(postalAddressListVm); } } } return(null); }