private void SaveWareHouse() { _Warehouse.Name = Name.Text; _Warehouse.Address1 = Address1.Text; _Warehouse.Address2 = Address2.Text; _Warehouse.City = City.Text; _Warehouse.Province = (Province.Visible ? Province.Text : Province2.SelectedValue); _Warehouse.PostalCode = PostalCode.Text; _Warehouse.CountryCode = Country.SelectedValue; _Warehouse.Phone = Phone.Text; _Warehouse.Fax = Fax.Text; _Warehouse.Email = Email.Text; IAddressValidatorService validationService = AddressValidatorServiceLocator.Locate(); if (validationService != null) { validationService.ValidateAddress(_Warehouse); } _Warehouse.Save(); }
protected void SaveButton_Click(object sender, EventArgs e) { if (Page.IsValid) { Warehouse warehouse = new Warehouse(); warehouse.Name = Name.Text; warehouse.Address1 = Address1.Text; warehouse.Address2 = Address2.Text; warehouse.City = City.Text; warehouse.Province = (Province.Visible ? Province.Text : Province2.SelectedValue); warehouse.PostalCode = PostalCode.Text; warehouse.CountryCode = Country.SelectedValue; warehouse.Phone = Phone.Text; warehouse.Fax = Fax.Text; warehouse.Email = Email.Text; IAddressValidatorService validationService = AddressValidatorServiceLocator.Locate(); if (validationService != null) { validationService.ValidateAddress(warehouse); } warehouse.Save(); Response.Redirect("Default.aspx"); } }
protected void EditSaveButton_Click(object sender, EventArgs e) { string buttonId = ((Button)sender).ID; string provinceName; if (ValidateProvince(out provinceName)) { if (Page.IsValid) { Address address = this.Address; string address1 = StringHelper.StripHtml(Address1.Text.Trim()); string address2 = StringHelper.StripHtml(Address2.Text.Trim()); string city = StringHelper.StripHtml(City.Text.Trim()); string postalCode = StringHelper.StripHtml(PostalCode.Text.Trim()); if (address.Address1 != address1 || address.Address2 != address2 || address.City != city || address.Province != provinceName || address.PostalCode != postalCode) { address.Validated = false; } if (buttonId == "UseValidAddressButton") { int id = AlwaysConvert.ToInt(ValidAddressesList.SelectedValue); address.Validated = true; if (id > 0) { if (ValidAddresses != null && buttonId == "UseValidAddressButton") { ValidAddress validAddress = (from va in ValidAddresses where va.Id == id select va).SingleOrDefault(); if (validAddress != null) { address1 = validAddress.Address1; address2 = validAddress.Address2; city = validAddress.City; provinceName = validAddress.Province; postalCode = validAddress.PostalCode; } } } ValidAddresses = null; } address.FirstName = StringHelper.StripHtml(FirstName.Text); address.LastName = StringHelper.StripHtml(LastName.Text); address.Address1 = address1; address.Address2 = address2; address.Company = StringHelper.StripHtml(Company.Text); address.City = city; address.Province = provinceName; address.PostalCode = postalCode; address.CountryCode = Country.SelectedValue; address.Phone = StringHelper.StripHtml(Phone.Text); address.Fax = StringHelper.StripHtml(Fax.Text); address.Residence = (Residence.SelectedIndex == 0); AbleContext.Current.User.Addresses.Add(address); address.Save(); this.AddressId = address.Id; if (!address.Validated && _addressValidator != null) { AddressValidationResponse avr = _addressValidator.ValidateAddress(address); if (avr != null) { if (!avr.IsValid.HasValue || !avr.IsValid.Value) { ValidAddresses = avr.Addresses; if (ValidAddresses != null) { int index = 0; foreach (ValidAddress validAddress in ValidAddresses) { validAddress.Id = ++index; } ValidAddressesList.DataSource = ValidAddresses; ValidAddressesList.DataBind(); ValidAddressesPanel.Visible = true; ValidAddressesList.Items.Add(new ListItem("Use the address exactly as I entered it", "0")); ValidAddressesList.Items[0].Selected = true; if (ValidAddressesList.Items.Count > 1) { PHAddressFound.Visible = true; PHNoAddress.Visible = false; } else { PHAddressFound.Visible = false; PHNoAddress.Visible = true; } return; } } } } ShowAddressBook(); } } else { Province2Invalid.IsValid = false; UpdateCountry(); } }
private bool UpdateAddress(bool validate) { // NEED TO REGISTER USER if (AbleContext.Current.User.IsAnonymous) { if (CreateNewAccountPanel.Visible) { if (!CreateNewAccount()) { return(false); } else { CreateNewAccountPanel.Visible = false; } } else { // VALIDATE EMAIL, IF EMAIL IS ALREADY REGISTERED, ASK FOR LOGIN string newEmail = StringHelper.StripHtml(BillToEmail.Text); if (UserDataSource.IsEmailRegistered(newEmail)) { InvalidRegistration.IsValid = false; InvalidRegistration.ErrorMessage = "The email address you have provided is already registered. Please sign in to access your account."; return(false); } // ANONYMOUS USER SELECTING GUEST CHECKOUT, CREATE TEMPORARY ACCOUNT User oldUser = AbleContext.Current.User; string newUserName = "******" + Guid.NewGuid().ToString("N") + "@domain.xyz"; string newPassword = Guid.NewGuid().ToString("N"); MembershipCreateStatus createStatus; User newUser = UserDataSource.CreateUser(newUserName, newEmail, newPassword, string.Empty, string.Empty, true, 0, out createStatus); // IF THE CREATE FAILS, IGNORE AND CONTINUE CREATING THE ORDER if (createStatus == MembershipCreateStatus.Success) { // CHANGE THE NAME AND EMAIL TO SOMETHING MORE FRIENDLY THAN GUID newUser.UserName = "******" + newUser.Id.ToString() + "@domain.xyz"; newUser.Save(); CommerceBuilder.Users.User.Migrate(oldUser, newUser, true, true); AbleContext.Current.User = newUser; FormsAuthentication.SetAuthCookie(newUser.UserName, false); } } } // MAILING LIST SIGNUP if (EmailLists.Visible && EmailLists.Items.Count > 0) { string email = AbleContext.Current.User.Email; int listIndex = 0; IList <EmailList> emailLists = GetPublicEmailLists(); if (emailLists != null && emailLists.Count > 0) { foreach (ListViewDataItem item in EmailLists.Items) { EmailList list = emailLists[listIndex]; CheckBox selected = (CheckBox)item.FindControl("Selected"); if (selected != null) { if (selected.Checked) { EmailListSignup signup = EmailListSignupDataSource.Load(list.Id, email); if (signup == null || signup.SignupDate < LocaleHelper.LocalNow.AddMinutes(-5)) { list.ProcessSignupRequest(email); } } else { list.RemoveMember(email); } } else { list.RemoveMember(email); } listIndex++; } } } string provinceName = string.Empty; if (ValidateProvince(out provinceName)) { Address address = AbleContext.Current.User.PrimaryAddress; string address1 = StringHelper.StripHtml(Address1.Text); string address2 = StringHelper.StripHtml(Address2.Text); string city = StringHelper.StripHtml(City.Text); string postColde = StringHelper.StripHtml(PostalCode.Text); if (address.Address1 != address1 || address.Address2 != address2 || address.City != city || address.Province != provinceName || address.PostalCode != postColde) { address.Validated = false; } address.FirstName = StringHelper.StripHtml(FirstName.Text); address.LastName = StringHelper.StripHtml(LastName.Text); address.Address1 = address1; address.Address2 = address2; address.Company = StringHelper.StripHtml(Company.Text); address.Email = trEmail.Visible ? StringHelper.StripHtml(BillToEmail.Text) : StringHelper.StripHtml(UserName.Text); address.City = city; address.Province = provinceName; address.PostalCode = postColde; address.CountryCode = Country.SelectedValue; address.Phone = StringHelper.StripHtml(Telephone.Text); address.Fax = StringHelper.StripHtml(Fax.Text); address.Residence = !IsBusinessAddress.Checked; address.Save(); if (validate && !address.Validated && _addressValidator != null) { AddressValidationResponse avr = _addressValidator.ValidateAddress(address); if (avr != null) { if (!avr.IsValid.HasValue || !avr.IsValid.Value) { ValidAddresses = avr.Addresses; if (ValidAddresses != null) { int index = 0; foreach (ValidAddress validAddress in ValidAddresses) { validAddress.Id = ++index; } ValidAddressesList.DataSource = ValidAddresses; ValidAddressesList.DataBind(); ValidAddressesPanel.Visible = true; ValidAddressesList.Items.Add(new ListItem("Use the address exactly as I entered it", "0")); ValidAddressesList.Items[0].Selected = true; if (ValidAddressesList.Items.Count > 1) { PHAddressFound.Visible = true; PHNoAddress.Visible = false; } else { PHAddressFound.Visible = false; PHNoAddress.Visible = true; } return(false); } } } } } else { Province2Invalid.IsValid = false; UpdateCountry(); return(false); } return(true); }