Created
July 6, 2012 20:56
-
-
Save flaviotsf/3062716 to your computer and use it in GitHub Desktop.
Bronto Integration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class BrontoIntegration { | |
| private static List<MailAddress> GetEmailList() { | |
| var list = new List<MailAddress>(); | |
| var selection = Globals.ThisAddIn.Application.Selection; | |
| foreach (var item in selection) { | |
| try { | |
| var email = new MailAddress(((Range)item).Value2); | |
| list.Add(email); | |
| } catch (FormatException) { | |
| //email is invalid | |
| } | |
| } | |
| return list; | |
| } | |
| private static string GetSegmentName() { | |
| var segmentNameForm = new SegmentNameInput(); | |
| segmentNameForm.ShowDialog(); | |
| var segmentName = segmentNameForm.SegmentName; | |
| if (segmentNameForm.Cancelled || string.IsNullOrEmpty(segmentName)) | |
| return null; | |
| return segmentName; | |
| } | |
| public string CreateStaticSegmentFromSelection() { | |
| //get the email list | |
| var emailList = GetEmailList(); | |
| if (emailList.Count == 0) { | |
| return Resources.NoEmails; | |
| } | |
| //Get the segment name | |
| var segmentName = GetSegmentName(); | |
| if (string.IsNullOrEmpty(segmentName)) { | |
| return Resources.MissingSegmentName; | |
| } | |
| var listId = Astd.BrontoHelper.BrontoHelper.CreateList(segmentName); | |
| if (string.IsNullOrEmpty(listId)) { | |
| return Resources.GroupExists; | |
| } | |
| var errors = 0; | |
| if (!string.IsNullOrEmpty(listId)) | |
| errors += Astd.BrontoHelper.BrontoHelper.AddContactsToList(listId, emailList); | |
| return errors == 0 ? Resources.GroupCreatedSuccess : string.Format("Your list was created successfully but there were {0} errors during the process.", errors); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment