public async Task GetContactsAsync() { if (IsBusy) { return; } IsBusy = true; try { Contacts.Clear(); var contacts = await ContactsAPI.GetContacts(); foreach (var contact in contacts) { #if NETFX_CORE contact.CompanyName = Gravatar.GetURL(contact.EmailAddresses[0].Address, 88); #endif Contacts.Add(contact); } SortContacts(); } catch (Exception ex) { //add pop up here for error } finally { IsBusy = false; } }
public async Task SaveContact() { var contact = Contact; bool newContact = (Contact == null); //add new contact if (newContact) { contact = new Contact(); } contact.GivenName = FirstName; contact.Surname = LastName; if (contact.EmailAddresses.Count == 0) { contact.EmailAddresses.Add(new EmailAddress { Address = Email, Name = FirstName + " " + LastName }); } else { contact.EmailAddresses[0].Address = Email; contact.EmailAddresses[0].Name = FirstName + " " + LastName; } if (contact.BusinessPhones.Count == 0) { contact.BusinessPhones.Add(Phone); } else { contact.BusinessPhones[0] = Phone; } if (newContact) { await ContactsAPI.AddContact(contact); App.ContactsViewModel.AddContact(contact); Contact = contact; } else { await ContactsAPI.UpdateContact(contact); } }
public async Task DeleteContact(IContact contact) { Contacts.Remove(contact); SortContacts(); ContactsAPI.DeleteContact(contact); }