-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
105 lines (90 loc) · 3.09 KB
/
Program.cs
File metadata and controls
105 lines (90 loc) · 3.09 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using QueryObjectPattern.DAL;
using System;
using QueryObjectPattern.QueryObjects;
namespace QueryObjectPattern
{
class Program
{
static void Main(string[] args)
{
TestQueryInStatus();
TestQueryDto();
TestQuery();
//AddBook();
Console.ReadKey();
}
public static void AddBook()
{
var book = new Book<Spices>
{
Spice = new Spices()
{
SpiceMixName = "Zuppa di ceci",
Supplier = "Boh"
}
};
var context = new StudioDBContext();
context.Books.Add(book);
context.SaveChanges();
}
public static void TestQuery()
{
// DbContext (in verità arriva dal container DI)
var dbContext = new StudioDBContext();
// Creo un oggetto QueryObjectQueryable
CustomersInDateQueryObject queryObj =
new CustomersInDateQueryObject(dbContext)
{
StartDate = DateTime.Parse("2017-12-31"),
EndDate = DateTime.Parse("2018-01-01")
};
var result = queryObj.Execute();
foreach (var customer in result)
{
Console.WriteLine($"{customer.Nome} {customer.Cognome}");
}
Console.ReadKey();
}
public static void TestQueryDto()
{
// DbContext (in verità arriva dal container DI)
var dbContext = new StudioDBContext();
// Creo una query
CustomersInDateDtoQueryObject queryObj =
new CustomersInDateDtoQueryObject (dbContext)
{
Status = 2,
StartDate = DateTime.Parse("2017-10-09"),
EndDate = null
};
var result = queryObj.Execute();
foreach (var customer in result)
{
Console.WriteLine($"FullName: {customer.FullName}");
Console.WriteLine($"Matricola: {customer.Matricola}");
Console.WriteLine($"Password: {customer.Password}");
Console.WriteLine("-------------------------------------");
}
Console.ReadKey();
}
public static void TestQueryInStatus()
{
// DbContext (in verità arriva dal container DI)
var dbContext = new StudioDBContext();
// Creo una query
CustomersInStatusQueryObject queryObj =
new CustomersInStatusQueryObject(dbContext)
{
Status = new[] {3,4}
};
var result = queryObj.Execute();
foreach (var customer in result)
{
Console.WriteLine($"Nome: {customer.Nome}");
Console.WriteLine($"Status: {customer.Status}");
Console.WriteLine("-------------------------------------");
}
Console.ReadKey();
}
}
}