Beispiel #1
0
        void ProfileLedger1_ControlSaved(object sender, ControlSavedEventArgs e)
        {
            if (CurrentUserProfile == null)
            {
                CurrentUserProfile = hccUserProfile.GetById(this.PrimaryKeyIndex);
            }

            if (CurrentUserProfile != null)
            {
                ProfileCartEdit1.PrimaryKeyIndex = CurrentUserProfile.UserProfileID;
                ProfileCartEdit1.Bind();
            }
        }
Beispiel #2
0
        void BillingInfoEdit1_ControlSaved(object sender, ControlSavedEventArgs e)
        {
            if (CurrentUserProfile == null)
            {
                CurrentUserProfile = hccUserProfile.GetParentProfileBy(CurrentAspNetId.Value);
            }

            if (CurrentUserProfile != null)
            {
                CurrentUserProfile.BillingAddressID = BillingInfoEdit1.CurrentBillingAddressID;
                CurrentUserProfile.Save();
            }

            // some profile value changed, make sure order numbers for current cart are still inline with one another
            SessionManager.CurrentUserProfileInfoChanged = true;

            ProfileCartEdit1.Bind();
        }
Beispiel #3
0
        protected override void LoadForm()
        {
            try
            {
                BindcblRoles();
                //BindrblDeliveryTypes();
                BindddlCoupons();

                //form fields
                if (CurrentAspNetId != null)
                {
                    divPassword.Visible = true;

                    MembershipUser user = Membership.GetUser(CurrentAspNetId);

                    chkIsLockedOut.Checked = user.IsLockedOut;
                    chkIsActive.Checked    = user.IsApproved;

                    if ((Guid)user.ProviderUserKey == (Guid)Helpers.LoggedUser.ProviderUserKey)
                    {
                        chkIsLockedOut.Enabled = false;
                    }

                    txtEmail.Text = user.Email;

                    string[] userRoles = Roles.GetRolesForUser(user.UserName);

                    foreach (string role in userRoles)
                    {
                        ListItem roleItem = cblRoles.Items.FindByValue(role);

                        if (roleItem != null)
                        {
                            roleItem.Selected = true;
                        }
                    }

                    if (userRoles.ToList().Count(a => a == "Customer") > 0)
                    {
                        DisplayProfileTabs(true);
                    }
                    else
                    {
                        DisplayProfileTabs(false);
                    }

                    PasswordReset1.CurrentAspNetId = CurrentAspNetId;

                    CurrentUserProfile = hccUserProfile.GetParentProfileBy((Guid)user.ProviderUserKey);

                    if (CurrentUserProfile == null)
                    {
                        hccUserProfile newProfile = new hccUserProfile
                        {
                            MembershipID   = (Guid)user.ProviderUserKey,
                            CreatedBy      = (Guid)Helpers.LoggedUser.ProviderUserKey,
                            CreatedDate    = DateTime.Now,
                            ProfileName    = string.Empty,
                            AccountBalance = 0.00m,
                            IsActive       = true
                        };

                        newProfile.Save();
                        CurrentUserID.Value  = newProfile.MembershipID.ToString();
                        CurrentUserProfile   = newProfile;
                        this.PrimaryKeyIndex = newProfile.UserProfileID;
                    }


                    if (CurrentUserProfile != null)
                    {
                        txtProfileName.Text = CurrentUserProfile.ProfileName;
                        txtFirstName.Text   = CurrentUserProfile.FirstName;
                        txtLastName.Text    = CurrentUserProfile.LastName;

                        // Canyon Ranch
                        if (CurrentUserProfile.CanyonRanchCustomer != null)
                        {
                            cbCanyonRanchCustomer.Checked = CurrentUserProfile.CanyonRanchCustomer.Value;
                        }

                        if (CurrentUserProfile.DefaultCouponId.HasValue)
                        {
                            ddlCoupons.SelectedIndex = ddlCoupons.Items.IndexOf(
                                ddlCoupons.Items.FindByValue(CurrentUserProfile.DefaultCouponId.ToString()));
                        }

                        //billing info
                        BillingInfoEdit1.PrimaryKeyIndex = CurrentUserProfile.UserProfileID;
                        BillingInfoEdit1.Bind();

                        //shipping address
                        if (CurrentUserProfile.ShippingAddressID.HasValue)
                        {
                            AddressEdit_Shipping1.PrimaryKeyIndex = CurrentUserProfile.ShippingAddressID.Value;
                            AddressEdit_Shipping1.Bind();
                        }

                        //preferences
                        ProfilePrefsEdit1.PrimaryKeyIndex = CurrentUserProfile.UserProfileID;
                        ProfilePrefsEdit1.Bind();

                        //allergens
                        ProfileAllgsEdit1.PrimaryKeyIndex = CurrentUserProfile.UserProfileID;
                        ProfileAllgsEdit1.Bind();

                        //subprofiles
                        BindgvwSubProfiles();
                        SubProfileEdit1.CurrentParentAspNetId  = CurrentAspNetId;
                        SubProfileEdit1.CurrentParentProfileId = CurrentUserProfile.UserProfileID;

                        //order history
                        BindHistory(); //0);

                        // recurring
                        BindRecurring();

                        //ledger
                        BindLedger();

                        //notes
                        ProfileNotesEdit_Billing.CurrentUserProfileId = CurrentUserProfile.UserProfileID;
                        ProfileNotesEdit_Billing.Bind();
                        ProfileNotesEdit_General.CurrentUserProfileId = CurrentUserProfile.UserProfileID;
                        ProfileNotesEdit_General.Bind();
                        ProfileNotesEdit_Shipping.CurrentUserProfileId = CurrentUserProfile.UserProfileID;
                        ProfileNotesEdit_Shipping.Bind();

                        //current cart
                        ProfileCartEdit1.PrimaryKeyIndex = CurrentUserProfile.UserProfileID;
                        ProfileCartEdit1.Bind();
                    }
                }
                else
                {
                    cblRoles.Items.FindByText("Customer").Selected = true;
                    DisplayProfileTabs(true);

                    liBilling.Visible      = false;
                    liShipping.Visible     = false;
                    liPrefs.Visible        = false;
                    liAllergens.Visible    = false;
                    liSubProfiles.Visible  = false;
                    liNotes.Visible        = false;
                    liTransactions.Visible = false;
                    liPurchases.Visible    = false;
                    liCart.Visible         = false;

                    tabs2.Visible  = false;
                    tabs3.Visible  = false;
                    tabs4.Visible  = false;
                    tabs5.Visible  = false;
                    tabs6.Visible  = false;
                    tabs8.Visible  = false;
                    tabs10.Visible = false;
                    tabs7.Visible  = false;
                    tabs9.Visible  = false;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #4
0
        protected override void SaveForm()
        {
            try
            {
                MembershipUser user = null;

                if (CurrentAspNetId != null)
                {
                    user = Membership.GetUser(CurrentAspNetId);
                }
                else
                {
                    try
                    {
                        user = Membership.GetUser(Membership.GetUserNameByEmail(txtEmail.Text.Trim()));
                    }
                    catch (Exception) { }
                }

                if (user == null) // create new profile
                {
                    // create membership user

                    //formulate username
                    string email    = txtEmail.Text.Trim();
                    string userName = email.Split('@')[0] + DateTime.Now.ToString("yyyyMMddHHmmtt");
                    string password = OrderNumberGenerator.GenerateOrderNumber("?#?#?#?#");

                    MembershipCreateStatus createResult;
                    MembershipUser         newUser = Membership.CreateUser(userName, password, email, null, null, true, out createResult);

                    List <ListItem> selRoles = cblRoles.Items.OfType <ListItem>().Where(a => a.Selected).ToList();
                    selRoles.ForEach(delegate(ListItem item) { Roles.AddUserToRole(userName, item.Value); });

                    if (createResult == MembershipCreateStatus.Success)
                    {
                        CurrentAspNetId = (Guid)newUser.ProviderUserKey;

                        Email.EmailController ec = new Email.EmailController();
                        ec.SendMail_NewUserConfirmation(email, password);

                        if (selRoles.Where(a => a.Text.Contains("Customer")).Count() > 0)
                        {
                            hccUserProfile newProfile = new hccUserProfile
                            {
                                MembershipID = (Guid)newUser.ProviderUserKey,
                                CreatedBy    = (Guid)Helpers.LoggedUser.ProviderUserKey,
                                CreatedDate  = DateTime.Now,
                                ProfileName  = txtProfileName.Text.Trim(),
                                FirstName    = txtFirstName.Text.Trim(),
                                LastName     = txtLastName.Text.Trim(),
                                IsActive     = true
                            };

                            if (ddlCoupons.SelectedIndex > 0)
                            {
                                newProfile.DefaultCouponId = int.Parse(ddlCoupons.SelectedValue);
                            }
                            else
                            {
                                newProfile.DefaultCouponId = null;
                            }

                            newProfile.Save();
                            CurrentUserID.Value  = newProfile.MembershipID.ToString();
                            this.PrimaryKeyIndex = newProfile.UserProfileID;
                            Response.Redirect("~/WebModules/ShoppingCart/Admin/AccountManager.aspx?UserID=" + newProfile.MembershipID.ToString(), false);
                        }

                        liBilling.Visible      = true;
                        liShipping.Visible     = true;
                        liPrefs.Visible        = true;
                        liAllergens.Visible    = true;
                        liSubProfiles.Visible  = true;
                        liNotes.Visible        = true;
                        liTransactions.Visible = true;
                        liPurchases.Visible    = true;
                        liCart.Visible         = true;

                        tabs2.Visible  = true;
                        tabs3.Visible  = true;
                        tabs4.Visible  = true;
                        tabs5.Visible  = true;
                        tabs6.Visible  = true;
                        tabs8.Visible  = true;
                        tabs10.Visible = true;
                        tabs7.Visible  = true;
                        tabs9.Visible  = true;

                        LoadForm();

                        OnSaved(new ControlSavedEventArgs(newUser.ProviderUserKey));
                    }
                    else
                    {
                        cstValProfile0.Enabled      = true;
                        cstValProfile0.ErrorMessage = Helpers.CreateUserStatusMessage(createResult);
                        cstValProfile0.Validate();
                        Page.Validate();
                    }
                }
                else // edit existing profile
                {
                    if (user.Email != txtEmail.Text.Trim()) // update userprofile and aspmembership user
                    {
                        user.Email = txtEmail.Text.Trim();
                        Membership.UpdateUser(user);
                    }

                    if (chkIsLockedOut.Checked)
                    {
                        Helpers.LockUser(user);
                    }
                    else
                    {
                        if (user.IsLockedOut)
                        {
                            user.UnlockUser();
                        }

                        if (!user.IsApproved)
                        {
                            user.IsApproved = true;
                            Membership.UpdateUser(user);
                        }
                    }


                    List <ListItem> selRoles = cblRoles.Items.OfType <ListItem>().Where(a => a.Selected).ToList();
                    if (Roles.IsUserInRole(Helpers.LoggedUser.UserName, "Administrators"))
                    {
                        Roles.GetAllRoles().ToList().ForEach(delegate(string roleName)
                        {
                            if (Roles.IsUserInRole(user.UserName, roleName))
                            {
                                Roles.RemoveUserFromRole(user.UserName, roleName);
                            }
                        });

                        selRoles.ForEach(delegate(ListItem item)
                        {
                            Roles.AddUserToRole(user.UserName, item.Value);
                        });
                    }

                    hccUserProfile editProfile = hccUserProfile.GetParentProfileBy((Guid)user.ProviderUserKey);

                    if (editProfile == null && selRoles.Where(a => a.Text.Contains("Customer")).Count() > 0)
                    {
                        editProfile = new hccUserProfile
                        {
                            MembershipID        = (Guid)user.ProviderUserKey,
                            CreatedBy           = (Guid)Helpers.LoggedUser.ProviderUserKey,
                            CreatedDate         = DateTime.Now,
                            ProfileName         = txtProfileName.Text.Trim(),
                            FirstName           = txtFirstName.Text.Trim(),
                            LastName            = txtLastName.Text.Trim(),
                            CanyonRanchCustomer = cbCanyonRanchCustomer.Checked
                        };

                        editProfile.Save();
                        this.PrimaryKeyIndex = editProfile.UserProfileID;

                        OnSaved(new ControlSavedEventArgs(editProfile.UserProfileID));
                    }

                    if (editProfile != null)
                    {
                        editProfile.ProfileName = txtProfileName.Text.Trim();
                        editProfile.FirstName   = txtFirstName.Text.Trim();
                        editProfile.LastName    = txtLastName.Text.Trim();

                        editProfile.CanyonRanchCustomer = cbCanyonRanchCustomer.Checked;

                        if (ddlCoupons.SelectedIndex > 0)
                        {
                            editProfile.DefaultCouponId = int.Parse(ddlCoupons.SelectedValue);
                        }
                        else
                        {
                            editProfile.DefaultCouponId = null;
                        }

                        editProfile.Save();

                        if (!ProfilePrefsEdit1.ShowSave)
                        {
                            ProfilePrefsEdit1.Save();
                        }

                        if (!ProfileAllgsEdit1.ShowSave)
                        {
                            ProfileAllgsEdit1.Save();
                        }

                        ProfileCartEdit1.Bind();

                        OnSaved(new ControlSavedEventArgs(editProfile.UserProfileID));
                    }
                    OnSaved(new ControlSavedEventArgs(editProfile.UserProfileID));
                }
            }
            catch (ProviderException pex)
            {
                lblFeedback.Text = pex.Message;
            }
            catch
            {
                throw;
            }
        }