public static void Phones(this Contact contact, PhoneTypeEnum type, string value)
        {
            if (String.IsNullOrEmpty(value))
            {
                return;
            }

            contact.ChangeValueDelegate += delegate(Contact x) {
                x.Fields = x.Fields ?? new List <Field>();
                if (!x.Fields.Any(fl => fl.Id == (int)ContactFieldsEnum.Phone))
                {
                    x.Fields.Add(new Field {
                        Id = (int)ContactFieldsEnum.Phone, Values = new List <FieldValue>()
                    });
                }

                var current = x.Phones();
                if (current != null && current.Any(p => p.Key == type))
                {
                    x.Fields.FirstOrDefault(fl => fl.Id == (int)ContactFieldsEnum.Phone).Values.FirstOrDefault(p => p.Enum == (int)type).Value = value.LeaveJustDigits();
                }
                else
                {
                    x.Fields.FirstOrDefault(fl => fl.Id == (int)ContactFieldsEnum.Phone).Values.Add(new FieldValue {
                        Enum = (int)type, Value = value.LeaveJustDigits()
                    });
                }
            };
        }
示例#2
0
 public virtual void AddPhone(string value, PhoneTypeEnum type = PhoneTypeEnum.MOB)
 {
     if (String.IsNullOrEmpty(value) || CheckPhoneDouble(value))
     {
         return;
     }
     SetField((int)ContactSystemFields.Phone, value, (int)type, add: true);
 }