protected void SaveButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                // DETERMINE SELECTED LISTS
                List <int> offList = new List <int>();
                List <int> onList  = new List <int>();
                int        index   = 0;
                foreach (RepeaterItem item in dlEmailLists.Items)
                {
                    int      tempListId = AlwaysConvert.ToInt(((HiddenField)item.FindControl("EmailListId")).Value);
                    CheckBox selected   = (CheckBox)item.FindControl("Selected");
                    if ((selected != null) && (selected.Checked))
                    {
                        onList.Add(tempListId);
                    }
                    else
                    {
                        offList.Add(tempListId);
                    }
                    index++;
                }
                string email = AbleContext.Current.User.Email;

                // PROCESS LISTS THAT SHOULD NOT BE SUBSCRIBED
                foreach (int emailListId in offList)
                {
                    EmailListUser elu = EmailListUserDataSource.Load(emailListId, email);
                    if (elu != null)
                    {
                        elu.Delete();
                    }
                }

                // PROCESS LISTS THAT SHOULD BE SUBSCRIBED
                foreach (int emailListId in onList)
                {
                    EmailListUser elu = EmailListUserDataSource.Load(emailListId, email);
                    if (elu == null)
                    {
                        EmailList list = EmailListDataSource.Load(emailListId);
                        if (list != null)
                        {
                            list.ProcessSignupRequest(email);
                        }
                    }
                }

                // DISPLAY RESULT
                ConfirmationMsg.Visible = true;
            }
        }
        protected void UpdateButton_Click(object sender, EventArgs e)
        {
            List <int> offList = new List <int>();
            List <int> onList  = new List <int>();
            //LOOP THROUGH SIGNUP LIST
            int index = 0;

            foreach (DataListItem item in dlEmailLists.Items)
            {
                int      tempListId = (int)dlEmailLists.DataKeys[index];
                CheckBox selected   = (CheckBox)item.FindControl("Selected");
                if ((selected != null) && (selected.Checked))
                {
                    onList.Add(tempListId);
                }
                else
                {
                    offList.Add(tempListId);
                }
                index++;
            }
            string email = AbleContext.Current.User.Email;

            //PROCESS LISTS THAT SHOULD NOT BE SUBSCRIBED
            foreach (int emailListId in offList)
            {
                EmailListUser elu = EmailListUserDataSource.Load(emailListId, email);
                if (elu != null)
                {
                    elu.Delete();
                }
            }
            //PROCESS LISTS THAT SHOULD BE SUBSCRIBED
            IDatabaseSessionManager database = AbleContext.Current.Database;

            database.BeginTransaction();
            foreach (int emailListId in onList)
            {
                EmailListUser elu = EmailListUserDataSource.Load(emailListId, email);
                if (elu == null)
                {
                    EmailList list = EmailListDataSource.Load(emailListId);
                    if (list != null)
                    {
                        list.ProcessSignupRequest(email);
                    }
                }
            }
            //DISPLAY CONFIRMATION
            UpdatedMessage.Visible = true;
            database.CommitTransaction();
        }
        private void UpdateEmailLists()
        {
            // DETERMINE SELECTED LISTS
            List <int> offList = new List <int>();
            List <int> onList  = new List <int>();
            int        index   = 0;

            foreach (DataListItem item in dlEmailLists.Items)
            {
                int      tempListId = (int)dlEmailLists.DataKeys[index];
                CheckBox selected   = (CheckBox)item.FindControl("Selected");
                if ((selected != null) && (selected.Checked))
                {
                    onList.Add(tempListId);
                }
                else
                {
                    offList.Add(tempListId);
                }
                index++;
            }
            string email = AbleContext.Current.User.Email;

            // PROCESS LISTS THAT SHOULD NOT BE SUBSCRIBED
            foreach (int emailListId in offList)
            {
                EmailListUser elu = EmailListUserDataSource.Load(emailListId, email);
                if (elu != null)
                {
                    elu.Delete();
                }
            }

            // PROCESS LISTS THAT SHOULD BE SUBSCRIBED
            IDatabaseSessionManager database = AbleContext.Current.Database;

            database.BeginTransaction();
            foreach (int emailListId in onList)
            {
                EmailListUser elu = EmailListUserDataSource.Load(emailListId, email);
                if (elu == null)
                {
                    EmailList list = EmailListDataSource.Load(emailListId);
                    if (list != null)
                    {
                        list.ProcessSignupRequest(email);
                    }
                }
            }
            database.CommitTransaction();
        }
예제 #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string action = Request.QueryString["action"];

            if (!string.IsNullOrEmpty(action))
            {
                //DETERMINE THE ACTION
                action = action.ToLowerInvariant();
                if (action == "remove")
                {
                    //delete user from the list
                    int    emailListId = AlwaysConvert.ToInt(Request.QueryString["list"]);
                    string email       = Request.QueryString["email"];
                    string key         = Request.QueryString["key"];
                    AbleContext.Current.Database.BeginTransaction();
                    EmailList list = EmailListDataSource.Load(emailListId);
                    if ((list != null) && (email != null))
                    {
                        string        eluKey = string.Empty;
                        EmailListUser elu    = EmailListUserDataSource.Load(emailListId, email);
                        if (elu != null)
                        {
                            eluKey = elu.SignupDate.ToString("MMddyyhhmmss");
                        }
                        if (key == eluKey)
                        {
                            list.RemoveMember(email);
                            phMessage.Controls.Add(new LiteralControl(string.Format(this.DeletedMessage, list.Name)));
                        }
                    }
                    AbleContext.Current.Database.CommitTransaction();
                }
                else if (action == "confirm")
                {
                    //ADD USER TO LIST
                    int    emailListId = AlwaysConvert.ToInt(Request.QueryString["list"]);
                    string email       = Request.QueryString["email"];
                    string key         = Request.QueryString["key"];
                    AbleContext.Current.Database.BeginTransaction();
                    EmailList list = EmailListDataSource.Load(emailListId);
                    if ((list == null) || !ValidationHelper.IsValidEmail(email))
                    {
                        Response.Redirect(AbleCommerce.Code.NavigationHelper.GetHomeUrl());
                    }
                    EmailListSignup signup = EmailListSignupDataSource.Load(emailListId, email);
                    if (signup != null)
                    {
                        if (key == signup.SignupKey)
                        {
                            signup.Activate();

                            //confirm user subscription
                            phMessage.Controls.Add(new LiteralControl(string.Format(this.SubscribedMessage, list.Name)));
                        }
                    }
                    else if (EmailListUserDataSource.Load(emailListId, email) != null)
                    {
                        //CHECK IF USER HAS ALREADY ACTIVATED
                        //confirm user subscription
                        phMessage.Controls.Add(new LiteralControl(string.Format(this.SubscribedMessage, list.Name)));
                    }
                    AbleContext.Current.Database.CommitTransaction();
                }
                else if (action == "unsubrr")
                {
                    int    userId = AlwaysConvert.ToInt(Request.QueryString["uid"]);
                    string email  = Request.QueryString["email"];
                    if (string.IsNullOrEmpty(email))
                    {
                        return;
                    }

                    CommerceBuilder.Users.User user = CommerceBuilder.Users.UserDataSource.Load(userId);
                    if (user != null && email.ToLowerInvariant() == user.Email.ToLowerInvariant())
                    {
                        user.Settings.OptOutReviewReminders = true;
                        user.Save();
                        string message = "You have successfully unsubscribed from all future product review invitations. If you are a registered user, you may join again by logging into your account and updating your profile.";
                        phMessage.Controls.Add(new LiteralControl(message));
                    }
                }
            }

            //IF RESPONSE IS EMPTY, REQUEST IS INVALID
            if (phMessage.Controls.Count == 0)
            {
                phMessage.Controls.Add(new LiteralControl(this.InvalidMessage));
            }
        }