private void InitializeFilter <T>(PriceFilterCategory category, string type, string id, string label, T value, double delta = 5, bool enabled = false, double?min = null, bool alwaysIncluded = false) { if (value is bool boolValue) { if (!boolValue && !alwaysIncluded) { return; } } else if (value is int intValue) { if (intValue == 0 && !alwaysIncluded) { return; } if (min == null) { min = (int)Math.Min(intValue - delta, intValue * 0.9); } } else if (value is double doubleValue) { if (doubleValue == 0 && !alwaysIncluded) { return; } if (min == null) { min = (int)Math.Min(doubleValue - delta, doubleValue * 0.9); } } else if (value is IGrouping <string, Magnitude> groupValue) { min = groupValue.Select(x => x.Min).OrderBy(x => x).FirstOrDefault(); if (min.HasValue) { min = (int)Math.Min(min.Value - delta, min.Value * 0.9); } } var priceFilter = new PriceFilter() { Enabled = enabled, Type = type, Id = id, Text = label, Min = min, Max = null, HasRange = min.HasValue }; priceFilter.PropertyChanged += async(object sender, PropertyChangedEventArgs e) => { await UpdateQuery(); }; category.Filters.Add(priceFilter); }
private void InitializeFilter <T>(PriceFilterCategory category, string type, string id, string label, T value, double delta = 5, bool enabled = false, double?min = null, double?max = null, bool alwaysIncluded = false, bool normalizeValues = true, bool applyNegative = false) { ModifierOption option = null; 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}"; } } else 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; } } else if (value is ModifierOption modifierOption) { option = modifierOption; min = null; max = null; } var priceFilter = new PriceFilter() { Enabled = enabled, Type = type, Id = id, Text = label, Min = min, Max = max, HasRange = min.HasValue || max.HasValue, ApplyNegative = applyNegative, Option = option, }; priceFilter.PropertyChanged += (object sender, PropertyChangedEventArgs e) => { UpdateDebounce(); }; category.Filters.Add(priceFilter); }
private void InitializeFilter <T>(PriceFilterCategory category, string type, string id, string label, T value, double delta = 5, bool enabled = false, double?min = 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 = NormalizeValue(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 = NormalizeValue(doubleValue, delta); } if (LabelValues.IsMatch(label)) { label = LabelValues.Replace(label, doubleValue.ToString("0.00")); } else { label += $": {doubleValue:0.00}"; } } else if (value is List <double> groupValue) { min = groupValue.OrderBy(x => x).FirstOrDefault(); if (normalizeValues) { min = NormalizeValue(min, delta); } } var priceFilter = new PriceFilter() { Enabled = enabled, Type = type, Id = id, Text = label, Min = min, Max = null, HasRange = min.HasValue }; priceFilter.PropertyChanged += async(object sender, PropertyChangedEventArgs e) => { await UpdateQuery(); }; category.Filters.Add(priceFilter); }