| | | 1 | | using Elsa.KeyValues.Entities; |
| | | 2 | | |
| | | 3 | | namespace Elsa.KeyValues.Models; |
| | | 4 | | |
| | | 5 | | public class KeyValueFilter |
| | | 6 | | { |
| | | 7 | | /// <summary> |
| | | 8 | | /// Gets or sets whether the <see cref="Key"/> needs to match the beginning of the key found. |
| | | 9 | | /// </summary> |
| | 0 | 10 | | public bool StartsWith { get; set; } |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Gets or sets the key to filter for. |
| | | 14 | | /// </summary> |
| | 0 | 15 | | public string? Key { get; set; } |
| | | 16 | | |
| | | 17 | | /// <summary> |
| | | 18 | | /// Gets or sets the keys to filter for. |
| | | 19 | | /// </summary> |
| | 0 | 20 | | public ICollection<string>? Keys { get; set; } |
| | | 21 | | |
| | | 22 | | /// <summary> |
| | | 23 | | /// Applies the filter to the specified queryable. |
| | | 24 | | /// </summary> |
| | | 25 | | /// <param name="queryable">The queryable.</param> |
| | | 26 | | /// <returns>The filtered queryable.</returns> |
| | | 27 | | public IQueryable<SerializedKeyValuePair> Apply(IQueryable<SerializedKeyValuePair> queryable) |
| | | 28 | | { |
| | 0 | 29 | | var filter = this; |
| | 0 | 30 | | if (filter.Key != null) |
| | | 31 | | { |
| | 0 | 32 | | queryable = StartsWith |
| | 0 | 33 | | ? queryable.Where(x => x.Id.StartsWith(filter.Key)) |
| | 0 | 34 | | : queryable.Where(x => x.Id == filter.Key); |
| | | 35 | | } |
| | | 36 | | |
| | 0 | 37 | | if (filter.Keys != null) queryable = queryable.Where(x => filter.Keys.Contains(x.Id)); |
| | | 38 | | |
| | 0 | 39 | | return queryable; |
| | | 40 | | } |
| | | 41 | | } |