Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
private static refreshContactList(laListe: Windows.ApplicationModel.Contacts.ContactList) {
ListeContactSample.getAllFromBackEnd(function (ctcs) {
for (var i = 0; i < ctcs.length; i++) {
ListeContactSample.refreshContact(laListe, ctcs[i]);
}
});
}
private static refreshContact(laListe: Windows.ApplicationModel.Contacts.ContactList,
leContact: ContactBackend) {
// obtient le contact depuis son id "distant"
laListe.getContactFromRemoteIdAsync(leContact.remoteId).done(function (ctc) {
// si il n'existe pas, il faut le créer
if (ctc == null) {
ctc = new Windows.ApplicationModel.Contacts.Contact();
ctc.remoteId = leContact.remoteId;
} else {
ctc.emails.clear();
}
// puis mettre à jour ses données
ctc.name = leContact.name;
if (leContact.email != null && leContact.email != "") {
var email = new Windows.ApplicationModel.Contacts.ContactEmail();
email.address = leContact.email;
email.kind = Windows.ApplicationModel.Contacts.ContactEmailKind.work;
ctc.emails.push(email);
}
// et finalement l'enregistrer
laListe.saveContactAsync(ctc).done(function () {
});
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment