internal static OwnerVm MapToOwnerVm(this Owner owner, OwnerType ownerType) { OwnerVm ownerVm = new OwnerVm() { Id = owner.Id, NewOwner = new NewOwnerVm() { Address = AdminViewModelsProvider.GetAddressVm(), PhoneList = AdminViewModelsProvider.GetPhoneList(ownerType), EmailList = AdminViewModelsProvider.GetEmailListVm(ownerType), Contacts = new List <ContactVm>() { AdminViewModelsProvider.GetContactVm(ownerType) }, LogoImages = new ImageListVm(ownerType.MapToDisplayName()), OwnerType = ownerType }, Owners = OwnerBc.Instance.GetAllByOwnerType(owner.OwnerType).Select <Owner, SelectListItem>((Owner m) => { SelectListItem selectListItem = new SelectListItem(); long?id = m.Id; selectListItem.set_Value(id.ToString()); selectListItem.set_Text(m.Name); id = ownerVm.Id; long?nullable = m.Id; selectListItem.set_Selected(id.GetValueOrDefault() == nullable.GetValueOrDefault() & id.HasValue == nullable.HasValue); return(selectListItem); }).ToList <SelectListItem>() }; return(ownerVm); }
public static List <SelectListItem> CountryListToSelectListItems(IEnumerable <Country> countryList, string selectedCountryCode) { List <SelectListItem> result = new List <SelectListItem>(); foreach (Country country in countryList) { SelectListItem item = new SelectListItem(); item.set_Text(country.Name); item.set_Value(country.Code); item.set_Selected((selectedCountryCode == null ? false : country.Code == selectedCountryCode)); result.Add(item); } return(result); }
public static AddressVm Repopulate(this AddressVm address) { if (!address.Country.Id.HasValue) { address.Country.Id = LocationBc.Instance.DefaultCountry.Id; } List <Country> countries = LocationBc.Instance.GetAllCountries(); address.Country.AvailableCountries = countries.ConvertAll <SelectListItem>((Country m) => { SelectListItem selectListItem = new SelectListItem(); long?id = m.Id; selectListItem.set_Value(id.ToString()); selectListItem.set_Text(m.Name); id = m.Id; long?nullable = address.Country.Id; selectListItem.set_Selected(id.GetValueOrDefault() == nullable.GetValueOrDefault() & id.HasValue == nullable.HasValue); return(selectListItem); }); List <State> states = LocationBc.Instance.GetStates(address.Country.Id); address.State.AvailableStates = states.ConvertAll <SelectListItem>((State m) => { SelectListItem selectListItem = new SelectListItem(); long?id = m.Id; selectListItem.set_Value(id.ToString()); selectListItem.set_Text(m.Name); id = m.Id; long?nullable = address.State.Id; selectListItem.set_Selected(id.GetValueOrDefault() == nullable.GetValueOrDefault() & id.HasValue == nullable.HasValue); return(selectListItem); }); if (address.State.Id.HasValue) { List <City> cities = LocationBc.Instance.GetCities(address.State.Id); address.City.AvailableCities = cities.ConvertAll <SelectListItem>((City m) => { SelectListItem selectListItem = new SelectListItem(); long?id = m.Id; selectListItem.set_Value(id.ToString()); selectListItem.set_Text(m.Name); id = m.Id; long?nullable = address.City.Id; selectListItem.set_Selected(id.GetValueOrDefault() == nullable.GetValueOrDefault() & id.HasValue == nullable.HasValue); return(selectListItem); }); } else { address.City.AvailableCities = new List <SelectListItem>(); } return(address); }
public static List <SelectListItem> EnumToSelectListItems <T>(Nullable <T> selectedItem = null) where T : struct { if (!typeof(T).IsEnum) { throw new ArgumentException(ErrorMessages.NotEnumType); } return(ConverterHelpers.EnumToList <T>().Select <T, SelectListItem>((T enumItem) => { string text = enumItem.ToString(); SelectListItem selectListItem = new SelectListItem(); selectListItem.set_Text(enumItem.GetEnumLocalizedValue <T>() ?? text); selectListItem.set_Value(text); selectListItem.set_Selected((!selectedItem.HasValue ? false : enumItem.Equals(selectedItem.Value))); return selectListItem; }).ToList <SelectListItem>()); }