示例#1
0
        public BillingAddressViewModel(AddressInfo address, SelectList countries, CountryRepository countryRepository, SelectList addresses = null)
        {
            if (address != null)
            {
                if (countryRepository == null)
                {
                    throw new ArgumentNullException(nameof(countryRepository));
                }

                BillingAddressLine1      = address.AddressLine1;
                BillingAddressLine2      = address.AddressLine2;
                BillingAddressCity       = address.AddressCity;
                BillingAddressPostalCode = address.AddressZip;
                BillingAddressState      = countryRepository.GetState(address.AddressStateID)?.StateDisplayName ?? String.Empty;
                BillingAddressCountry    = countryRepository.GetCountry(address.AddressCountryID)?.CountryDisplayName ?? String.Empty;
                Countries = countries;
            }

            BillingAddressCountryStateSelector = new CountryStateViewModel
            {
                Countries = countries,
                CountryID = address?.AddressCountryID ?? 0,
                StateID   = address?.AddressStateID ?? 0
            };

            BillingAddressSelector = new AddressSelectorViewModel
            {
                Addresses = addresses,
                AddressID = address?.AddressID ?? 0
            };
        }
示例#2
0
        public static ContactViewModel GetViewModel(IContact contact, CountryRepository countryProvider, IStringLocalizer localizer)
        {
            var countryStateName = CountryStateName.Parse(contact.Country);
            var country          = countryProvider.GetCountry(countryStateName.CountryName);
            var state            = countryProvider.GetState(countryStateName.StateName);

            var model = new ContactViewModel(contact)
            {
                CountryCode = country.CountryTwoLetterCode,
                Country     = localizer[country.CountryDisplayName]
            };

            if (state != null)
            {
                model.StateCode = state.StateName;
                model.State     = localizer[state.StateDisplayName];
            }

            return(model);
        }