protected void Page_PreRender(object sender, EventArgs e)
        {
            // Do we have an existing Main Address ?
            CustomerAddressInfo customerAddress = Controller.GetCustomerMainAddress(this.MainControl.CustomerId);

            if (customerAddress == null)
            {
                List <CustomerAddressInfo> customerSecondaryAddresses = Controller.GetCustomerAddresses(this.MainControl.CustomerId);

                if (customerSecondaryAddresses.Count > 0)
                {
                    customerAddress           = customerSecondaryAddresses[0];
                    customerAddress.IsDefault = true;
                    Controller.UpdateCustomerAddress(customerAddress);
                }
                else
                {
                    // Create New Address
                    customerAddress = new CustomerAddressInfo();

                    UserInfo usr = UserController.GetUserById(PortalId, UserId);
                    if (usr == null)
                    {
                        throw new Exception("Userdata not found");
                    }

                    customerAddress.CustomerId        = this.MainControl.CustomerId;
                    customerAddress.PortalId          = PortalId;
                    customerAddress.Company           = (usr.Profile.GetPropertyValue("Company") ?? "");
                    customerAddress.Prefix            = (usr.Profile.GetPropertyValue("Prefix") ?? "");
                    customerAddress.Firstname         = (usr.FirstName ?? "");
                    customerAddress.Middlename        = (usr.Profile.GetPropertyValue("Middlename") ?? "");
                    customerAddress.Lastname          = (usr.LastName ?? "");
                    customerAddress.Suffix            = (usr.Profile.GetPropertyValue("Suffix") ?? "");
                    customerAddress.Unit              = (usr.Profile.GetPropertyValue("Unit") ?? "");
                    customerAddress.Street            = (usr.Profile.Street ?? "");
                    customerAddress.Region            = (usr.Profile.GetPropertyValue("Region") ?? "");
                    customerAddress.PostalCode        = (usr.Profile.PostalCode ?? "");
                    customerAddress.City              = (usr.Profile.City ?? "");
                    customerAddress.Suburb            = (usr.Profile.GetPropertyValue("Suburb") ?? "");
                    customerAddress.Country           = (usr.Profile.Country ?? "");
                    customerAddress.CountryCode       = GetCountryCode(customerAddress.Country);
                    customerAddress.Cell              = (usr.Profile.Cell ?? "");
                    customerAddress.Telephone         = (usr.Profile.Telephone ?? "");
                    customerAddress.Fax               = (usr.Profile.Fax ?? "");
                    customerAddress.Email             = (usr.Email ?? "");
                    customerAddress.IsDefault         = true;
                    customerAddress.CustomerAddressId = Controller.NewCustomerAddress(customerAddress);

                    // Add this address to all mandatory subscriberaddresstypes
                    foreach (var addressType in _addressTypes)
                    {
                        if (addressType.Mandatory)
                        {
                            CartAddressInfo cartAddress = new CartAddressInfo()
                            {
                                CartID                  = this.MainControl.CartId,
                                CustomerAddressId       = customerAddress.CustomerAddressId,
                                SubscriberAddressTypeId = addressType.SubscriberAddressTypeId
                            };
                            Controller.NewCartAddress(cartAddress);
                        }
                    }
                    // Edit this address
                    Response.Redirect(Globals.NavigateURL(TabId, "", "action=adredit", "adrid=" + customerAddress.CustomerAddressId.ToString()));
                }
            }

            // Now lets retrieve all adresses of the customer
            List <CustomerAddressInfo> customerAddresses = Controller.GetCustomerAddresses(this.MainControl.CustomerId);

            // Check if all adresses meet the requirements
            foreach (CustomerAddressInfo customerCheckAddress in customerAddresses)
            {
                if ((Settings["MandCompany"] != null && Convert.ToBoolean(Settings["MandCompany"]) && String.IsNullOrEmpty(customerCheckAddress.Company)) ||
                    (Settings["MandPrefix"] != null && Convert.ToBoolean(Settings["MandPrefix"]) && String.IsNullOrEmpty(customerCheckAddress.Prefix)) ||
                    (Settings["MandFirstName"] != null && Convert.ToBoolean(Settings["MandFirstName"]) && String.IsNullOrEmpty(customerCheckAddress.Firstname)) ||
                    (Settings["MandMiddleName"] != null && Convert.ToBoolean(Settings["MandMiddleName"]) && String.IsNullOrEmpty(customerCheckAddress.Middlename)) ||
                    (Settings["MandLastName"] != null && Convert.ToBoolean(Settings["MandLastName"]) && String.IsNullOrEmpty(customerCheckAddress.Lastname)) ||
                    (Settings["MandSuffix"] != null && Convert.ToBoolean(Settings["MandSuffix"]) && String.IsNullOrEmpty(customerCheckAddress.Suffix)) ||
                    (Settings["MandStreet"] != null && Convert.ToBoolean(Settings["MandStreet"]) && String.IsNullOrEmpty(customerCheckAddress.Street)) ||
                    (Settings["MandUnit"] != null && Convert.ToBoolean(Settings["MandUnit"]) && String.IsNullOrEmpty(customerCheckAddress.Unit)) ||
                    (Settings["MandRegion"] != null && Convert.ToBoolean(Settings["MandRegion"]) && String.IsNullOrEmpty(customerCheckAddress.Region)) ||
                    (Settings["MandPostalCode"] != null && Convert.ToBoolean(Settings["MandPostalCode"]) && String.IsNullOrEmpty(customerCheckAddress.PostalCode)) ||
                    (Settings["MandCity"] != null && Convert.ToBoolean(Settings["MandCity"]) && String.IsNullOrEmpty(customerCheckAddress.City)) ||
                    (Settings["MandSuburb"] != null && Convert.ToBoolean(Settings["MandSuburb"]) && String.IsNullOrEmpty(customerCheckAddress.Suburb)) ||
                    (Settings["MandCountry"] != null && Convert.ToBoolean(Settings["MandCountry"]) && String.IsNullOrEmpty(customerCheckAddress.Country)) ||
                    (Settings["MandTelephone"] != null && Convert.ToBoolean(Settings["MandTelephone"]) && String.IsNullOrEmpty(customerCheckAddress.Telephone)) ||
                    (Settings["MandCell"] != null && Convert.ToBoolean(Settings["MandCell"]) && String.IsNullOrEmpty(customerCheckAddress.Cell)) ||
                    (Settings["MandFax"] != null && Convert.ToBoolean(Settings["MandFax"]) && String.IsNullOrEmpty(customerCheckAddress.Fax)) ||
                    (Settings["MandEmail"] != null && Convert.ToBoolean(Settings["MandEmail"]) && String.IsNullOrEmpty(customerCheckAddress.Email)))
                {
                    Response.Redirect(Globals.NavigateURL(TabId, "", "action=adredit", "adrid=" + customerCheckAddress.CustomerAddressId.ToString()));
                }
            }

            customerAddresses.Add(new CustomerAddressInfo());

            //if (customerAddresses.Count > 0)
            {
                lstCustomerAddresses.Visible = true;

                lstCustomerAddresses.DataSource = customerAddresses;
                lstCustomerAddresses.DataBind();
            }
            //else
            //{
            //    lstCustomerAddresses.Visible = false;
            //}
        }
Exemplo n.º 2
0
 public abstract void NewCartAddress(CartAddressInfo cartAddress);