コード例 #1
0
        public static ContactBase AddADRecipientToContacts(UserContext userContext, ADRecipient adRecipient)
        {
            if (userContext == null)
            {
                throw new ArgumentNullException("userContext");
            }
            if (adRecipient == null)
            {
                throw new ArgumentNullException("adRecipient");
            }
            Participant primaryParticipant = ContactUtilities.GetPrimaryParticipant(adRecipient);

            if (primaryParticipant == null)
            {
                return(null);
            }
            if (adRecipient is IADDistributionList)
            {
                DistributionList distributionList = DistributionList.Create(userContext.MailboxSession, userContext.ContactsFolderId);
                distributionList.Add(new Participant(adRecipient));
                distributionList.DisplayName = (string)adRecipient[ADRecipientSchema.DisplayName];
                distributionList.Save(SaveMode.ResolveConflicts);
                return(distributionList);
            }
            Contact contact = Contact.Create(userContext.MailboxSession, userContext.ContactsFolderId);

            ContactUtilities.AddContactProperties(userContext, contact, adRecipient, primaryParticipant);
            contact.Save(SaveMode.ResolveConflicts);
            return(contact);
        }