-
Notifications
You must be signed in to change notification settings - Fork 34
/
Int64Binder.cs
64 lines (51 loc) · 2.06 KB
/
Int64Binder.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.ModelBinding;
namespace Tzkt.Api
{
public class Int64Binder : IModelBinder
{
public Task BindModelAsync(ModelBindingContext bindingContext)
{
var model = bindingContext.ModelName;
var hasValue = false;
if (!bindingContext.TryGetInt64($"{model}", ref hasValue, out var value))
return Task.CompletedTask;
if (!bindingContext.TryGetInt64($"{model}.eq", ref hasValue, out var eq))
return Task.CompletedTask;
if (!bindingContext.TryGetInt64($"{model}.ne", ref hasValue, out var ne))
return Task.CompletedTask;
if (!bindingContext.TryGetInt64($"{model}.gt", ref hasValue, out var gt))
return Task.CompletedTask;
if (!bindingContext.TryGetInt64($"{model}.ge", ref hasValue, out var ge))
return Task.CompletedTask;
if (!bindingContext.TryGetInt64($"{model}.lt", ref hasValue, out var lt))
return Task.CompletedTask;
if (!bindingContext.TryGetInt64($"{model}.le", ref hasValue, out var le))
return Task.CompletedTask;
if (!bindingContext.TryGetInt64List($"{model}.in", ref hasValue, out var @in))
return Task.CompletedTask;
if (!bindingContext.TryGetInt64List($"{model}.ni", ref hasValue, out var ni))
return Task.CompletedTask;
if (!hasValue)
{
bindingContext.Result = ModelBindingResult.Success(null);
return Task.CompletedTask;
}
bindingContext.Result = ModelBindingResult.Success(new Int64Parameter
{
Eq = value ?? eq,
Ne = ne,
Gt = gt,
Ge = ge,
Lt = lt,
Le = le,
In = @in,
Ni = ni
});
return Task.CompletedTask;
}
}
}