/// <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
                });
            }
        }
        private static ContactImport BuildContactImport(List <ConstantContactMember> members, List <string> listNames)
        {
            ContactImport import = new ContactImport
            {
                ImportData  = BuildMemberImportData(members),
                Lists       = listNames,
                ColumnNames = _importColumnNames
            };

            return(import);
        }
        public void Import(ContactImport importFile)
        {
            // todo: process file
            //      validate/sanitise file

            // for each contact
            //dedupe against DB
            // upsert


            // todo: method should return status/error result but left void for now
        }
        public static async Task <ConstantContactBulkResponse> ExportConstantContactList(List <ConstantContactMember> members, string listId)
        {
            var listNames = new List <string> {
                listId
            };

            ContactImport import = BuildContactImport(members, listNames);

            var bulkActivitiesService = ConstantContactHelper.BulkListsService();

            BulkActivityResponse response = await bulkActivitiesService.ImportContactsAsync(import);


            return(new ConstantContactBulkResponse
            {
                Id = response.Id,
                ContactCount = int.Parse(response.ContactCount),
                ErrorCount = int.Parse(response.ErrorCount)
            });
        }
示例#5
0
    protected void btnWebMailLogin_Click(object sender, System.EventArgs e)
    {
        AjaxPro.Utility.RegisterTypeForAjax(typeof(ImportEmails));

        member = (Member)Session["Member"];

        if (member == null)
        {
            Response.Redirect("/signup");
        }

        if (this.txtUserID.Text == "" || this.txtPassword.Text == "")
        {
            return;
        }

        Regex isNumeric = new Regex(@"^\d+$");

        //strip email address
        string Login = txtUserID.Text;

        int AtSignIndex = Login.IndexOf("@");

        if (AtSignIndex > 0)
        {
            if (emailCat.SelectedValue.ToLower() != "linkedin.com")
            {
                Login = Login.Substring(0, AtSignIndex);
            }
        }

        DateTime start = DateTime.Now;

        contactImporter = new ContactImporter(Login, txtPassword.Text, emailCat.SelectedValue);

        contactImporter.login();

        LoginOkay = contactImporter.logged_in;

        if (LoginOkay)
        {
            try
            {
                contactImporter.getcontacts();
                fetch = DateTime.Now - start;
            }
            catch { }

            this.nameArray  = contactImporter.nameArray;
            this.emailArray = contactImporter.emailArray;

            for (int i = 0; i < emailArray.Length; i++)
            {
                emailArray[i] = emailArray[i].ToLower();
            }

            string ImportToken = Next2Friends.Misc.UniqueID.NewWebID();

            //insert into the db so they can be referenced by JoinEmailsWithMembers
            for (int i = 0; i < emailArray.Length; i++)
            {
                ContactImport contact = new ContactImport();

                contact.WebID            = Next2Friends.Misc.UniqueID.NewWebID();
                contact.ImporterMemberID = member.MemberID;
                contact.Email            = emailArray[i];
                contact.Name             = nameArray[i];
                contact.FriendState      = (int)FriendState.None;
                contact.InviteState      = (int)InviteState.None;
                contact.ImportToken      = ImportToken;
                contact.IsInitialImport  = 1;

                contact.SaveWithCheck();
            }

            FullContacts = new List <ContactImport>();
            List <ContactImport> MemberList = new List <ContactImport>();

            //List<ContactImport> ExistingContactList = ContactImport.GetAllContactImportByMemberID(member.MemberID);

            if (emailArray.Length > 0)
            {
                MemberList = ContactImport.JoinEmailsWithMembers(member.MemberID, emailArray, ImportToken);
            }

            List <Member> FriendList = Member.GetAllFriendsByMemberID(member.MemberID);

            for (int i = 0; i < emailArray.Length; i++)
            {
                int friendState = (int)FriendState.None;
                int inviteState = (int)InviteState.None;

                ContactImport Associcate = MemberList.FirstOrDefault(f => f.Email == emailArray[i]);

                if (Associcate != null)
                {
                    friendState = Associcate.FriendState;
                    inviteState = Associcate.InviteState;
                }

                ContactImport contact = new ContactImport();

                contact.WebID            = Next2Friends.Misc.UniqueID.NewWebID();
                contact.ImporterMemberID = member.MemberID;
                contact.Email            = emailArray[i];
                contact.Name             = nameArray[i];
                contact.FriendState      = friendState;
                contact.InviteState      = inviteState;

                FullContacts.Add(contact);
            }

            var sortedContacts =
                from c in FullContacts
                where c.Email != string.Empty
                orderby c.Name
                select c;

            FullContacts = sortedContacts.ToList();

            Imported    = true;
            ImportCount = FullContacts.Count;

            Session["Contacts"] = FullContacts;

            BuildContactList();

            ImportStage = true;

            HelperMessage = "<p style='color:#0257AE'>You may now choose your contacts to invite</p>";
        }
        else
        {
            BuildLetterIndexList();
            Session["Contacts"] = null;
            HelperMessage       = "<p style='color:red;'>Login details are incorrect, please try again</p>";
        }
    }
示例#6
0
    protected void ImportAndInvite()
    {
        FullContacts = (List <ContactImport>)Session["Contacts"];

        if (FullContacts == null)
        {
            ImportStage   = false;
            HelperMessage = "<p style='color:#0257AE'>Your session timed out<br /> Log into your webmail account below</p>";
            BuildLetterIndexList();

            return;
        }

        string[] EmailInviteList = Request.Form["emaillist"].Split(new char[] { ',' });
        string[] FriendnviteList = Request.Form["friendlist"].Split(new char[] { ',' });

        foreach (string key in EmailInviteList)
        {
            string WebIDKey = key;

            if (key.Length > 0)
            {
                WebIDKey = key.Substring(1);
            }

            ContactImport contact = FullContacts.FirstOrDefault(e => e.WebID == WebIDKey);

            if (contact != null)
            {
                // make sure noone has hacked the checkboxes client side to send again..
                if (contact.InviteState == (int)InviteState.None)
                {
                    contact.InviteState = (int)InviteState.InviteSent;
                }
            }
        }

        foreach (string key in FriendnviteList)
        {
            string WebIDKey = key;

            if (key.Length > 0)
            {
                WebIDKey = key.Substring(1);
            }

            ContactImport contact = FullContacts.FirstOrDefault(e => e.WebID == WebIDKey);

            if (contact != null)
            {
                if (contact.FriendState == (int)FriendState.None)
                {
                    //could fire off the friend request here
                    if (contact.InviteState == (int)InviteState.AlreadyAMember)
                    {
                        FriendRequest.CreateWebFriendRequestFromEmail(member.MemberID, contact.Email);
                    }

                    contact.FriendState = (int)FriendState.InviteSent;
                }
            }
        }

        ImportStage       = false;
        HelperMessage     = "<p style='color:#0257AE'>Your invites have been sent<br /> Login to another account to invite more</p>";
        ContactBoxMessage = "Your friends have been invited";
        AsyncImport();
        BuildLetterIndexList();

        Session["Contacts"] = FullContacts;
    }