|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq.Expressions; |
| 4 | +using System.Text; |
| 5 | + |
| 6 | +namespace WorkflowCore.Models.Search |
| 7 | +{ |
| 8 | + public abstract class SearchFilter |
| 9 | + { |
| 10 | + public bool IsData { get; set; } |
| 11 | + public Type DataType { get; set; } |
| 12 | + public Expression Property { get; set; } |
| 13 | + |
| 14 | + static Func<T, V> Lambda<T, V>(Func<T, V> del) |
| 15 | + { |
| 16 | + return del; |
| 17 | + } |
| 18 | + } |
| 19 | + |
| 20 | + public class ScalarFilter : SearchFilter |
| 21 | + { |
| 22 | + public object Value { get; set; } |
| 23 | + |
| 24 | + public static SearchFilter Equals(Expression<Func<WorkflowSearchResult, object>> property, object value) => new ScalarFilter() |
| 25 | + { |
| 26 | + Property = property, |
| 27 | + Value = value |
| 28 | + }; |
| 29 | + |
| 30 | + public static SearchFilter Equals<T>(Expression<Func<T, object>> property, object value) => new ScalarFilter() |
| 31 | + { |
| 32 | + IsData = true, |
| 33 | + DataType = typeof(T), |
| 34 | + Property = property, |
| 35 | + Value = value |
| 36 | + }; |
| 37 | + } |
| 38 | + |
| 39 | + public class DateRangeFilter : SearchFilter |
| 40 | + { |
| 41 | + public DateTime? BeforeValue { get; set; } |
| 42 | + public DateTime? AfterValue { get; set; } |
| 43 | + |
| 44 | + public static DateRangeFilter Before(Expression<Func<WorkflowSearchResult, object>> property, DateTime value) => new DateRangeFilter() |
| 45 | + { |
| 46 | + Property = property, |
| 47 | + BeforeValue = value |
| 48 | + }; |
| 49 | + |
| 50 | + public static DateRangeFilter After(Expression<Func<WorkflowSearchResult, object>> property, DateTime value) => new DateRangeFilter() |
| 51 | + { |
| 52 | + Property = property, |
| 53 | + AfterValue = value |
| 54 | + }; |
| 55 | + |
| 56 | + public static DateRangeFilter Between(Expression<Func<WorkflowSearchResult, object>> property, DateTime start, DateTime end) => new DateRangeFilter() |
| 57 | + { |
| 58 | + Property = property, |
| 59 | + BeforeValue = end, |
| 60 | + AfterValue = start |
| 61 | + }; |
| 62 | + |
| 63 | + public static DateRangeFilter Before<T>(Expression<Func<T, object>> property, DateTime value) => new DateRangeFilter() |
| 64 | + { |
| 65 | + IsData = true, |
| 66 | + DataType = typeof(T), |
| 67 | + Property = property, |
| 68 | + BeforeValue = value |
| 69 | + }; |
| 70 | + |
| 71 | + public static DateRangeFilter After<T>(Expression<Func<T, object>> property, DateTime value) => new DateRangeFilter() |
| 72 | + { |
| 73 | + IsData = true, |
| 74 | + DataType = typeof(T), |
| 75 | + Property = property, |
| 76 | + AfterValue = value |
| 77 | + }; |
| 78 | + |
| 79 | + public static DateRangeFilter Between<T>(Expression<Func<T, object>> property, DateTime start, DateTime end) => new DateRangeFilter() |
| 80 | + { |
| 81 | + IsData = true, |
| 82 | + DataType = typeof(T), |
| 83 | + Property = property, |
| 84 | + BeforeValue = end, |
| 85 | + AfterValue = start |
| 86 | + }; |
| 87 | + } |
| 88 | + |
| 89 | + public class NumericRangeFilter : SearchFilter |
| 90 | + { |
| 91 | + public double? LessValue { get; set; } |
| 92 | + public double? GreaterValue { get; set; } |
| 93 | + |
| 94 | + public static NumericRangeFilter LessThan(Expression<Func<WorkflowSearchResult, object>> property, double value) => new NumericRangeFilter() |
| 95 | + { |
| 96 | + Property = property, |
| 97 | + LessValue = value |
| 98 | + }; |
| 99 | + |
| 100 | + public static NumericRangeFilter GreaterThan(Expression<Func<WorkflowSearchResult, object>> property, double value) => new NumericRangeFilter() |
| 101 | + { |
| 102 | + Property = property, |
| 103 | + GreaterValue = value |
| 104 | + }; |
| 105 | + |
| 106 | + public static NumericRangeFilter Between(Expression<Func<WorkflowSearchResult, object>> property, double start, double end) => new NumericRangeFilter() |
| 107 | + { |
| 108 | + Property = property, |
| 109 | + LessValue = end, |
| 110 | + GreaterValue = start |
| 111 | + }; |
| 112 | + |
| 113 | + public static NumericRangeFilter LessThan<T>(Expression<Func<T, object>> property, double value) => new NumericRangeFilter() |
| 114 | + { |
| 115 | + IsData = true, |
| 116 | + DataType = typeof(T), |
| 117 | + Property = property, |
| 118 | + LessValue = value |
| 119 | + }; |
| 120 | + |
| 121 | + public static NumericRangeFilter GreaterThan<T>(Expression<Func<T, object>> property, double value) => new NumericRangeFilter() |
| 122 | + { |
| 123 | + IsData = true, |
| 124 | + DataType = typeof(T), |
| 125 | + Property = property, |
| 126 | + GreaterValue = value |
| 127 | + }; |
| 128 | + |
| 129 | + public static NumericRangeFilter Between<T>(Expression<Func<T, object>> property, double start, double end) => new NumericRangeFilter() |
| 130 | + { |
| 131 | + IsData = true, |
| 132 | + DataType = typeof(T), |
| 133 | + Property = property, |
| 134 | + LessValue = end, |
| 135 | + GreaterValue = start |
| 136 | + }; |
| 137 | + } |
| 138 | + |
| 139 | + public class StatusFilter : ScalarFilter |
| 140 | + { |
| 141 | + protected StatusFilter() |
| 142 | + { |
| 143 | + Expression<Func<WorkflowSearchResult, object>> lambda = (WorkflowSearchResult x) => x.Status; |
| 144 | + Property = lambda; |
| 145 | + } |
| 146 | + |
| 147 | + public static StatusFilter Equals(WorkflowStatus value) => new StatusFilter() |
| 148 | + { |
| 149 | + Value = value.ToString() |
| 150 | + }; |
| 151 | + } |
| 152 | + |
| 153 | +} |
0 commit comments