Ejemplo n.º 1
0
    /// <summary>
    /// Gets Where condition for filtering by the state. When using separated database, materializes the nested query on the other DB.
    /// </summary>
    private string GetStateCondition(TextSimpleFilter filter)
    {
        string originalQuery = filter.WhereCondition;

        if (String.IsNullOrEmpty(originalQuery))
        {
            return(string.Empty);
        }

        // Query with ContactInfo context has to be used in order to be able to determine DB context of the query (otherwise the materialization would not perform).
        var query = ContactInfoProvider.GetContacts()
                    .WhereIn("ContactStateID", StateInfoProvider
                             .GetStates()
                             .Where(originalQuery)
                             .Column(StateInfo.TYPEINFO.IDColumn)
                             );

        if (filter.FilterOperator == WhereBuilder.NOT_LIKE || filter.FilterOperator == WhereBuilder.NOT_EQUAL)
        {
            query = query.Or(new WhereCondition().WhereNull("ContactStateID"));
        }

        query.EnsureParameters();
        return(query.Parameters.Expand(query.WhereCondition));
    }
Ejemplo n.º 2
0
 /// <summary>
 /// Gets target shipping address
 /// </summary>
 /// <returns></returns>
 private static AddressDTO GetBillingAddress()
 {
     try
     {
         var distributorID      = Cart.GetIntegerValue("ShoppingCartDistributorID", default(int));
         var distributorAddress = AddressInfoProvider.GetAddresses().WhereEquals("AddressID", distributorID).FirstOrDefault();
         var country            = CountryInfoProvider.GetCountries().WhereEquals("CountryID", distributorAddress.GetStringValue("AddressCountryID", string.Empty)).FirstOrDefault();
         var state = StateInfoProvider.GetStates().WhereEquals("StateID", distributorAddress.GetStringValue("AddressStateID", string.Empty)).FirstOrDefault();
         return(new AddressDTO()
         {
             KenticoAddressID = distributorAddress.AddressID,
             AddressLine1 = distributorAddress.AddressLine1,
             AddressLine2 = distributorAddress.AddressLine2,
             City = distributorAddress.AddressCity,
             State = state.StateCode,
             Zip = distributorAddress.GetStringValue("AddressZip", string.Empty),
             KenticoCountryID = distributorAddress.AddressCountryID,
             Country = country.CountryName,
             isoCountryCode = country.CountryTwoLetterCode,
             KenticoStateID = distributorAddress.AddressStateID,
             AddressPersonalName = distributorAddress.AddressPersonalName,
             AddressCompanyName = distributorAddress.GetStringValue("CompanyName", string.Empty)
         });
     }
     catch (Exception ex)
     {
         EventLogProvider.LogInformation("ShoppingCartHelper", "GetBillingAddress", ex.Message);
         return(null);
     }
 }
    protected void EditForm_OnItemValidation(object sender, ref string errorMessage)
    {
        FormEngineUserControl ctrl = sender as FormEngineUserControl;

        // Checking countryselector if some country was selected
        if ((ctrl != null) && (ctrl.FieldInfo.Name == "AddressCountryID"))
        {
            int countryId = ValidationHelper.GetInteger(ctrl.Value, 0);

            if (countryId == 0)
            {
                errorMessage = GetString("basicform.erroremptyvalue");
            }

            // If country has states, check if some state was selected
            DataSet states = StateInfoProvider.GetStates("CountryID = " + countryId, "CountryID", 1, "CountryID");

            if (!DataHelper.DataSourceIsEmpty(states))
            {
                object[,] stateObj = ctrl.GetOtherValues();

                if ((stateObj == null) || (stateObj[0, 1] == null))
                {
                    errorMessage = GetString("com.address.nostate");
                }
            }
        }
    }
Ejemplo n.º 4
0
 /// <summary>
 /// Gets target shipping address
 /// </summary>
 /// <returns></returns>
 private static AddressDto GetTargetAddress()
 {
     try
     {
         var distributorID      = Cart.GetIntegerValue("ShoppingCartDistributorID", default(int));
         var distributorAddress = AddressInfoProvider.GetAddresses().WhereEquals("AddressID", distributorID).FirstOrDefault();
         var addressLines       = new[] {
             distributorAddress.GetStringValue("AddressLine1", string.Empty),
             distributorAddress.GetStringValue("AddressLine2", string.Empty)
         }.Where(a => !string.IsNullOrWhiteSpace(a)).ToList();
         var country = CountryInfoProvider.GetCountries().WhereEquals("CountryID", distributorAddress.GetStringValue("AddressCountryID", string.Empty))
                       .Column("CountryTwoLetterCode").FirstOrDefault();
         var state = StateInfoProvider.GetStates().WhereEquals("StateID", distributorAddress.GetStringValue("AddressStateID", string.Empty)).Column("StateCode").FirstOrDefault();
         return(new AddressDto()
         {
             City = distributorAddress.GetStringValue("AddressCity", string.Empty),
             Country = country?.CountryTwoLetterCode,
             Postal = distributorAddress.GetStringValue("AddressZip", string.Empty),
             State = state?.StateCode,
             StreetLines = addressLines
         });
     }
     catch (Exception ex)
     {
         EventLogProvider.LogInformation("ShoppingCartHelper", "GetTargetAddress", ex.Message);
         return(null);
     }
 }
Ejemplo n.º 5
0
 public IEnumerable <State> GetStates()
 {
     return(StateInfoProvider
            .GetStates()
            .Columns("StateDisplayName", "StateId", "StateName", "StateCode", "CountryId")
            .Select <StateInfo, State>(s => _mapper.Map <State>(s)));
 }
        public JsonResult CountryStates(int countryId)
        {
            // Gets the display names of the country's states
            var responseModel = StateInfoProvider.GetStates().WhereEquals("CountryID", countryId)
                                .Select(s => new
            {
                id   = s.StateID,
                name = HTMLHelper.HTMLEncode(s.StateDisplayName)
            });

            // Returns serialized display names of the states
            return(Json(responseModel));
        }
Ejemplo n.º 7
0
        private StateInfo FindState(string state)
        {
            if (string.IsNullOrWhiteSpace(state))
            {
                return(null);
            }

            var code = state.ToUpper();

            return(StateInfoProvider.GetStates()
                   .WhereStartsWith("StateDisplayName", state)
                   .Or()
                   .WhereEquals("StateCode", code)
                   .FirstOrDefault());
        }
Ejemplo n.º 8
0
    /// <summary>
    /// Validates data
    /// </summary>
    protected override void ValidateStepData(object sender, StepEventArgs e)
    {
        base.ValidateStepData(sender, e);

        if (!StopProcessing)
        {
            if (!addressForm.ValidateData())
            {
                e.CancelEvent = true;
                return;
            }
            // Just set current filed values into EditableObject, saving was canceled in OnBeforeSave
            addressForm.SaveData(null, false);

            AddressInfo address = addressForm.EditedObject as AddressInfo;
            if (address != null)
            {
                // Validate state
                if (StateInfoProvider.GetStates().WhereEquals("CountryID", address.AddressCountryID).TopN(1).HasResults())
                {
                    if (address.AddressStateID < 1)
                    {
                        e.CancelEvent = true;
                        addressForm.DisplayErrorLabel("AddressCountryID", ResHelper.GetString("com.address.nostate"));
                        return;
                    }
                }

                // Clear AddressName and AddressPersonalName to force their update (only if not present on the address form)
                if (!addressForm.FieldControls.Contains("AddressName"))
                {
                    address.AddressName = null;
                }
                if (!addressForm.FieldControls.Contains("AddressPersonalName"))
                {
                    address.AddressPersonalName = null;
                }

                // Assign validated new address to the current shopping cart
                // Address will be saved by customer detail web part (existing customer object is needed for the address)
                CurrentCartAddress = address;
            }
        }

        // Clear shipping address (StopProcessing is true when chkShowAddress is cleared)
        ClearShippingAddressIfNotUsed();
    }
 /// <summary>
 /// Returns all states in country with given ID.
 /// </summary>
 /// <param name="countryId">Country identifier</param>
 /// <returns>Collection of all states in county.</returns>
 public IEnumerable <StateInfo> GetCountryStates(int countryId)
 {
     return(StateInfoProvider.GetStates().WhereEquals("CountryID", countryId));
 }
Ejemplo n.º 10
0
 private object CreateFormInfo()
 {
     return(new
     {
         Title = ResHelper.GetString("Kadena.MailingList.EditorTitle"),
         DownloadErrorFile = new
         {
             Url = string.Empty,
             Text = string.Empty
         },
         DiscardChanges = ResHelper.GetString("Kadena.MailingList.DiscardChanges"),
         ConfirmChanges = new
         {
             Text = ResHelper.GetString("Kadena.MailingList.ConfirmChanges"),
             Redirect = ConfirmedPageUrl,
             Request = "/klist/update"
         },
         Message = new
         {
             Required = ResHelper.GetString("Kadena.MailingList.EnterValidValue")
         },
         Fields = new
         {
             FullName = new
             {
                 Required = true,
                 Header = ResHelper.GetString("Kadena.MailingList.Name", string.Empty)
             },
             FirstAddressLine = new
             {
                 Required = true,
                 Header = ResHelper.GetString("Kadena.MailingList.Address1", string.Empty)
             },
             SecondAddressLine = new
             {
                 Header = ResHelper.GetString("Kadena.MailingList.Address2", string.Empty)
             },
             City = new
             {
                 Required = true,
                 Header = ResHelper.GetString("Kadena.MailingList.City", string.Empty)
             },
             State = new
             {
                 Required = true,
                 Header = ResHelper.GetString("Kadena.MailingList.State", string.Empty),
                 Value = StateInfoProvider
                         .GetStates()
                         .Column("StateCode")
                         .Select(s => s["StateCode"].ToString())
             },
             PostalCode = new
             {
                 Required = true,
                 Header = ResHelper.GetString("Kadena.MailingList.Zip", string.Empty)
             },
             Error = new
             {
                 Header = ResHelper.GetString("Kadena.MailingList.Error", string.Empty)
             }
         }
     });
 }