Exemplo 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();
        }
        protected override void ClearForm()
        {
            BillingInfoEdit1.Clear();

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

            //subprofiles
            SubProfileEdit1.Clear();
            gvwSubProfiles.DataSource = null;
            gvwSubProfiles.DataBind();
        }
 protected void chxSameBillingAddress_CheckedChanged(object sender, EventArgs e)
 {
     if (chxSameBillingAddress.Checked)
     {
         AddressEdit_Billing1.CurrentAddress = AddressEdit_Shipping1.GetCloningAddress();
         AddressEdit_Billing1.Bind();
     }
     else
     {
         AddressEdit_Billing1.Clear();
     }
 }
Exemplo n.º 4
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;
            }
        }
        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;
            }
        }
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            try
            {
                Page.Validate("NewUserGroup");

                if (Page.IsValid)
                {
                    //Fill cart from anonymous user
                    MembershipUser user = Membership.GetUser();

                    if (user != null)
                    {
                        CurrentCart = hccCart.GetCurrentCart(user);
                    }
                    else
                    {
                        CurrentCart = hccCart.GetCurrentCart();
                    }

                    UserRegistration_Module userRegistrationModule = null;
                    WebpageInfo             confirmPage            = null;

                    if (null != this.WebModuleInfo)
                    {
                        UserRegistration_Module.Get(this.WebModuleInfo.Id);
                    }

                    //formulate username
                    if (CurrentAspNetId != null)
                    {
                        user = Membership.GetUser(CurrentAspNetId);
                    }

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

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

                    if (createResult == MembershipCreateStatus.Success)
                    {
                        //Assign Customer role to newUser
                        Roles.AddUserToRole(newUser.UserName, "Customer");

                        //log in user.
                        FormsAuthentication.SetAuthCookie(newUser.UserName, false);

                        //Create a Healthy Chef profile for this new user
                        hccUserProfile newProfile = new hccUserProfile
                        {
                            MembershipID   = (Guid)newUser.ProviderUserKey,
                            CreatedBy      = (Membership.GetUser() == null ? Guid.Empty : (Guid)Membership.GetUser().ProviderUserKey),
                            CreatedDate    = DateTime.Now,
                            AccountBalance = 0.00m,
                            IsActive       = true
                        };

                        //save Shipping Address
                        AddressEdit_Shipping1.Save();
                        newProfile.ShippingAddressID = AddressEdit_Shipping1.PrimaryKeyIndex;
                        newProfile.FirstName         = AddressEdit_Shipping1.CurrentAddress.FirstName.Trim();
                        newProfile.LastName          = AddressEdit_Shipping1.CurrentAddress.LastName.Trim();
                        newProfile.ProfileName       = AddressEdit_Shipping1.CurrentAddress.FirstName.Trim();

                        //save Billing Address
                        AddressEdit_Billing1.Save();
                        newProfile.BillingAddressID = AddressEdit_Billing1.PrimaryKeyIndex;

                        //Save all hccProfile information
                        newProfile.Save();

                        //Credit Card
                        try
                        {
                            CreditCard1.CurrentUserProfileID = newProfile.UserProfileID;
                            CreditCard1.Save();
                        }
                        catch { }

                        //Update previously anonymously-created hccCart
                        CurrentCart.AspNetUserID = newProfile.MembershipID;
                        CurrentCart.Save();

                        List <hccCartItem> cartItems = hccCartItem.GetBy(CurrentCart.CartID);
                        cartItems.ForEach(delegate(hccCartItem ci) { ci.UserProfileID = newProfile.UserProfileID; ci.Save(); });

                        //Send E-mail notification to account user
                        try
                        {
                            HealthyChef.Email.EmailController ec = new HealthyChef.Email.EmailController();
                            ec.SendMail_NewUserConfirmation(email, password);
                        }
                        catch { }

                        if (null != userRegistrationModule)
                        {
                            if (!string.IsNullOrEmpty(userRegistrationModule.NotifyEmailAddress))
                            {
                                SecurityEmail.Send(userRegistrationModule.NotifyEmailAddress,
                                                   "New user registration",
                                                   "A new user is waiting for approval. To manage users, click this link:\n"
                                                   + Request.Url.Scheme
                                                   + "://"
                                                   + Request.Url.Authority
                                                   + "/WebModules/Security/Manage/UserList.aspx"
                                                   );
                            }

                            if (!DisableRedirect)
                            {
                                confirmPage = Webpage.GetWebpage(userRegistrationModule.ConfirmationPageNavigationId);
                                if (null != confirmPage)
                                {
                                    Response.Redirect(confirmPage.Path);
                                }
                                else
                                {
                                    if (Request.QueryString["fc"] != null)
                                    {
                                        HttpContext.Current.Response.Redirect("~/cart.aspx?confirm=1", false);
                                    }
                                    else
                                    {
                                        if (newUser != null)
                                        {
                                            HttpContext.Current.Response.Redirect(FormsAuthentication.GetRedirectUrl(newUser.UserName, false));
                                        }
                                        else
                                        {
                                            HttpContext.Current.Response.Redirect("~/", false);
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (Request.QueryString["fc"] != null)
                            {
                                HttpContext.Current.Response.Redirect("~/cart.aspx?confirm=1", false);
                            }
                            else
                            {
                                if (newUser != null)
                                {
                                    HttpContext.Current.Response.Redirect(FormsAuthentication.GetRedirectUrl(newUser.UserName, false));
                                }
                                else
                                {
                                    HttpContext.Current.Response.Redirect("~/", false);
                                }
                            }
                        }
                    }
                    else
                    {
                        Msg.ShowError(UserRegistration_Module.GetHumanStatusMessage(createResult));
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }