Guest User

Untitled

a guest
Jan 22nd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. public class GoogleContactService
  2. {
  3. public void CreateContact()
  4. {
  5. var cr = this.CreateContactsRequest();
  6. var groups = cr.GetGroups().Entries.ToList();
  7. var myContactsSystemGroup = groups.FirstOrDefault(x => x.SystemGroup == "Contacts");
  8.  
  9. var newContact = new Contact();
  10.  
  11. // ...
  12.  
  13. // attempt to add to `My Contacts` system group
  14. if (myContactsSystemGroup != null && !String.IsNullOrWhiteSpace(myContactsSystemGroup.Id))
  15. {
  16. newContact.GroupMembership.Add(new GroupMembership() { HRef = myContactsSystemGroup.Id });
  17. }
  18.  
  19. var createUri = this.CreateCreateContactUri();
  20. var createdEntry = cr.Insert(createUri, newContact);
  21. }
  22.  
  23. private ContactsRequest CreateContactsRequest()
  24. {
  25. // todo: outside the scope of this gist
  26. }
  27.  
  28. private Uri CreateCreateContactUri()
  29. {
  30. // todo: outside the scope of this gist
  31. }
  32. }
Add Comment
Please, Sign In to add comment