Esempio n. 1
0
        protected override void ClearForm()
        {
            CurrentAspNetId = null;
            DisplayProfileTabs(false);

            chkIsLockedOut.Checked = false;
            chkIsLockedOut.Enabled = true;

            cbCanyonRanchCustomer.Checked = false;

            txtEmail.Text       = string.Empty;
            txtProfileName.Text = string.Empty;
            txtFirstName.Text   = string.Empty;
            txtLastName.Text    = string.Empty;
            ddlCoupons.ClearSelection();
            //ddlDeliveryTypes.ClearSelection();

            BillingInfoEdit1.Clear();

            AddressEdit_Shipping1.Clear();
            AddressEdit_Shipping1.EnableFields = false;

            ////preferences
            ProfilePrefsEdit1.Clear();

            ////allergens
            ProfileAllgsEdit1.Clear();

            //subprofiles
            SubProfileEdit1.Clear();
            gvwSubProfiles.DataSource = null;
            gvwSubProfiles.DataBind();
        }
Esempio n. 2
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;
            }
        }
Esempio n. 3
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;
            }
        }
        protected override void LoadForm()
        {
            try
            {
                MembershipUser user = Helpers.LoggedUser;

                //form fields
                if (user != null)
                {
                    CurrentUserProfile = hccUserProfile.GetParentProfileBy((Guid)user.ProviderUserKey);

                    if (Roles.IsUserInRole("Customer"))
                    {
                        if (CurrentUserProfile == null)
                        {
                            CurrentUserProfile = new hccUserProfile
                            {
                                AccountBalance = 0.0m,
                                CreatedBy      = (Guid)user.ProviderUserKey,
                                CreatedDate    = DateTime.Now,
                                IsActive       = true,
                                MembershipID   = (Guid)user.ProviderUserKey,
                                ModifiedBy     = (Guid)user.ProviderUserKey,
                                ModifiedDate   = DateTime.Now
                            };

                            CurrentUserProfile.Save();
                        }

                        if (CurrentUserProfile != null)
                        {
                            this.PrimaryKeyIndex = CurrentUserProfile.UserProfileID;

                            //Basic Info
                            BasicEdit1.PrimaryKeyIndex = this.PrimaryKeyIndex;
                            BasicEdit1.Bind();

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

                            ProfileNotesEdit_Shipping.CurrentUserProfileId = CurrentUserProfile.UserProfileID;
                            ProfileNotesEdit_Shipping.Bind();

                            //billing address
                            BillingInfoEdit1.PrimaryKeyIndex         = CurrentUserProfile.UserProfileID;
                            BillingInfoEdit1.CurrentBillingAddressID = CurrentUserProfile.BillingAddressID;
                            BillingInfoEdit1.Bind();

                            ProfileNotesEdit_Billing.CurrentUserProfileId = CurrentUserProfile.UserProfileID;
                            ProfileNotesEdit_Billing.Bind();

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

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

                            //subprofiles
                            BindgvwSubProfiles();
                            SubProfileEdit1.CurrentParentAspNetId  = (Guid)user.ProviderUserKey;
                            SubProfileEdit1.CurrentParentProfileId = CurrentUserProfile.UserProfileID;

                            //order history
                            PurchaseHistory1.CurrentAspNetId = (Guid)user.ProviderUserKey;
                            PurchaseHistory1.Bind();

                            //Recurring Orders
                            UserProfileRecurringOrders.CurrentAspNetId = (Guid)user.ProviderUserKey;
                            UserProfileRecurringOrders.Bind();
                        }
                    }
                    else
                    {
                        //This Account exists but doesn't have the Customer Role
                        //pnl_js_noncustomer.Visible = true;
                        li_link_01.Visible = false;
                        panel1.Visible     = false;
                        li_link_02.Visible = false;
                        panel2.Visible     = false;
                        li_link_03.Visible = false;
                        panel3.Visible     = false;
                        li_link_04.Visible = false;
                        panel4.Visible     = false;
                        li_link_05.Visible = false;
                        panel5.Visible     = false;
                        li_link_06.Visible = false;
                        panel6.Visible     = false;
                        li_link_07.Visible = false;
                        panel7.Visible     = false;
                        li_link_09.Visible = false;
                        panel9.Visible     = false;

                        if (CurrentUserProfile != null)
                        {
                            CurrentUserProfile.Activation(false);
                        }
                    }
                }
                else
                {
                    FormsAuthentication.RedirectToLoginPage();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }