public ContactsViewModel() { // Instantiate a private instance of the contacts operations object _contactsOperations = new ContactsOperations(); this.Contacts = new ObservableCollection <ContactItemViewModel>(); //construct relay commands to be bound to controls on a UI this.NewContactCommand = new RelayCommand(ExecuteNewContactCommand); this.GetContactsCommand = new RelayCommand(ExecuteGetContactsCommandAsync); this.DeleteContactCommand = new RelayCommand(ExecuteDeleteCommandAsync, CanDeleteContact); this.CancelContactChangesCommand = new RelayCommand(ExecuteCancelContactChangesCommand, CanCancelContactChanges); }
private async void btnGetMyContacts_Click(object sender, RoutedEventArgs e) { setLoadingString("Loading...."); clearAllLists(); if (AppCapabilities == null) { await getAppCapabilities(); } var contactsClient = ExchangeClient.ensureOutlookClientCreated(AppCapabilities, "Contacts"); string fileAction = FileParse.readFileAction(SettingsHelper.ContactsFilePath); if (fileAction == "ADD") { setLoadingString("Adding Contacts...."); await ContactsOperations.addContacts(contactsClient, FileParse.readContact()); var myContacts = await ContactsOperations.getContacts(contactsClient); foreach (var myContact in myContacts) { Contacts.Add(new MyContact { Name = myContact.DisplayName }); } } else if (fileAction == "UPDATE") { setLoadingString("Updating Contacts...."); var fileContacts = FileParse.readContact(); foreach (var fileContact in fileContacts) { var contact = await ContactsOperations.getContactByGivenNameAndSurname(contactsClient, fileContact); await ContactsOperations.updateContact(contactsClient, contact.Id, fileContact); } var myContacts = await ContactsOperations.getContacts(contactsClient); foreach (var myContact in myContacts) { Contacts.Add(new MyContact { Name = myContact.DisplayName }); } } else if (fileAction == "DELETE") { setLoadingString("Deleting Contacts...."); var fileContacts = FileParse.readContact(); foreach (var fileContact in fileContacts) { var contact = await ContactsOperations.getContactByGivenNameAndSurname(contactsClient, fileContact); await ContactsOperations.deleteContact(contactsClient, contact.Id); } var myContacts = await ContactsOperations.getContacts(contactsClient); foreach (var myContact in myContacts) { Contacts.Add(new MyContact { Name = myContact.DisplayName }); } } setLoadingString(""); }