-
Notifications
You must be signed in to change notification settings - Fork 133
/
Copy pathSieveModel.cs
73 lines (66 loc) · 2.09 KB
/
SieveModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
namespace Sieve.Models
{
public class SieveModel: ISieveModel<IFilterTerm, ISortTerm>
{
public string Filters { get; set; }
public string Sorts { get; set; }
[Range(1, Double.MaxValue)]
public int? Page { get; set; }
[Range(1, Double.MaxValue)]
public int? PageSize { get; set; }
public List<IFilterTerm> FiltersParsed
{
get
{
if (Filters != null)
{
var value = new List<IFilterTerm>();
foreach (var filter in Filters.Split(','))
{
if (filter.StartsWith("("))
{
var filterOpAndVal = filter.Substring(filter.LastIndexOf(")") + 1);
var subfilters = filter.Replace(filterOpAndVal, "").Replace("(", "").Replace(")","");
foreach (var subfilter in subfilters.Split('|'))
{
value.Add(new FilterTerm(subfilter + filterOpAndVal));
}
}
else
{
value.Add(new FilterTerm(filter));
}
}
return value;
}
else
{
return null;
}
}
}
public List<ISortTerm> SortsParsed
{
get
{
if (Sorts != null)
{
var value = new List<ISortTerm>();
foreach (var sort in Sorts.Split(','))
{
value.Add(new SortTerm(sort));
}
return value;
}
else
{
return null;
}
}
}
}
}