/// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        if (customerObj == null)
        {
            return;
        }

        if (!ECommerceContext.IsUserAuthorizedToModifyCustomer())
        {
            RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyCustomers");
        }

        if (customerId != 0)
        {
            string errorMessage = new Validator().NotEmpty(txtAddressLine1.Text, "Customer_Edit_Address_Edit.rqvLine")
                                  .NotEmpty(txtAddressCity.Text, "Customer_Edit_Address_Edit.rqvCity")
                                  .NotEmpty(txtAddressZip.Text, "Customer_Edit_Address_Edit.rqvZipCode")
                                  .NotEmpty(txtPersonalName.Text, "Customer_Edit_Address_Edit.rqvPersonalName").Result;

            // Check country presence
            if (errorMessage == "" && (ucCountrySelector.CountryID <= 0))
            {
                errorMessage = GetString("countryselector.selectedcountryerr");
            }

            if (errorMessage == "")
            {
                // Get object
                AddressInfo addressObj = AddressInfoProvider.GetAddressInfo(addressId);
                if (addressObj == null)
                {
                    addressObj = new AddressInfo();
                }

                addressObj.AddressIsBilling    = chkAddressIsBilling.Checked;
                addressObj.AddressIsShipping   = chkAddressIsShipping.Checked;
                addressObj.AddressZip          = txtAddressZip.Text.Trim();
                addressObj.AddressPhone        = txtAddressDeliveryPhone.Text.Trim();
                addressObj.AddressPersonalName = txtPersonalName.Text.Trim();
                addressObj.AddressLine1        = txtAddressLine1.Text.Trim();
                addressObj.AddressEnabled      = chkAddressEnabled.Checked;
                addressObj.AddressLine2        = txtAddressLine2.Text.Trim();
                addressObj.AddressCity         = txtAddressCity.Text.Trim();
                addressObj.AddressCountryID    = ucCountrySelector.CountryID;
                addressObj.AddressStateID      = ucCountrySelector.StateID;
                addressObj.AddressIsCompany    = chkAddressIsCompany.Checked;
                addressObj.AddressName         = AddressInfoProvider.GetAddressName(addressObj);
                addressObj.AddressCustomerID   = customerId;

                AddressInfoProvider.SetAddressInfo(addressObj);

                URLHelper.Redirect("Customer_Edit_Address_Edit.aspx?customerId=" + customerId + "&addressId=" + Convert.ToString(addressObj.AddressID) + "&saved=1");
            }
            else
            {
                lblError.Visible = true;
                lblError.Text    = errorMessage;
            }
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// On btnOK click, save edited or new created address.
    /// </summary>
    protected void btnOK_OnClick(object sender, EventArgs e)
    {
        if (mCustomerId != 0)
        {
            // Check field emptiness
            string errorMessage = new Validator().NotEmpty(txtAddressLine1.Text, "Customer_Edit_Address_Edit.rqvLine").NotEmpty(txtAddressCity.Text, "Customer_Edit_Address_Edit.rqvCity").NotEmpty(txtAddressZip.Text, "Customer_Edit_Address_Edit.rqvZipCode").NotEmpty(txtPersonalName.Text, "Customer_Edit_Address_Edit.rqvPersonalName").Result;

            // Check country presence
            if ((errorMessage == "") && (ucCountrySelector.CountryID <= 0))
            {
                errorMessage = GetString("countryselector.selectedcountryerr");
            }

            if (errorMessage == "")
            {
                AddressInfo ai = null;
                // Create new addressinfo or get the existing one
                if (AddressId == 0)
                {
                    ai = new AddressInfo();
                    ai.AddressEnabled    = true;
                    ai.AddressIsBilling  = true;
                    ai.AddressIsShipping = true;
                    ai.AddressIsCompany  = true;
                    ai.AddressCustomerID = mCustomerId;
                }
                else
                {
                    ai = AddressInfoProvider.GetAddressInfo(AddressId);
                }

                if (ai != null)
                {
                    ai.AddressPersonalName = txtPersonalName.Text;
                    ai.AddressLine1        = txtAddressLine1.Text;
                    ai.AddressLine2        = txtAddressLine2.Text;
                    ai.AddressCity         = txtAddressCity.Text;
                    ai.AddressZip          = txtAddressZip.Text;
                    ai.AddressCountryID    = ucCountrySelector.CountryID;
                    ai.AddressStateID      = ucCountrySelector.StateID;
                    ai.AddressPhone        = txtAddressDeliveryPhone.Text;
                    ai.AddressName         = AddressInfoProvider.GetAddressName(ai);
                    // Save addressinfo
                    AddressInfoProvider.SetAddressInfo(ai);
                    AddressId = ai.AddressID;

                    lblInfo.Visible = true;
                    lblAddress.Text = "> " + HTMLHelper.HTMLEncode(ai.AddressName);
                }
            }
            else
            {
                lblError.Visible = true;
                lblError.Text    = errorMessage;
            }
        }
    }
Exemplo n.º 3
0
        /// <summary>
        /// Saves the address into the database.
        /// </summary>
        /// <param name="validate">Specifies whether the validation should be performed.</param>
        public void Save(bool validate = true)
        {
            if (validate)
            {
                var result = Validate();
                if (result.CheckFailed)
                {
                    throw new InvalidOperationException();
                }
            }

            OriginalAddress.AddressName = AddressInfoProvider.GetAddressName(OriginalAddress);
            AddressInfoProvider.SetAddressInfo(OriginalAddress);
        }
    private IAddress SaveAddress(IAddress addressObject, CustomerInfo customer)
    {
        AddressInfo address = addressObject as AddressInfo;

        if (address == null)
        {
            return(null);
        }

        if (string.IsNullOrEmpty(address.AddressPersonalName))
        {
            address.AddressPersonalName = TextHelper.LimitLength(string.Format("{0} {1}", customer.CustomerFirstName, customer.CustomerLastName), 200);
        }

        address.AddressCustomerID = customer.CustomerID;
        address.AddressName       = AddressInfoProvider.GetAddressName(address);
        AddressInfoProvider.SetAddressInfo(address);

        return(address);
    }
Exemplo n.º 5
0
    void EditForm_OnBeforeSave(object sender, EventArgs e)
    {
        if (CreateNewAddress)
        {
            var newAddress = EditForm.EditedObject as AddressInfo;

            if (newAddress == null)
            {
                return;
            }

            // Ensure address name
            if (String.IsNullOrEmpty(newAddress.AddressName))
            {
                newAddress.AddressName = AddressInfoProvider.GetAddressName(newAddress);
            }

            // Ensure customer
            if (newAddress.AddressCustomerID <= 0)
            {
                newAddress.AddressCustomerID = CurrentCustomerID;
            }
        }
    }
    public override bool ProcessStep()
    {
        string siteName = SiteContext.CurrentSiteName;

        if (IsExistingAccount())
        {
            // Sign in customer with existing account

            // Authenticate user
            //UserInfo ui = UserInfoProvider.GetUserInfo(txtLogin.Text);

            UserInfo ui = AuthenticationHelper.AuthenticateUser(txtLogin.Text.Trim(), txtMotDePasse.Text, SiteContext.CurrentSiteName);

            if (ui == null)
            {
                // ShowError(ResHelper.GetString("ShoppingCartCheckRegistration.LoginFailed"));
                return(false);
            }

            // Set current user
            MembershipContext.AuthenticatedUser = new CurrentUserInfo(ui, true);
            UserInfoProvider.SetPreferredCultures(ui);

            // Sign in
            FormsAuthentication.SetAuthCookie(ui.UserName, false);

            // Registered user has already started shopping as anonymous user -> Drop his stored shopping cart
            ShoppingCartInfoProvider.DeleteShoppingCartInfo(ui.UserID, siteName);

            // Assign current user to the current shopping cart
            ShoppingCart.User = ui;

            // Save changes to database // Already done in the end of this method
            if (!this.ShoppingCartControl.IsInternalOrder)
            {
                ShoppingCartInfoProvider.SetShoppingCartInfo(this.ShoppingCartInfObj);
            }

            //Create a customer for the user if do not yet exist
            CustomerInfo ci = CustomerInfoProvider.GetCustomerInfoByUserID(this.ShoppingCartControl.UserInfo.UserID);
            if (ci == null)
            {
                ci = new CustomerInfo();
                ci.CustomerUserID  = this.ShoppingCartControl.UserInfo.UserID;
                ci.CustomerEnabled = true;
            }

            // Old email address
            //string oldEmail = ci.CustomerEmail.ToLower(); ;

            ci.CustomerFirstName = ui.FirstName;
            ci.CustomerLastName  = ui.LastName;
            ci.CustomerEmail     = ui.Email;

            ci.CustomerCompany           = "";
            ci.CustomerOrganizationID    = "";
            ci.CustomerTaxRegistrationID = "";

            // Update customer data
            CustomerInfoProvider.SetCustomerInfo(ci);

            // Set the shopping cart customer ID
            this.ShoppingCart.ShoppingCartCustomerID = ci.CustomerID;
        }
        else if (IsNewAccount())
        {
            txtEmail2.Text             = txtEmail2.Text.Trim();
            pnlCompanyAccount1.Visible = chkCorporateBody.Checked;

            // Check if user exists
            UserInfo ui = UserInfoProvider.GetUserInfo(txtEmail2.Text);
            if (ui != null)
            {
                lblError.Visible = true;
                lblError.Text    = GetString("ShoppingCartUserRegistration.ErrorUserExists");
                return(false);
            }

            // Check all sites where user will be assigned
            string checkSites = (String.IsNullOrEmpty(ShoppingCartControl.AssignToSites)) ? SiteContext.CurrentSiteName : ShoppingCartControl.AssignToSites;
            if (!UserInfoProvider.IsEmailUnique(txtEmail2.Text.Trim(), checkSites, 0))
            {
                lblError.Visible = true;
                lblError.Text    = GetString("UserInfo.EmailAlreadyExist");
                return(false);
            }

            // Create new customer and user account and sign in
            // User



            ui = new UserInfo();


            ui.UserName  = txtEmailRegistration.Text.Trim();
            ui.Email     = txtEmailRegistration.Text.Trim();
            ui.FirstName = txtFirstName.Text.Trim();
            ui.FullName  = UserInfoProvider.GetFullName(txtFirstName.Text.Trim(), String.Empty, txtLastName.Text.Trim());
            ui.LastName  = txtLastName.Text.Trim();
            ui.Enabled   = true;
            ui.UserIsGlobalAdministrator = false;
            ui.UserURLReferrer           = MembershipContext.AuthenticatedUser.URLReferrer;
            ui.UserCampaign = AnalyticsHelper.Campaign;
            ui.UserSettings.UserRegistrationInfo.IPAddress = RequestContext.UserHostAddress;
            ui.UserSettings.UserRegistrationInfo.Agent     = HttpContext.Current.Request.UserAgent;

            try
            {
                UserInfoProvider.SetPassword(ui, txtMotDePasseRegistration.Text);

                string[] siteList;

                // If AssignToSites field set
                if (!String.IsNullOrEmpty(ShoppingCartControl.AssignToSites))
                {
                    siteList = ShoppingCartControl.AssignToSites.Split(';');
                }
                else // If not set user current site
                {
                    siteList = new string[] { siteName };
                }

                foreach (string site in siteList)
                {
                    UserInfoProvider.AddUserToSite(ui.UserName, site);

                    // Add user to roles
                    if (ShoppingCartControl.AssignToRoles != "")
                    {
                        AssignUserToRoles(ui.UserName, ShoppingCartControl.AssignToRoles, site);
                    }
                }

                // Log registered user
                AnalyticsHelper.LogRegisteredUser(siteName, ui);

                Activity activity = new ActivityRegistration(ui, DocumentContext.CurrentDocument, AnalyticsContext.ActivityEnvironmentVariables);
                if (activity.Data != null)
                {
                    activity.Data.ContactID = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui);
                    activity.Log();
                }
            }
            catch (Exception ex)
            {
                lblError.Visible = true;
                lblError.Text    = ex.Message;
                return(false);
            }

            // Customer
            CustomerInfo ci = new CustomerInfo();
            ci.CustomerFirstName = txtFirstName.Text.Trim();
            ci.CustomerLastName  = txtLastName.Text.Trim();
            ci.CustomerEmail     = txtEmailRegistration.Text.Trim();

            ci.CustomerCompany           = "";
            ci.CustomerOrganizationID    = "";
            ci.CustomerTaxRegistrationID = "";
            if (chkCorporateBody.Checked)
            {
                ci.CustomerCompany = txtCompany1.Text.Trim();
                if (mShowOrganizationIDField)
                {
                    ci.CustomerOrganizationID = txtOrganizationID.Text.Trim();
                }
                if (mShowTaxRegistrationIDField)
                {
                    ci.CustomerTaxRegistrationID = txtTaxRegistrationID.Text.Trim();
                }
            }

            ci.CustomerUserID  = ui.UserID;
            ci.CustomerSiteID  = 0;
            ci.CustomerEnabled = true;
            ci.CustomerCreated = DateTime.Now;
            CustomerInfoProvider.SetCustomerInfo(ci);

            // Track successful registration conversion
            string name = ShoppingCartControl.RegistrationTrackConversionName;
            ECommerceHelper.TrackRegistrationConversion(ShoppingCart.SiteName, name);

            // Log "customer registration" activity and update profile
            var activityCustomerRegistration = new ActivityCustomerRegistration(ci, MembershipContext.AuthenticatedUser, AnalyticsContext.ActivityEnvironmentVariables);
            if (activityCustomerRegistration.Data != null)
            {
                if (ContactID <= 0)
                {
                    activityCustomerRegistration.Data.ContactID = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui);
                }
                activityCustomerRegistration.Log();
            }

            // Sign in
            if (ui.UserEnabled)
            {
                CMSContext.AuthenticateUser(ui.UserName, false);
                ShoppingCart.User = ui;

                ContactID = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui);
                Activity activity = new ActivityUserLogin(ContactID, ui, DocumentContext.CurrentDocument, AnalyticsContext.ActivityEnvironmentVariables);
                activity.Log();
            }

            ShoppingCart.ShoppingCartCustomerID = ci.CustomerID;

            // Send new registration notification email
            if (ShoppingCartControl.SendNewRegistrationNotificationToAddress != "")
            {
                SendRegistrationNotification(ui);
            }
            /**aadrresse*/
            // Process billing address
            //------------------------
            int         CountryID  = ValidationHelper.GetInteger(ddlShippingCountry.SelectedValue, 0);
            AddressInfo ai         = null;
            bool        newAddress = true;
            ai = new AddressInfo();
            string mCustomerName = ci.CustomerFirstName + " " + ci.CustomerLastName;
            // newAddress.AddressName = mCustomerName + " , " + txtAdresse.Text + " - " + txtCodePostale.Text + " " + txtVille.Text;


            ai.AddressPersonalName = mCustomerName + " , " + txtAdresse.Text + " - " + txtCodePostale.Text + " " + txtVille.Text;
            ai.AddressLine1        = txtAdresse.Text.Trim();
            ai.AddressLine2        = txtAdresse.Text.Trim();
            ai.AddressCity         = txtVille.Text.Trim();
            ai.AddressZip          = txtCodePostale.Text.Trim();
            ai.AddressCountryID    = CountryID;


            if (newAddress)
            {
                ai.AddressIsBilling  = true;
                ai.AddressIsShipping = !chkShippingAddr.Checked;
                ai.AddressEnabled    = true;
            }
            ai.AddressCustomerID = ci.CustomerID;
            ai.AddressName       = AddressInfoProvider.GetAddressName(ai);

            // Save address and set it's ID to ShoppingCartInfoObj
            AddressInfoProvider.SetAddressInfo(ai);

            // Update current contact's address
            ModuleCommands.OnlineMarketingMapAddress(ai, ContactID);

            ShoppingCart.ShoppingCartBillingAddressID = ai.AddressID;

            // If shopping cart does not need shipping
            if (!ShippingOptionInfoProvider.IsShippingNeeded(ShoppingCart))
            {
                ShoppingCart.ShoppingCartShippingAddressID = 0;
            }
            // If shipping address is different from billing address
            else if (chkShippingAddr.Checked)
            {
                //// Check country presence
                //if (CountrySelector2.CountryID <= 0)
                //{
                //    lblError.Visible = true;
                //    lblError.Text = GetString("countryselector.selectedcountryerr");
                //    return false;
                //}

                //if (!CountrySelector2.StateSelectionIsValid)
                //{
                //    lblError.Visible = true;
                //    lblError.Text = GetString("countryselector.selectedstateerr");
                //    return false;
                //}

                //newAddress = false;
                //// Process shipping address
                ////-------------------------
                //ai = AddressInfoProvider.GetAddressInfo(Convert.ToInt32(drpShippingAddr.SelectedValue));
                //if (ai == null)
                //{
                //    ai = new AddressInfo();
                //    newAddress = true;
                //}

                ai.AddressPersonalName = txtadresseshipping.Text.Trim();
                ai.AddressLine1        = txtadresseshipping.Text.Trim();
                ai.AddressLine2        = txtadresseshipping.Text.Trim();
                ai.AddressCity         = txtvilleshipping.Text.Trim();
                ai.AddressZip          = txtcpshipping.Text.Trim();
                ai.AddressCountryID    = CountryID;

                if (newAddress)
                {
                    ai.AddressIsShipping = true;
                    ai.AddressEnabled    = true;
                    ai.AddressIsBilling  = false;
                    ai.AddressIsCompany  = false;
                    ai.AddressEnabled    = true;
                }
                ai.AddressCustomerID = ci.CustomerID;
                ai.AddressName       = AddressInfoProvider.GetAddressName(ai);

                // Save address and set it's ID to ShoppingCartInfoObj
                AddressInfoProvider.SetAddressInfo(ai);
                ShoppingCart.ShoppingCartShippingAddressID = ai.AddressID;
            }
            // Shipping address is the same as billing address
            else
            {
                ShoppingCart.ShoppingCartShippingAddressID = ShoppingCart.ShoppingCartBillingAddressID;
            }
            /**finadrress*/
            this.ShoppingCartControl.ButtonNextClickAction();
        }

        try
        {
            if (!this.ShoppingCartControl.IsInternalOrder)
            {
                ShoppingCartInfoProvider.SetShoppingCartInfo(this.ShoppingCart);
            }
            return(true);
        }
        catch
        {
            return(false);
        }
    }
    /// <summary>
    /// Process valid values of this step.
    /// </summary>
    public override bool ProcessStep()
    {
        if (mCustomerId > 0)
        {
            // Clean the viewstate
            RemoveBillingTempValues();
            RemoveShippingTempValues();
            RemoveCompanyTempValues();

            // Check country presence
            if (CountrySelector1.CountryID <= 0)
            {
                lblError.Visible = true;
                lblError.Text    = GetString("countryselector.selectedcountryerr");
                return(false);
            }

            if (!CountrySelector1.StateSelectionIsValid)
            {
                lblError.Visible = true;
                lblError.Text    = GetString("countryselector.selectedstateerr");
                return(false);
            }

            // Process billing address
            //------------------------
            var ai = AddressInfoProvider.GetAddressInfo(ValidationHelper.GetInteger(drpBillingAddr.SelectedValue, 0)) ?? new AddressInfo();
            ai.AddressPersonalName = GetTruncatedTextBoxInput(txtBillingName);
            ai.AddressLine1        = GetTruncatedTextBoxInput(txtBillingAddr1);
            ai.AddressLine2        = GetTruncatedTextBoxInput(txtBillingAddr2);
            ai.AddressCity         = GetTruncatedTextBoxInput(txtBillingCity);
            ai.AddressZip          = GetTruncatedTextBoxInput(txtBillingZip);
            ai.AddressCountryID    = CountrySelector1.CountryID;
            ai.AddressStateID      = CountrySelector1.StateID;
            ai.AddressPhone        = GetTruncatedTextBoxInput(txtBillingPhone);
            ai.AddressCustomerID   = mCustomerId;
            ai.AddressName         = AddressInfoProvider.GetAddressName(ai);

            // Save address and set it's ID to ShoppingCartInfoObj
            AddressInfoProvider.SetAddressInfo(ai);

            // Update current contact's address
            MapContactAddress(ai);

            ShoppingCart.ShoppingCartBillingAddress = ai;

            // If shopping cart does not need shipping
            if (!ShoppingCart.IsShippingNeeded)
            {
                ShoppingCart.ShoppingCartShippingAddress = null;
            }
            // If shipping address is different from billing address
            else if (chkShippingAddr.Checked)
            {
                // Check country presence
                if (CountrySelector2.CountryID <= 0)
                {
                    lblError.Visible = true;
                    lblError.Text    = GetString("countryselector.selectedcountryerr");
                    return(false);
                }

                if (!CountrySelector2.StateSelectionIsValid)
                {
                    lblError.Visible = true;
                    lblError.Text    = GetString("countryselector.selectedstateerr");
                    return(false);
                }

                // Process shipping address
                //-------------------------
                ai = AddressInfoProvider.GetAddressInfo(Convert.ToInt32(drpShippingAddr.SelectedValue)) ?? new AddressInfo();
                ai.AddressPersonalName = GetTruncatedTextBoxInput(txtShippingName);
                ai.AddressLine1        = GetTruncatedTextBoxInput(txtShippingAddr1);
                ai.AddressLine2        = GetTruncatedTextBoxInput(txtShippingAddr2);
                ai.AddressCity         = GetTruncatedTextBoxInput(txtShippingCity);
                ai.AddressZip          = GetTruncatedTextBoxInput(txtShippingZip);
                ai.AddressCountryID    = CountrySelector2.CountryID;
                ai.AddressStateID      = CountrySelector2.StateID;
                ai.AddressPhone        = GetTruncatedTextBoxInput(txtShippingPhone);
                ai.AddressCustomerID   = mCustomerId;
                ai.AddressName         = AddressInfoProvider.GetAddressName(ai);

                // Save address and set it's ID to ShoppingCartInfoObj
                AddressInfoProvider.SetAddressInfo(ai);
                ShoppingCart.ShoppingCartShippingAddress = ai;
            }
            // Shipping address is the same as billing address
            else
            {
                ShoppingCart.ShoppingCartShippingAddress = ShoppingCart.ShoppingCartBillingAddress;
            }

            if (chkCompanyAddress.Checked)
            {
                // Check country presence
                if (CountrySelector3.CountryID <= 0)
                {
                    lblError.Visible = true;
                    lblError.Text    = GetString("countryselector.selectedcountryerr");
                    return(false);
                }

                if (!CountrySelector3.StateSelectionIsValid)
                {
                    lblError.Visible = true;
                    lblError.Text    = GetString("countryselector.selectedstateerr");
                    return(false);
                }

                // Process company address
                //-------------------------
                ai = AddressInfoProvider.GetAddressInfo(Convert.ToInt32(drpCompanyAddress.SelectedValue)) ?? new AddressInfo();
                ai.AddressPersonalName = GetTruncatedTextBoxInput(txtCompanyName);
                ai.AddressLine1        = GetTruncatedTextBoxInput(txtCompanyLine1);
                ai.AddressLine2        = GetTruncatedTextBoxInput(txtCompanyLine2);
                ai.AddressCity         = GetTruncatedTextBoxInput(txtCompanyCity);
                ai.AddressZip          = GetTruncatedTextBoxInput(txtCompanyZip);
                ai.AddressCountryID    = CountrySelector3.CountryID;
                ai.AddressStateID      = CountrySelector3.StateID;
                ai.AddressPhone        = GetTruncatedTextBoxInput(txtCompanyPhone);
                ai.AddressCustomerID   = mCustomerId;
                ai.AddressName         = AddressInfoProvider.GetAddressName(ai);

                // Save address and set it's ID to ShoppingCartInfoObj
                AddressInfoProvider.SetAddressInfo(ai);
                ShoppingCart.ShoppingCartCompanyAddress = ai;
            }
            // Company address is the same as billing address
            else
            {
                // Save information about company address or not (according to the site settings)
                if (ECommerceSettings.UseExtraCompanyAddress(mCurrentSite.SiteName))
                {
                    ShoppingCart.ShoppingCartCompanyAddress = ShoppingCart.ShoppingCartBillingAddress;
                }
                else
                {
                    ShoppingCart.ShoppingCartCompanyAddress = null;
                }
            }

            try
            {
                ShoppingCart.Evaluate();

                // Update changes in database only when on the live site
                if (!ShoppingCartControl.IsInternalOrder)
                {
                    ShoppingCartInfoProvider.SetShoppingCartInfo(ShoppingCart);
                }
                return(true);
            }
            catch (Exception ex)
            {
                // Show error message
                lblError.Visible = true;
                lblError.Text    = ex.Message;
                return(false);
            }
        }
        else
        {
            lblError.Visible = true;
            lblError.Text    = GetString("Ecommerce.NoCustomerSelected");
            return(false);
        }
    }
Exemplo n.º 8
0
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Check 'EcommerceModify' permission
        if (!ECommerceContext.IsUserAuthorizedForPermission("ModifyCustomers"))
        {
            RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyCustomers");
        }

        if (customerId != 0)
        {
            string errorMessage = new Validator().NotEmpty(txtAddressLine1.Text, "Customer_Edit_Address_Edit.rqvLine").NotEmpty(txtAddressCity.Text, "Customer_Edit_Address_Edit.rqvCity").NotEmpty(txtAddressZip.Text, "Customer_Edit_Address_Edit.rqvZipCode").NotEmpty(txtPersonalName.Text, "Customer_Edit_Address_Edit.rqvPersonalName").Result;

            // Check country presence
            if ((errorMessage == "") && (ucCountrySelector.CountryID <= 0))
            {
                errorMessage = GetString("countryselector.selectedcountryerr");
            }

            if ((errorMessage == "") && !ucCountrySelector.StateSelectionIsValid)
            {
                errorMessage = GetString("countryselector.selectedstateerr");
            }

            if (errorMessage == "")
            {
                AddressInfo addressObj = AddressInfoProvider.GetAddressInfo(addressId);

                // if address doesn't already exist, create new one
                if (addressObj == null)
                {
                    addressObj = new AddressInfo();
                    addressObj.AddressIsShipping = false;
                    addressObj.AddressIsBilling  = false;
                    addressObj.AddressIsCompany  = false;
                }

                switch (typeId)
                {
                // Shipping addres selection
                case 0:
                    addressObj.AddressIsShipping = true;
                    break;

                // Billing addres selection
                case 1:
                    addressObj.AddressIsBilling = true;
                    break;

                // Company addres selection
                case 2:
                    addressObj.AddressIsCompany = true;
                    break;

                default:
                    break;
                }

                // Set address object data
                addressObj.AddressZip          = txtAddressZip.Text.Trim();
                addressObj.AddressPhone        = txtAddressDeliveryPhone.Text.Trim();
                addressObj.AddressPersonalName = txtPersonalName.Text.Trim();
                addressObj.AddressLine1        = txtAddressLine1.Text.Trim();
                addressObj.AddressEnabled      = chkAddressEnabled.Checked;
                addressObj.AddressLine2        = txtAddressLine2.Text.Trim();
                addressObj.AddressCity         = txtAddressCity.Text.Trim();
                addressObj.AddressCountryID    = ucCountrySelector.CountryID;
                addressObj.AddressStateID      = ucCountrySelector.StateID;
                addressObj.AddressCustomerID   = customerId;
                addressObj.AddressName         = AddressInfoProvider.GetAddressName(addressObj);
                addressObj.SetValue("AddressNumber", txtnum.Text);

                AddressInfoProvider.SetAddressInfo(addressObj);

                ltlScript.Text = ScriptHelper.GetScript("if(wopener.AddressChange!=null){wopener.AddressChange('" + addressObj.AddressID + "');}CloseDialog();");
            }
            else
            {
                // Show error message
                ShowError(errorMessage);
            }
        }
    }
Exemplo n.º 9
0
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        if (customerObj == null)
        {
            return;
        }

        if (!ECommerceContext.IsUserAuthorizedToModifyCustomer())
        {
            RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyCustomers");
        }

        if (customerId != 0)
        {
            string errorMessage = new Validator().NotEmpty(txtAddressLine1.Text, "Customer_Edit_Address_Edit.rqvLine")
                                  .NotEmpty(txtAddressCity.Text, "Customer_Edit_Address_Edit.rqvCity")
                                  .NotEmpty(txtAddressZip.Text, "Customer_Edit_Address_Edit.rqvZipCode")
                                  .NotEmpty(txtPersonalName.Text, "Customer_Edit_Address_Edit.rqvPersonalName").Result;

            // Check country presence
            if (errorMessage == "" && (ucCountrySelector.CountryID <= 0))
            {
                errorMessage = GetString("countryselector.selectedcountryerr");
            }
            if (errorMessage == "" && (!string.IsNullOrEmpty(txtnum.Text)))
            {
                int result;
                if (int.TryParse(txtnum.Text, out result))
                {
                    //ok, do something
                }
                else
                {
                    errorMessage = "Number is not valid";
                }
            }
            if (errorMessage == "")
            {
                // Get object
                AddressInfo addressObj = AddressInfoProvider.GetAddressInfo(addressId);
                if (addressObj == null)
                {
                    addressObj = new AddressInfo();
                }

                // Set address object data
                addressObj.AddressIsBilling    = chkAddressIsBilling.Checked;
                addressObj.AddressIsShipping   = chkAddressIsShipping.Checked;
                addressObj.AddressZip          = txtAddressZip.Text.Trim();
                addressObj.AddressPhone        = txtAddressDeliveryPhone.Text.Trim();
                addressObj.AddressPersonalName = txtPersonalName.Text.Trim();
                addressObj.AddressLine1        = txtAddressLine1.Text.Trim();
                addressObj.AddressEnabled      = chkAddressEnabled.Checked;
                addressObj.AddressLine2        = txtAddressLine2.Text.Trim();
                addressObj.AddressCity         = txtAddressCity.Text.Trim();
                addressObj.AddressCountryID    = ucCountrySelector.CountryID;
                addressObj.AddressStateID      = ucCountrySelector.StateID;
                addressObj.AddressIsCompany    = chkAddressIsCompany.Checked;
                addressObj.AddressName         = AddressInfoProvider.GetAddressName(addressObj);
                addressObj.AddressCustomerID   = customerId;
                addressObj.SetValue("AddressNumber", txtnum.Text);

                AddressInfoProvider.SetAddressInfo(addressObj);

                // Redirect to editing UI
                URLHelper.Redirect("Customer_Edit_Address_Edit.aspx?customerId=" + customerId + "&addressId=" + Convert.ToString(addressObj.AddressID) + "&saved=1");
            }
            else
            {
                // Show error message
                ShowError(errorMessage);
            }
        }
    }