Commit bce5562aafbffff05786482112b99e3a8fe70824
1 parent
43dfbc98
add filter to bus stop
Showing
1 changed file
with
32 additions
and
30 deletions
Show diff stats
src/MapsDb/DataService/BusStopDs.cs
| ... | ... | @@ -31,6 +31,7 @@ namespace MapsDb.DataService |
| 31 | 31 | .Include(d=>d.Region) |
| 32 | 32 | .Include(d=>d.SurfaceType) |
| 33 | 33 | .Include(d=>d.StateCommon); |
| 34 | + | |
| 34 | 35 | data = Filtering(pagination.filter, data); |
| 35 | 36 | //.Where(d => d.Region.Name == filter); |
| 36 | 37 | |
| ... | ... | @@ -88,20 +89,21 @@ namespace MapsDb.DataService |
| 88 | 89 | continue; |
| 89 | 90 | } |
| 90 | 91 | string field = char.ToUpper(filter[1][0]) + filter[1].Substring(1); |
| 92 | + string param = filter[2].ToLower(); | |
| 91 | 93 | if(word.StartsWith("$")){ |
| 92 | - data = FilterByEndWith(field, filter[2], data); | |
| 94 | + data = FilterByEndWith(field, param, data); | |
| 93 | 95 | } |
| 94 | 96 | else if(word.StartsWith("^")){ |
| 95 | - data = FilterByStartWith(field, filter[2], data); | |
| 97 | + data = FilterByStartWith(field, param, data); | |
| 96 | 98 | } |
| 97 | 99 | else if(word.StartsWith("*")){ |
| 98 | - data = FilterByComtains(field, filter[2], data); | |
| 100 | + data = FilterByComtains(field, param, data); | |
| 99 | 101 | } |
| 100 | 102 | else if(word.StartsWith("!")){ |
| 101 | - data = FilterByNotEquals(field, filter[2], data); | |
| 103 | + data = FilterByNotEquals(field, param, data); | |
| 102 | 104 | } |
| 103 | 105 | else if(word.StartsWith("=")){ |
| 104 | - data = FilterByEquals(field, filter[2], data); | |
| 106 | + data = FilterByEquals(field, param, data); | |
| 105 | 107 | } |
| 106 | 108 | } |
| 107 | 109 | |
| ... | ... | @@ -111,72 +113,72 @@ namespace MapsDb.DataService |
| 111 | 113 | public IQueryable<BusStop> FilterByComtains(string field, string param, IQueryable<BusStop> data){ |
| 112 | 114 | switch(field){ |
| 113 | 115 | case "RoadId": |
| 114 | - return data.Where(i => i.Road.Name.Contains(param) ); | |
| 116 | + return data.Where(i => i.Road.Name != null && i.Road.Name.ToLower().Contains(param) ); | |
| 115 | 117 | case "RegionId": |
| 116 | - return data.Where(i => i.Region.Name.Contains(param) ); | |
| 118 | + return data.Where(i => i.Region.Name != null && i.Region.Name.ToLower().Contains(param) ); | |
| 117 | 119 | case "SurfaceTypeId": |
| 118 | - return data.Where(i => i.SurfaceType.Name.Contains(param) ); | |
| 120 | + return data.Where(i => i.SurfaceType.Name != null && i.SurfaceType.Name.ToLower().Contains(param) ); | |
| 119 | 121 | case "StateCommonId": |
| 120 | - return data.Where(i => i.StateCommon.Value.Contains(param) ); | |
| 122 | + return data.Where(i => i.StateCommon.Value != null && i.StateCommon.Value.ToLower().Contains(param) ); | |
| 121 | 123 | default: |
| 122 | - return data.Where(i => Convert.ToString(i.GetType().GetProperty(field).GetValue(i, null)).Contains(param) ); | |
| 124 | + return data.Where(i => Convert.ToString(i.GetType().GetProperty(field).GetValue(i, null)).ToLower().Contains(param) ); | |
| 123 | 125 | } |
| 124 | 126 | } |
| 125 | 127 | public IQueryable<BusStop> FilterByEquals(string field, string param, IQueryable<BusStop> data){ |
| 126 | 128 | switch(field){ |
| 127 | 129 | case "RoadId": |
| 128 | - return data.Where(i => i.Road.Name == param ); | |
| 130 | + return data.Where(i => i.Road.Name != null && i.Road.Name.ToLower() == param ); | |
| 129 | 131 | case "RegionId": |
| 130 | - return data.Where(i => i.Region.Name == param ); | |
| 132 | + return data.Where(i => i.Region.Name != null && i.Region.Name.ToLower() == param ); | |
| 131 | 133 | case "SurfaceTypeId": |
| 132 | - return data.Where(i => i.SurfaceType.Name == param ); | |
| 134 | + return data.Where(i => i.SurfaceType.Name != null && i.SurfaceType.Name.ToLower() == param ); | |
| 133 | 135 | case "StateCommonId": |
| 134 | - return data.Where(i => i.StateCommon.Value == param ); | |
| 136 | + return data.Where(i => i.StateCommon.Value != null && i.StateCommon.Value.ToLower() == param ); | |
| 135 | 137 | default: |
| 136 | - return data.Where(i => Convert.ToString(i.GetType().GetProperty(field).GetValue(i, null)) == param ); | |
| 138 | + return data.Where(i => Convert.ToString(i.GetType().GetProperty(field).GetValue(i, null)).ToLower() == param ); | |
| 137 | 139 | } |
| 138 | 140 | |
| 139 | 141 | } |
| 140 | 142 | public IQueryable<BusStop> FilterByNotEquals(string field, string param, IQueryable<BusStop> data){ |
| 141 | 143 | switch(field){ |
| 142 | 144 | case "RoadId": |
| 143 | - return data.Where(i => i.Road.Name != param ); | |
| 145 | + return data.Where(i => i.Road.Name != null && i.Road.Name.ToLower() != param ); | |
| 144 | 146 | case "RegionId": |
| 145 | - return data.Where(i => i.Region.Name != param ); | |
| 147 | + return data.Where(i => i.Region.Name != null && i.Region.Name.ToLower() != param ); | |
| 146 | 148 | case "SurfaceTypeId": |
| 147 | - return data.Where(i => i.SurfaceType.Name != param ); | |
| 149 | + return data.Where(i => i.SurfaceType.Name != null && i.SurfaceType.Name.ToLower() != param ); | |
| 148 | 150 | case "StateCommonId": |
| 149 | - return data.Where(i => i.StateCommon.Value != param ); | |
| 151 | + return data.Where(i => i.StateCommon.Value != null && i.StateCommon.Value.ToLower() != param ); | |
| 150 | 152 | default: |
| 151 | - return data.Where(i => Convert.ToString(i.GetType().GetProperty(field).GetValue(i, null)) != param ); | |
| 153 | + return data.Where(i => Convert.ToString(i.GetType().GetProperty(field).GetValue(i, null)).ToLower() != param ); | |
| 152 | 154 | } |
| 153 | 155 | } |
| 154 | 156 | public IQueryable<BusStop> FilterByStartWith(string field, string param, IQueryable<BusStop> data){ |
| 155 | 157 | switch(field){ |
| 156 | 158 | case "RoadId": |
| 157 | - return data.Where(i => i.Road.Name.StartsWith(param) ); | |
| 159 | + return data.Where(i => i.Road.Name != null && i.Road.Name.ToLower().StartsWith(param) ); | |
| 158 | 160 | case "RegionId": |
| 159 | - return data.Where(i => i.Region.Name.StartsWith(param) ); | |
| 161 | + return data.Where(i => i.Region.Name != null && i.Region.Name.ToLower().StartsWith(param) ); | |
| 160 | 162 | case "SurfaceTypeId": |
| 161 | - return data.Where(i => i.SurfaceType.Name.StartsWith(param) ); | |
| 163 | + return data.Where(i => i.SurfaceType.Name != null && i.SurfaceType.Name.ToLower().StartsWith(param) ); | |
| 162 | 164 | case "StateCommonId": |
| 163 | - return data.Where(i => i.StateCommon.Value.StartsWith(param) ); | |
| 165 | + return data.Where(i => i.StateCommon.Value != null && i.StateCommon.Value.ToLower().StartsWith(param) ); | |
| 164 | 166 | default: |
| 165 | - return data.Where(i => Convert.ToString(i.GetType().GetProperty(field).GetValue(i, null)).StartsWith(param) ); | |
| 167 | + return data.Where(i => Convert.ToString(i.GetType().GetProperty(field).GetValue(i, null)).ToLower().StartsWith(param) ); | |
| 166 | 168 | } |
| 167 | 169 | } |
| 168 | 170 | public IQueryable<BusStop> FilterByEndWith(string field, string param, IQueryable<BusStop> data){ |
| 169 | 171 | switch(field){ |
| 170 | 172 | case "RoadId": |
| 171 | - return data.Where(i => i.Road.Name.EndsWith(param) ); | |
| 173 | + return data.Where(i => i.Road.Name != null && i.Road.Name.ToLower().EndsWith(param) ); | |
| 172 | 174 | case "RegionId": |
| 173 | - return data.Where(i => i.Region.Name.EndsWith(param) ); | |
| 175 | + return data.Where(i => i.Region.Name != null && i.Region.Name.ToLower().EndsWith(param) ); | |
| 174 | 176 | case "SurfaceTypeId": |
| 175 | - return data.Where(i => i.SurfaceType.Name.EndsWith(param) ); | |
| 177 | + return data.Where(i => i.SurfaceType.Name != null && i.SurfaceType.Name.ToLower().EndsWith(param) ); | |
| 176 | 178 | case "StateCommonId": |
| 177 | - return data.Where(i => i.StateCommon.Value.EndsWith(param) ); | |
| 179 | + return data.Where(i => i.StateCommon.Value != null && i.StateCommon.Value.ToLower().EndsWith(param) ); | |
| 178 | 180 | default: |
| 179 | - return data.Where(i => Convert.ToString(i.GetType().GetProperty(field).GetValue(i, null)).EndsWith(param) ); | |
| 181 | + return data.Where(i => Convert.ToString(i.GetType().GetProperty(field).GetValue(i, null)).ToLower().EndsWith(param) ); | |
| 180 | 182 | } |
| 181 | 183 | } |
| 182 | 184 | public async Task<int> DeleteAsync(int Id) | ... | ... |