-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tools.cs
65 lines (64 loc) · 1.81 KB
/
Tools.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MongoDB.Driver;
namespace pwc_mongo_helper
{
public static class Tools<T>
{
public static FieldsDocument getDisplayFiles(Dictionary<string, int> fields)
{
FieldsDocument fd = new FieldsDocument();
fd.AddRange(fields);
return fd;
}
public static SortDefinition<T> getSortDefinition(Dictionary<string,int> sortfields)
{
SortDefinition<T> sd = null;
foreach (var item in sortfields)
{
if (sd == null)
{
if (item.Value == 1)
{
sd = Builders<T>.Sort.Ascending(item.Key);
}
else
{
sd = Builders<T>.Sort.Descending(item.Key);
}
}
else
{
if (item.Value == 1)
{
sd.Ascending(item.Key);
}
else
{
sd.Descending(item.Key);
}
}
}
return sd;
}
public static UpdateDefinition<T> getUpdateDefinition(Dictionary<string, object> updatedic)
{
UpdateDefinition<T> ud = null;
foreach (var item in updatedic)
{
if (ud == null)
{
ud = Builders<T>.Update.Set(item.Key, item.Value);
}
else
{
ud.Set(item.Key, item.Value);
}
}
return ud;
}
}
}