/// <summary> /// Create or Update A Constant Contact List /// </summary> /// <param name="members">List to Export </param> /// <param name="listName">Name Of List</param> /// <returns></returns> public async Task <ServiceResponse> ExportConstantContactList(IList <PaaMember> members, string listName) { // find existing list or create new one ContactList requestedList = await ConstantContactService.GetListByListName(listName, true); // build the export structure ContactImport import = BuildContactImport(members, new List <string> { requestedList.Id }); var bulkActivitiesService = ConstantContact.BulkListsService(); try { // clear any existing list ConstantContactBulkResponse clearResponse = await ClearConstantContactList(requestedList.Id); if (import.ImportData.Count() < 1) // nothing to add { return(new ServiceResponse { Name = listName, Success = true, SuccessCount = 0, ErrorCount = 0, Message = "Success" }); } else { BulkActivityResponse response = await bulkActivitiesService.ImportContactsAsync(import); return(new ServiceResponse { Name = listName, Success = true, SuccessCount = int.Parse(response.ContactCount), ErrorCount = int.Parse(response.ErrorCount), Message = "Success" }); } } catch (Exception ex) { return(new ServiceResponse { Name = listName, Success = false, Message = "Failed", ExceptionMessage = ex.Message }); } }
public async Task <ConstantContactModel> CreateAConstantContactList(string listName) { List <string> names = new List <string>() { listName }; List <ConstantContactModel> returnedList = await ConstantContactService.Create(names); return(returnedList.FirstOrDefault()); }