void AddSampleContact(SampleContact sampleContact)
        {
            Contact contact = new Contact();

            contact.Name = sampleContact.Name;

            AppendValue(contact, sampleContact.HomeEmail, ContactFieldType.Email, ContactFieldCategory.Home);
            AppendValue(contact, sampleContact.WorkEmail, ContactFieldType.Email, ContactFieldCategory.Work);

            AppendValue(contact, sampleContact.HomePhone, ContactFieldType.PhoneNumber, ContactFieldCategory.Home);
            AppendValue(contact, sampleContact.MobilePhone, ContactFieldType.PhoneNumber, ContactFieldCategory.Mobile);
            AppendValue(contact, sampleContact.WorkPhone, ContactFieldType.PhoneNumber, ContactFieldCategory.Work);

            if (!string.IsNullOrEmpty(sampleContact.Address))
            {
                contact.Fields.Add(new ContactLocationField(sampleContact.Address, ContactFieldCategory.None,
                                                            sampleContact.Street, sampleContact.City, sampleContact.State, "", sampleContact.ZipCode));
            }

            switch (contactPickerUI.AddContact(sampleContact.Id, contact))
            {
            case AddContactResult.Added:
                // Notify the user that the contact was added
                OutputText.Text = sampleContact.Name + " was added to the basket";
                break;

            case AddContactResult.AlreadyAdded:
                // Notify the user that the contact is already added
                OutputText.Text = sampleContact.Name + " is already in the basket";
                break;

            case AddContactResult.Unavailable:
            default:
                // Notify the user that the basket is unavailable
                OutputText.Text = sampleContact.Name + " could not be added to the basket";
                break;
            }
        }
Beispiel #2
0
        void AddSampleContact(SampleContact sampleContact)
        {
            Contact contact = new Contact();

            contact.Id        = sampleContact.Id;
            contact.FirstName = sampleContact.FirstName;
            contact.LastName  = sampleContact.LastName;

            if (!string.IsNullOrEmpty(sampleContact.HomeEmail))
            {
                ContactEmail homeEmail = new ContactEmail();
                homeEmail.Address = sampleContact.HomeEmail;
                homeEmail.Kind    = ContactEmailKind.Personal;
                contact.Emails.Add(homeEmail);
            }

            if (!string.IsNullOrEmpty(sampleContact.WorkEmail))
            {
                ContactEmail workEmail = new ContactEmail();
                workEmail.Address = sampleContact.WorkEmail;
                workEmail.Kind    = ContactEmailKind.Work;
                contact.Emails.Add(workEmail);
            }

            if (!string.IsNullOrEmpty(sampleContact.HomePhone))
            {
                ContactPhone homePhone = new ContactPhone();
                homePhone.Number = sampleContact.HomePhone;
                homePhone.Kind   = ContactPhoneKind.Home;
                contact.Phones.Add(homePhone);
            }

            if (!string.IsNullOrEmpty(sampleContact.MobilePhone))
            {
                ContactPhone mobilePhone = new ContactPhone();
                mobilePhone.Number = sampleContact.MobilePhone;
                mobilePhone.Kind   = ContactPhoneKind.Mobile;
                contact.Phones.Add(mobilePhone);
            }

            if (!string.IsNullOrEmpty(sampleContact.WorkPhone))
            {
                ContactPhone workPhone = new ContactPhone();
                workPhone.Number = sampleContact.WorkPhone;
                workPhone.Kind   = ContactPhoneKind.Work;
                contact.Phones.Add(workPhone);
            }

            if (!string.IsNullOrEmpty(sampleContact.Street))
            {
                ContactAddress homeAddress = new ContactAddress();
                homeAddress.StreetAddress = sampleContact.Street;
                homeAddress.Locality      = sampleContact.City;
                homeAddress.Region        = sampleContact.State;
                homeAddress.PostalCode    = sampleContact.ZipCode;
                homeAddress.Kind          = ContactAddressKind.Home;
                contact.Addresses.Add(homeAddress);
            }

            switch (contactPickerUI.AddContact(contact))
            {
            case AddContactResult.Added:
                // Notify the user that the contact was added
                OutputText.Text = contact.DisplayName + " was added to the basket";
                break;

            case AddContactResult.AlreadyAdded:
                // Notify the user that the contact is already added
                OutputText.Text = contact.DisplayName + " is already in the basket";
                break;

            case AddContactResult.Unavailable:
            default:
                // Notify the user that the basket is unavailable
                OutputText.Text = contact.DisplayName + " could not be added to the basket";
                break;
            }
        }
 /// <summary>
 /// Initializes a new instance of the ContactPickerPage class.
 /// </summary>
 public ContactPickerPage()
 {
     this.InitializeComponent();
     ContactList.ItemsSource       = SampleContact.CreateSampleContacts();
     ContactList.SelectionChanged += this.ContactList_SelectionChanged;
 }