示例#1
0
        private IList <SearchProductAttributeValue> ParceCustomerAttributesToSearch(SearchModel model)
        {
            var list = new List <SearchProductAttributeValue>();

            foreach (var attribute in model.CustomerAttributes.Attributes.Where(x => !String.IsNullOrEmpty(x.AttributeValue) ||
                                                                                !String.IsNullOrEmpty(x.AttributeValueMax) ||
                                                                                x.SelectedAttributeId != 0))
            {
                var attributeForSearch = new SearchProductAttributeValue();
                attributeForSearch.CustomerControlType = (CustomerInformationProductSearchControlType)attribute.AttributeControlTypeId;

                if (!String.IsNullOrEmpty(attribute.AttributeValue))
                {
                    double res = 0;
                    double.TryParse(attribute.AttributeValue, out res);
                    if (attribute.CurrencyId != 0)
                    {
                        var currency = _currencyService.GetCurrencyById(attribute.CurrencyId);
                        res = res / (double)currency.Rate;
                    }
                    attributeForSearch.ExactValue = res;
                    attributeForSearch.MinValue   = res;
                }
                attributeForSearch.IdValue = attribute.SelectedAttributeId;
                if (!String.IsNullOrEmpty(attribute.AttributeValueMax))
                {
                    double res = 0;
                    double.TryParse(attribute.AttributeValueMax, out res);
                    if (attribute.CurrencyId != 0)
                    {
                        var currency = _currencyService.GetCurrencyById(attribute.CurrencyId);
                        res = res / (double)currency.Rate;
                    }
                    attributeForSearch.MaxValue = res;
                }
                attributeForSearch.Textvalue = attribute.AttributeValue;
                attributeForSearch.CategoryProductAttributeId = attribute.Id;
                list.Add(attributeForSearch);
            }

            return(list);
        }
示例#2
0
        private IList <SearchProductAttributeValue> PrepareAttributeModelForSearch(SearchProductAttributeModel model)
        {
            var attributesForSearch = new List <SearchProductAttributeValue>();

            switch ((SearchAttributeControlType)model.AttributeControlTypeId)
            {
            case SearchAttributeControlType.CheckBox:
            case SearchAttributeControlType.CheckBoxGroup:
            {
                foreach (var value in model.Values)
                {
                    if (value.Selected)
                    {
                        var attributeForSearch = new SearchProductAttributeValue();
                        attributeForSearch.CategoryProductAttributeId = model.Id;
                        attributeForSearch.IdValue     = value.Id;
                        attributeForSearch.ControlType = (SearchAttributeControlType)model.AttributeControlTypeId;
                        attributesForSearch.Add(attributeForSearch);
                    }
                }
                break;
            }

            case SearchAttributeControlType.DropDown:
            {
                if (model.SelectedAttributeId != 0)
                {
                    var attributeForSearch = new SearchProductAttributeValue();
                    attributeForSearch.CategoryProductAttributeId = model.Id;
                    attributeForSearch.IdValue     = model.SelectedAttributeId;
                    attributeForSearch.ControlType = (SearchAttributeControlType)model.AttributeControlTypeId;
                    attributesForSearch.Add(attributeForSearch);
                }
                break;
            }

            case SearchAttributeControlType.TextBoxText:
            {
                if (!String.IsNullOrEmpty(model.AttributeValue))
                {
                    var attributeForSearch = new SearchProductAttributeValue();
                    attributeForSearch.CategoryProductAttributeId = model.Id;
                    attributeForSearch.Textvalue   = model.AttributeValue;
                    attributeForSearch.ControlType = (SearchAttributeControlType)model.AttributeControlTypeId;
                    attributesForSearch.Add(attributeForSearch);
                }
                break;
            }

            case SearchAttributeControlType.TextBoxReal:
            {
                if (!String.IsNullOrEmpty(model.AttributeValue))
                {
                    var attributeForSearch = new SearchProductAttributeValue();
                    attributeForSearch.CategoryProductAttributeId = model.Id;
                    double res = 0;
                    double.TryParse(model.AttributeValue, out res);
                    attributeForSearch.ExactValue  = res;
                    attributeForSearch.ControlType = (SearchAttributeControlType)model.AttributeControlTypeId;
                    attributesForSearch.Add(attributeForSearch);
                }
                break;
            }

            case SearchAttributeControlType.ToddlerMax:
            {
                if (model.MinValue != 0 && model.SelectedIntValue != 0)
                {
                    var attributeForSearch = new SearchProductAttributeValue();
                    attributeForSearch.CategoryProductAttributeId = model.Id;
                    attributeForSearch.ControlType = (SearchAttributeControlType)model.AttributeControlTypeId;
                    attributeForSearch.MinValue    = model.MinValue;
                    attributeForSearch.MaxValue    = model.SelectedIntValue;
                    attributesForSearch.Add(attributeForSearch);
                }

                break;
            }

            case SearchAttributeControlType.ToddlerMin:
            {
                if (model.MaxValue != 0 && model.SelectedIntValue != 0)
                {
                    var attributeForSearch = new SearchProductAttributeValue();
                    attributeForSearch.CategoryProductAttributeId = model.Id;
                    attributeForSearch.ControlType = (SearchAttributeControlType)model.AttributeControlTypeId;
                    attributeForSearch.MinValue    = model.SelectedIntValue;
                    attributeForSearch.MaxValue    = model.MaxValue;
                    attributesForSearch.Add(attributeForSearch);
                }

                break;
            }

            case SearchAttributeControlType.ToddlerIntBetween:
            {
                if (model.SelectedMaxIntValue != 0 && model.SelectedIntValue != 0)
                {
                    var attributeForSearch = new SearchProductAttributeValue();
                    attributeForSearch.CategoryProductAttributeId = model.Id;
                    attributeForSearch.ControlType = (SearchAttributeControlType)model.AttributeControlTypeId;
                    attributeForSearch.MinValue    = model.SelectedIntValue;
                    attributeForSearch.MaxValue    = model.SelectedMaxIntValue;
                    attributesForSearch.Add(attributeForSearch);
                }

                break;
            }

            case SearchAttributeControlType.Money:
            {
                if (!String.IsNullOrEmpty(model.AttributeValue) || !String.IsNullOrEmpty(model.AttributeValueMax))
                {
                    var currency           = _currencyService.GetCurrencyById(model.CurrencyId);
                    var attributeForSearch = new SearchProductAttributeValue();
                    attributeForSearch.CategoryProductAttributeId = model.Id;
                    attributeForSearch.ControlType = (SearchAttributeControlType)model.AttributeControlTypeId;
                    if (!String.IsNullOrEmpty(model.AttributeValue))
                    {
                        double res = 0;
                        double.TryParse(model.AttributeValue, out res);
                        attributeForSearch.MinValue = res / ((double)currency.Rate);
                        attributeForSearch.MaxValue = res / ((double)currency.Rate);
                    }
                    attributesForSearch.Add(attributeForSearch);
                }
                break;
            }
            }

            return(attributesForSearch);
        }