Beispiel #1
0
        private static PhoneListVm MapToPhoneListVm(this List <Phone> phones, List <KeyValuePair <int, string> > phoneTypes)
        {
            Func <Phone, bool>         func         = null;
            PhoneListVm                phoneListVm  = new PhoneListVm();
            KeyValuePair <int, string> keyValuePair = phoneTypes.FirstOrDefault <KeyValuePair <int, string> >();

            phoneListVm.AdditionalPhones     = new List <PhoneVm>();
            phoneListVm.DefaultPhoneTypeName = keyValuePair.Value;
            phoneListVm.DefaultPhoneTypeId   = new long?((long)keyValuePair.Key);
            if (phones != null && phones.Any <Phone>())
            {
                Phone listingTypePhone = phones.FirstOrDefault <Phone>((Phone p) => {
                    long?phoneTypeId = p.PhoneTypeId;
                    long key         = (long)keyValuePair.Key;
                    return(phoneTypeId.GetValueOrDefault() == key & phoneTypeId.HasValue);
                });
                if (listingTypePhone != null)
                {
                    phoneListVm.DefaultPhoneId     = listingTypePhone.Id;
                    phoneListVm.DefaultPhoneNumber = listingTypePhone.Number;
                }
                List <Phone>       phones1 = phones;
                Func <Phone, bool> func1   = func;
                if (func1 == null)
                {
                    Func <Phone, bool> func2 = (Phone m) => {
                        long?id             = m.Id;
                        long?defaultPhoneId = phoneListVm.DefaultPhoneId;
                        return(!(id.GetValueOrDefault() == defaultPhoneId.GetValueOrDefault() & id.HasValue == defaultPhoneId.HasValue));
                    };
                    Func <Phone, bool> func3 = func2;
                    func  = func2;
                    func1 = func3;
                }
                foreach (Phone phone in phones1.Where <Phone>(func1))
                {
                    PhoneVm additionalPhone = new PhoneVm()
                    {
                        Id          = phone.Id,
                        PhoneTypeId = phone.PhoneTypeId,
                        Number      = phone.Number,
                        PhoneTypes  = phoneTypes.ToSelectListItemList(phone.PhoneTypeId)
                    };
                    phoneListVm.AdditionalPhones.Add(additionalPhone);
                }
            }
            if (!phoneListVm.AdditionalPhones.Any <PhoneVm>())
            {
                PhoneVm emptyAdditionalPhone = new PhoneVm()
                {
                    PhoneTypes = phoneTypes.ToSelectListItemList()
                };
                phoneListVm.AdditionalPhones.Add(emptyAdditionalPhone);
            }
            return(phoneListVm);
        }
Beispiel #2
0
        public static PhoneListVm Repopulate(this PhoneListVm model, ServiceType serviceType)
        {
            if (model == null)
            {
                return(AdminViewModelsProvider.GetPhoneList(serviceType));
            }
            if (model.AdditionalPhones == null || !model.AdditionalPhones.Any <PhoneVm>())
            {
                model.AdditionalPhones = new List <PhoneVm>()
                {
                    new PhoneVm()
                };
            }
            List <SelectListItem> phoneTypes = MSLivingChoices.Bcs.Admin.Components.ItemTypeBc.Instance.GetPhoneTypes(serviceType).ToSelectListItemList();

            foreach (PhoneVm additionalPhone in model.AdditionalPhones)
            {
                additionalPhone.PhoneTypes = phoneTypes;
            }
            return(model);
        }