public async Task<ActionResult> ListMyContacts() { HomeViewModel model = new HomeViewModel(); var signInUserId = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value; AuthenticationHelper authenticationHelper = new AuthenticationHelper(); authenticationHelper.EnsureAuthenticationContext(new ADALTokenCache(signInUserId)); ContactsHelper contactsHelper = new ContactsHelper(authenticationHelper); var contacts = await contactsHelper.GetContacts(); model.Office365ActionResult = String.Format("Found {0} contacts! Showing first 10, if any.", contacts.Count()); foreach (var item in contacts.Take(10)) { model.Items.Add(String.Format( "Name: {0} - Email: {1}", !String.IsNullOrEmpty(item.DisplayName) ? item.DisplayName : String.Empty, item.EmailAddresses != null ? item.EmailAddresses.First().Address : String.Empty)); } return View("UseOffice365API", model); }
protected async void ListContactsCommand_Click(object sender, EventArgs e) { var signInUserId = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value; AuthenticationHelper authenticationHelper = new AuthenticationHelper(); authenticationHelper.EnsureAuthenticationContext(new ADALTokenCache(signInUserId)); ContactsHelper contactsHelper = new ContactsHelper(authenticationHelper); var contacts = await contactsHelper.GetContacts(); List<String> results = new List<String>(); commandResult.Text = String.Format("Found {0} contacts! Showing first 10, if any.", contacts.Count()); foreach (var item in contacts.Take(10)) { results.Add(String.Format( "Name: {0} - Email: {1}", !String.IsNullOrEmpty(item.DisplayName) ? item.DisplayName : String.Empty, item.EmailAddresses != null ? item.EmailAddresses.First().Address : String.Empty)); } resultsList.DataSource = results; resultsList.DataBind(); }