public async Task AddContact(MyContact myContact)
        {
            try
            {
                var graphServiceClient = await GetGraphServiceAsync();

                var requestContact = new Microsoft.Graph.Contact
                {
                    GivenName   = myContact.GivenName,
                    Surname     = myContact.Surname,
                    CompanyName = myContact.CompanyName,
                };
                var emailList = new List <EmailAddress>();
                emailList.Add(new EmailAddress {
                    Address = myContact.EmailAddress, Name = myContact.EmailAddress
                });
                requestContact.EmailAddresses = emailList;
                var businessPhonesList = new List <string>();
                businessPhonesList.Add(myContact.BusinessPhone);
                requestContact.BusinessPhones = businessPhonesList;
                var homePhonesList = new List <string>();
                homePhonesList.Add(myContact.HomePhone);
                requestContact.HomePhones = homePhonesList;
                await graphServiceClient.Me.Contacts.Request().AddAsync(requestContact);
            }
            catch (Exception el)
            {
            }
            return;
        }
        public async Task CreateNewContact()
        {
            try
            {
                // create contact and get names
                Microsoft.Graph.Contact contact = new Microsoft.Graph.Contact();
                contact.GivenName = tbFName.Text;
                contact.Surname = tbLName.Text;
                contact.MiddleName = tbMName.Text;
                
                // check for email addresses
                if (tbEmailAddress1.Text != "")
                {
                    AddEmailAddressToCollection(tbEmailAddress1.Text);
                }

                if (tbEmailAddress1.Text != "")
                {
                    AddEmailAddressToCollection(tbEmailAddress2.Text);
                }

                if (tbEmailAddress1.Text != "")
                {
                    AddEmailAddressToCollection(tbEmailAddress3.Text);
                }
                
                // set the addresses for the contact         
                contact.EmailAddresses = emailAddresses;

                // get phone numbers
                contact.MobilePhone = tbMobilePhone.Text;
                businessPhones.Add(tbBusinessPhone.Text);
                homePhones.Add(tbHomePhone.Text);
                contact.BusinessPhones = businessPhones;
                contact.HomePhones = homePhones;
                
                // get company info
                contact.JobTitle = tbTitle.Text;
                contact.CompanyName = tbCompany.Text;
                contact.FileAs = tbFileAs.Text;

                // log the request info
                sdklogger.Log(graphClient.Me.Contacts.Request().GetHttpRequestMessage().Headers.ToString());
                sdklogger.Log(graphClient.Me.Contacts.Request().GetHttpRequestMessage().RequestUri.ToString());

                // sent the new contact request
                await graphClient.Me.Contacts.Request().AddAsync(contact);
            }
            catch (Exception ex)
            {
                sdklogger.Log("NewContactSend Failed: " + ex.Message);
                sdklogger.Log(ex.Message);
            }
            finally
            {
                // close the form
                Close();
            }
        }
Esempio n. 3
0
        public async Task CreateNewContact()
        {
            try
            {
                // create contact and get names
                Microsoft.Graph.Contact contact = new Microsoft.Graph.Contact();
                contact.GivenName  = tbFName.Text;
                contact.Surname    = tbLName.Text;
                contact.MiddleName = tbMName.Text;

                // check for email addresses
                if (tbEmailAddress1.Text != "")
                {
                    AddEmailAddressToCollection(tbEmailAddress1.Text);
                }

                if (tbEmailAddress1.Text != "")
                {
                    AddEmailAddressToCollection(tbEmailAddress2.Text);
                }

                if (tbEmailAddress1.Text != "")
                {
                    AddEmailAddressToCollection(tbEmailAddress3.Text);
                }

                // set the addresses for the contact
                contact.EmailAddresses = emailAddresses;

                // get phone numbers
                contact.MobilePhone = tbMobilePhone.Text;
                businessPhones.Add(tbBusinessPhone.Text);
                homePhones.Add(tbHomePhone.Text);
                contact.BusinessPhones = businessPhones;
                contact.HomePhones     = homePhones;

                // get company info
                contact.JobTitle    = tbTitle.Text;
                contact.CompanyName = tbCompany.Text;
                contact.FileAs      = tbFileAs.Text;

                // log the request info
                sdklogger.Log(graphClient.Me.Contacts.Request().GetHttpRequestMessage().Headers.ToString());
                sdklogger.Log(graphClient.Me.Contacts.Request().GetHttpRequestMessage().RequestUri.ToString());

                // sent the new contact request
                await graphClient.Me.Contacts.Request().AddAsync(contact);
            }
            catch (Exception ex)
            {
                sdklogger.Log("NewContactSend Failed: " + ex.Message);
                sdklogger.Log(ex.Message);
            }
            finally
            {
                // close the form
                Close();
            }
        }
 public async Task AddContact(MyContact myContact)
 {
     try
     {
         var graphServiceClient = await GetGraphServiceAsync();
         var requestContact = new Microsoft.Graph.Contact
         {
             GivenName = myContact.GivenName,
             Surname = myContact.Surname,
             CompanyName = myContact.CompanyName,
         };
         var emailList = new List<EmailAddress>();
         emailList.Add(new EmailAddress { Address = myContact.EmailAddress, Name = myContact.EmailAddress });
         requestContact.EmailAddresses = emailList;
         var businessPhonesList = new List<string>();
         businessPhonesList.Add(myContact.BusinessPhone);
         requestContact.BusinessPhones = businessPhonesList;
         var homePhonesList = new List<string>();
         homePhonesList.Add(myContact.HomePhone);
         requestContact.HomePhones = homePhonesList;
         await graphServiceClient.Me.Contacts.Request().AddAsync(requestContact);
     }
     catch (Exception el)
     {
     }
     return;
 }
Esempio n. 5
0
 /// <summary>
 /// Creates the specified Contact using PUT.
 /// </summary>
 /// <param name="contactToCreate">The Contact to create.</param>
 /// <returns>The created Contact.</returns>
 public System.Threading.Tasks.Task <Contact> CreateAsync(Contact contactToCreate)
 {
     return(this.CreateAsync(contactToCreate, CancellationToken.None));
 }