예제 #1
0
        private async Task <StoredContact> ToStoredContact(StoredContact contact)
        {
            if (contact == null)
            {
                ContactStore contactStore = await ContactStore.CreateOrOpenAsync(
                    ContactStoreSystemAccessMode.ReadWrite,
                    ContactStoreApplicationAccessMode.ReadOnly);

                contact = new StoredContact(contactStore);
            }

            IDictionary <string, object> properties = await contact.GetPropertiesAsync();

            // Address
            if (Addresses != null && Addresses.Count > 0)
            {
                Addresses.ForEach(address => address.AsStoredContactProperties(ref properties));
            }

            // Birthday
            if (W3ContactBirthday != null)
            {
                W3ContactBirthday.AsStoredContactProperties(ref properties);
            }

            // Emails
            if (Emails != null && Emails.Count > 0)
            {
                Emails.ForEach(email => email.AsStoredContactProperties(ref properties));
            }

            // Name
            if (Name != null)
            {
                Name.AsStoredContactProperties(ref properties);
            }

            // NickName
            if (W3ContactNickName != null)
            {
                W3ContactNickName.AsStoredContactProperties(ref properties);
            }

            // Note
            if (W3ContactNotes != null)
            {
                W3ContactNotes.AsStoredContactProperties(ref properties);
            }

            // Organization
            if (Organization != null)
            {
                Organization.AsStoredContactProperties(ref properties);
            }

            // Phones
            if (Phones != null && Phones.Count > 0)
            {
                Phones.ForEach(phone => phone.AsStoredContactProperties(ref properties));
            }

            // Photos
            if (Photos != null && Photos.Count > 0)
            {
                W3ContactPhoto firstPhoto = Photos.FirstOrDefault();
                if (firstPhoto != null)
                {
                    await firstPhoto.SetPictureOnStoredContactAsync(contact);
                }
            }

            // Urls
            if (Urls != null && Urls.Count > 0)
            {
                Urls.ForEach(url => url.AsStoredContactProperties(ref properties));
            }

            return(contact);
        }