Esempio n. 1
0
        private void InitializeModifierFilter <T>(PriceFilterCategory category,
                                                  string id,
                                                  string label,
                                                  T value,
                                                  double delta         = 5,
                                                  bool enabled         = false,
                                                  double?min           = null,
                                                  double?max           = null,
                                                  bool normalizeValues = true)
        {
            ModifierOption option = null;

            if (value is List <double> groupValue)
            {
                var itemValue = groupValue.OrderBy(x => x).FirstOrDefault();

                if (itemValue >= 0)
                {
                    min = itemValue;
                    if (normalizeValues)
                    {
                        min = NormalizeMinValue(min, delta);
                    }
                }
                else
                {
                    max = itemValue;
                    if (normalizeValues)
                    {
                        max = NormalizeMaxValue(max, delta);
                    }
                }

                if (!groupValue.Any())
                {
                    min = null;
                    max = null;
                }
            }

            var priceFilter = new PriceFilter()
            {
                Enabled      = enabled,
                PropertyType = null,
                Id           = id,
                Text         = label,
                Min          = min,
                Max          = max,
                HasRange     = min.HasValue || max.HasValue,
                Option       = option,
            };

            priceFilter.PropertyChanged += (object sender, PropertyChangedEventArgs e) => { UpdateDebounce(); };

            category.Filters.Add(priceFilter);
        }
Esempio n. 2
0
        private void InitializePropertyFilter <T>(PriceFilterCategory category,
                                                  PropertyFilterType type,
                                                  string label,
                                                  T value,
                                                  double delta         = 5,
                                                  bool enabled         = false,
                                                  double?min           = null,
                                                  double?max           = null,
                                                  bool alwaysIncluded  = false,
                                                  bool normalizeValues = true)
        {
            if (value is bool boolValue)
            {
                if (!boolValue && !alwaysIncluded)
                {
                    return;
                }
            }
            else if (value is int intValue)
            {
                if (intValue == 0 && !alwaysIncluded)
                {
                    return;
                }
                if (min == null && normalizeValues)
                {
                    min = NormalizeMinValue(intValue, delta);
                }
                if (LabelValues.IsMatch(label))
                {
                    label = LabelValues.Replace(label, intValue.ToString());
                }
                else
                {
                    label += $": {value}";
                }
            }
            else if (value is double doubleValue)
            {
                if (doubleValue == 0 && !alwaysIncluded)
                {
                    return;
                }
                if (min == null && normalizeValues)
                {
                    min = NormalizeMinValue(doubleValue, delta);
                }
                if (LabelValues.IsMatch(label))
                {
                    label = LabelValues.Replace(label, doubleValue.ToString("0.00"));
                }
                else
                {
                    label += $": {doubleValue:0.00}";
                }
            }

            var priceFilter = new PriceFilter()
            {
                Enabled      = enabled,
                PropertyType = type,
                Text         = label,
                Min          = min,
                Max          = max,
                HasRange     = min.HasValue || max.HasValue,
                Option       = null,
            };

            priceFilter.PropertyChanged += (object sender, PropertyChangedEventArgs e) => { UpdateDebounce(); };

            category.Filters.Add(priceFilter);
        }