static async Task <String> CreateGroup(Session session, String name) { var res = ContactGroup.Resource(session); String id = await res.Create(new ContactGroup() { Name = name }); return(id); }
public async void CreateGetListUpdateDelete() { await CleanUpContacts(); await PrepareContacts(); var res = ContactGroup.Resource(Session); String id = await res.Create(new ContactGroup() { Name = "ci-test" }); Assert.NotEmpty(id); var cg = await res.Get(id); Assert.Equal(id, cg.Id); Assert.Equal("ci-test", cg.Name); cg.Name = "Friends"; await res.Update(id, cg); var updatedCg = await res.Get(id); Assert.Equal(id, updatedCg.Id); Assert.Equal("Friends", updatedCg.Name); Assert.True(GetNumItems(res.List()) > 0); Assert.Equal(0, GetNumItems(res.ListContacts(id))); await res.AddContact(id, bobId); Assert.Equal(1, GetNumItems(res.ListContacts(id))); await res.AddContact(id, aliceId); Assert.Equal(2, GetNumItems(res.ListContacts(id))); await res.DeleteContact(id, bobId); Assert.Equal(1, GetNumItems(res.ListContacts(id))); await res.DeleteContact(id, aliceId); Assert.Equal(0, GetNumItems(res.ListContacts(id))); Assert.True(GetNumItems(res.List()) > 0); await res.Delete(id); await CleanUpContacts(); }
static async Task SendSmsToGroup(String senderId, String aliceMdn, String bobMdn, String body, SessionOptions opts) { using (var session = new Session(opts)) { // Create a group var grpRes = ContactGroup.Resource(session); String friendsId = await grpRes.Create(new ContactGroup() { Name = "Friends" }); // Create two contacts var contactRes = Contact.Resource(session); String aliceId = await contactRes.Create(new Contact() { FirstName = "Alice", PrimaryMdn = aliceMdn }); String bobId = await contactRes.Create(new Contact() { FirstName = "Bob", PrimaryMdn = bobMdn }); // Add the contacts to the group await grpRes.AddContact(friendsId, aliceId); await grpRes.AddContact(friendsId, bobId); // Send the message request var resMrq = MessageRequest.Resource(session); String mrqId = await resMrq.Create(new MessageRequest() { From = "sender_id:" + senderId, To = new List <String>() { "group:" + friendsId }, Body = body }); Console.WriteLine("Created message request {0} to group {1}", mrqId, friendsId); } }