Skip to content

Commit 1d4d8cd

Browse files
committed
Chapter 04 done.
1 parent 76ce06a commit 1d4d8cd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+23957
-90
lines changed

All_Chapters.sln

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31912.275
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyBGList", "Chapter_02\MyBGList\MyBGList.csproj", "{E0467401-AF14-4810-8E7E-22BD4E8D5FFE}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Chapter 02", "Chapter 02", "{AB5F2A98-5AA1-4A25-AD70-0BCBB3F5AA58}"
9+
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Chapter 01", "Chapter 01", "{6D526D52-DA7C-415F-A3D2-0C612923BF6E}"
11+
EndProject
12+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Exercises", "Exercises", "{6773746C-CAC2-4114-81DE-B3418FB485C5}"
13+
ProjectSection(SolutionItems) = preProject
14+
Chapter_02\Exercises\appsettings.Development.json = Chapter_02\Exercises\appsettings.Development.json
15+
Chapter_02\Exercises\appsettings.json = Chapter_02\Exercises\appsettings.json
16+
Chapter_02\Exercises\appsettings.Staging.json = Chapter_02\Exercises\appsettings.Staging.json
17+
Chapter_02\Exercises\BoardGame.cs = Chapter_02\Exercises\BoardGame.cs
18+
Chapter_02\Exercises\BoardGamesController.cs = Chapter_02\Exercises\BoardGamesController.cs
19+
Chapter_02\Exercises\launchSettings.json = Chapter_02\Exercises\launchSettings.json
20+
Chapter_02\Exercises\Program.cs = Chapter_02\Exercises\Program.cs
21+
EndProjectSection
22+
EndProject
23+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Chapter_03", "Chapter_03", "{39EC7DDB-AA88-480F-B324-877E2C473D9B}"
24+
EndProject
25+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyBGList", "Chapter_03\MyBGList\MyBGList.csproj", "{FBD73632-9D61-46DE-A057-8F01C77E2E49}"
26+
EndProject
27+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyBGList_ApiVersion", "Chapter_03\MyBGList_ApiVersion\MyBGList_ApiVersion.csproj", "{85DD4D4C-B8E0-49C2-9AA2-E198BBB62329}"
28+
EndProject
29+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Exercises", "Exercises", "{545CADC5-5C94-4792-81A3-0FD9EE3DC350}"
30+
ProjectSection(SolutionItems) = preProject
31+
Chapter_03\Exercises\Program.cs = Chapter_03\Exercises\Program.cs
32+
EndProjectSection
33+
EndProject
34+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Controllers", "Controllers", "{C692CEE7-E168-43C7-A5E9-7B05B29CE0AF}"
35+
EndProject
36+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "v1", "v1", "{27FADEF1-383E-4FCE-8FBD-7B1BBACAB926}"
37+
ProjectSection(SolutionItems) = preProject
38+
Chapter_03\Exercises\Controllers\v1\BoardGamesController.cs = Chapter_03\Exercises\Controllers\v1\BoardGamesController.cs
39+
EndProjectSection
40+
EndProject
41+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "v2", "v2", "{45E2DF92-2C53-476C-A9DB-2CA409068AEA}"
42+
ProjectSection(SolutionItems) = preProject
43+
Chapter_03\Exercises\Controllers\v2\BoardGamesController.cs = Chapter_03\Exercises\Controllers\v2\BoardGamesController.cs
44+
Chapter_03\Exercises\Controllers\v2\CodeOnDemandController.cs = Chapter_03\Exercises\Controllers\v2\CodeOnDemandController.cs
45+
EndProjectSection
46+
EndProject
47+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "v3", "v3", "{86155047-E0DD-485C-BCC8-048600286231}"
48+
ProjectSection(SolutionItems) = preProject
49+
Chapter_03\Exercises\Controllers\v3\CodeOnDemandController.cs = Chapter_03\Exercises\Controllers\v3\CodeOnDemandController.cs
50+
EndProjectSection
51+
EndProject
52+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Chapter_04", "Chapter_04", "{888CC4D4-8F56-4EBE-B0C3-829BCE934E00}"
53+
EndProject
54+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyBGList", "Chapter_04\MyBGList\MyBGList.csproj", "{8FDCC6E3-FB56-45EF-B18D-B34C882CD1FF}"
55+
EndProject
56+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Exercises", "Exercises", "{79FC43C4-0966-4DAC-957E-BDB1A36E696E}"
57+
EndProject
58+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Migrations", "Migrations", "{73294E53-5E4A-4E1E-9D57-3C6FE607EBCE}"
59+
ProjectSection(SolutionItems) = preProject
60+
Chapter_04\Exercises\Migrations\20220127000740_Chapter04_Exercises.cs = Chapter_04\Exercises\Migrations\20220127000740_Chapter04_Exercises.cs
61+
Chapter_04\Exercises\Migrations\20220127000740_Chapter04_Exercises.Designer.cs = Chapter_04\Exercises\Migrations\20220127000740_Chapter04_Exercises.Designer.cs
62+
Chapter_04\Exercises\Migrations\ApplicationDbContextModelSnapshot.cs = Chapter_04\Exercises\Migrations\ApplicationDbContextModelSnapshot.cs
63+
EndProjectSection
64+
EndProject
65+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Model", "Model", "{E566019F-3A19-4FF0-90C5-D5BB98B49A9E}"
66+
ProjectSection(SolutionItems) = preProject
67+
Chapter_04\Exercises\Model\ApplicationDbContext.cs = Chapter_04\Exercises\Model\ApplicationDbContext.cs
68+
Chapter_04\Exercises\Model\BoardGame.cs = Chapter_04\Exercises\Model\BoardGame.cs
69+
Chapter_04\Exercises\Model\BoardGames_Categories.cs = Chapter_04\Exercises\Model\BoardGames_Categories.cs
70+
Chapter_04\Exercises\Model\BoardGames_Domains.cs = Chapter_04\Exercises\Model\BoardGames_Domains.cs
71+
Chapter_04\Exercises\Model\BoardGames_Mechanics.cs = Chapter_04\Exercises\Model\BoardGames_Mechanics.cs
72+
Chapter_04\Exercises\Model\Category.cs = Chapter_04\Exercises\Model\Category.cs
73+
Chapter_04\Exercises\Model\Domain.cs = Chapter_04\Exercises\Model\Domain.cs
74+
Chapter_04\Exercises\Model\Mechanic.cs = Chapter_04\Exercises\Model\Mechanic.cs
75+
Chapter_04\Exercises\Model\Publisher.cs = Chapter_04\Exercises\Model\Publisher.cs
76+
EndProjectSection
77+
EndProject
78+
Global
79+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
80+
Debug|Any CPU = Debug|Any CPU
81+
Release|Any CPU = Release|Any CPU
82+
EndGlobalSection
83+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
84+
{E0467401-AF14-4810-8E7E-22BD4E8D5FFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
85+
{E0467401-AF14-4810-8E7E-22BD4E8D5FFE}.Debug|Any CPU.Build.0 = Debug|Any CPU
86+
{E0467401-AF14-4810-8E7E-22BD4E8D5FFE}.Release|Any CPU.ActiveCfg = Release|Any CPU
87+
{E0467401-AF14-4810-8E7E-22BD4E8D5FFE}.Release|Any CPU.Build.0 = Release|Any CPU
88+
{FBD73632-9D61-46DE-A057-8F01C77E2E49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
89+
{FBD73632-9D61-46DE-A057-8F01C77E2E49}.Debug|Any CPU.Build.0 = Debug|Any CPU
90+
{FBD73632-9D61-46DE-A057-8F01C77E2E49}.Release|Any CPU.ActiveCfg = Release|Any CPU
91+
{FBD73632-9D61-46DE-A057-8F01C77E2E49}.Release|Any CPU.Build.0 = Release|Any CPU
92+
{85DD4D4C-B8E0-49C2-9AA2-E198BBB62329}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
93+
{85DD4D4C-B8E0-49C2-9AA2-E198BBB62329}.Debug|Any CPU.Build.0 = Debug|Any CPU
94+
{85DD4D4C-B8E0-49C2-9AA2-E198BBB62329}.Release|Any CPU.ActiveCfg = Release|Any CPU
95+
{85DD4D4C-B8E0-49C2-9AA2-E198BBB62329}.Release|Any CPU.Build.0 = Release|Any CPU
96+
{8FDCC6E3-FB56-45EF-B18D-B34C882CD1FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
97+
{8FDCC6E3-FB56-45EF-B18D-B34C882CD1FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
98+
{8FDCC6E3-FB56-45EF-B18D-B34C882CD1FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
99+
{8FDCC6E3-FB56-45EF-B18D-B34C882CD1FF}.Release|Any CPU.Build.0 = Release|Any CPU
100+
EndGlobalSection
101+
GlobalSection(SolutionProperties) = preSolution
102+
HideSolutionNode = FALSE
103+
EndGlobalSection
104+
GlobalSection(NestedProjects) = preSolution
105+
{E0467401-AF14-4810-8E7E-22BD4E8D5FFE} = {AB5F2A98-5AA1-4A25-AD70-0BCBB3F5AA58}
106+
{6773746C-CAC2-4114-81DE-B3418FB485C5} = {AB5F2A98-5AA1-4A25-AD70-0BCBB3F5AA58}
107+
{FBD73632-9D61-46DE-A057-8F01C77E2E49} = {39EC7DDB-AA88-480F-B324-877E2C473D9B}
108+
{85DD4D4C-B8E0-49C2-9AA2-E198BBB62329} = {39EC7DDB-AA88-480F-B324-877E2C473D9B}
109+
{545CADC5-5C94-4792-81A3-0FD9EE3DC350} = {39EC7DDB-AA88-480F-B324-877E2C473D9B}
110+
{C692CEE7-E168-43C7-A5E9-7B05B29CE0AF} = {545CADC5-5C94-4792-81A3-0FD9EE3DC350}
111+
{27FADEF1-383E-4FCE-8FBD-7B1BBACAB926} = {C692CEE7-E168-43C7-A5E9-7B05B29CE0AF}
112+
{45E2DF92-2C53-476C-A9DB-2CA409068AEA} = {C692CEE7-E168-43C7-A5E9-7B05B29CE0AF}
113+
{86155047-E0DD-485C-BCC8-048600286231} = {C692CEE7-E168-43C7-A5E9-7B05B29CE0AF}
114+
{8FDCC6E3-FB56-45EF-B18D-B34C882CD1FF} = {888CC4D4-8F56-4EBE-B0C3-829BCE934E00}
115+
{79FC43C4-0966-4DAC-957E-BDB1A36E696E} = {888CC4D4-8F56-4EBE-B0C3-829BCE934E00}
116+
{73294E53-5E4A-4E1E-9D57-3C6FE607EBCE} = {79FC43C4-0966-4DAC-957E-BDB1A36E696E}
117+
{E566019F-3A19-4FF0-90C5-D5BB98B49A9E} = {79FC43C4-0966-4DAC-957E-BDB1A36E696E}
118+
EndGlobalSection
119+
GlobalSection(ExtensibilityGlobals) = postSolution
120+
SolutionGuid = {58E128FF-6460-4A49-9E95-9D8E08D888FC}
121+
EndGlobalSection
122+
EndGlobal

All_Projects.sln

-44
This file was deleted.

Chapter_02/MyBGList/Controllers/WeatherForecastController.cs

-33
This file was deleted.

Chapter_02/MyBGList/WeatherForecast.cs

-13
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using MyBGList.DTO.v1;
3+
4+
namespace MyBGList.Controllers.v1
5+
{
6+
[Route("v{version:apiVersion}/[controller]")]
7+
[ApiController]
8+
[ApiVersion("1.0")]
9+
public class BoardGamesController : ControllerBase
10+
{
11+
private readonly ILogger<BoardGamesController> _logger;
12+
13+
public BoardGamesController(ILogger<BoardGamesController> logger)
14+
{
15+
_logger = logger;
16+
}
17+
18+
[HttpGet(Name = "GetBoardGames")]
19+
[ResponseCache(NoStore = true)]
20+
public RestDTO<BoardGame[]> Get()
21+
{
22+
return new RestDTO<BoardGame[]>()
23+
{
24+
Data = new BoardGame[] {
25+
new BoardGame() {
26+
Id = 1,
27+
Name = "Axis & Allies",
28+
Publisher = "Milton Bradley",
29+
Year = 1981
30+
},
31+
new BoardGame() {
32+
Id = 2,
33+
Name = "Citadel",
34+
Publisher = "Hans im Glück",
35+
Year = 2000
36+
},
37+
new BoardGame() {
38+
Id = 3,
39+
Name = "Terraforming Mars",
40+
Publisher = "FryxGames",
41+
Year = 2016
42+
}
43+
},
44+
Links = new List<LinkDTO> {
45+
new LinkDTO(
46+
Url.Action(null, "BoardGames", null, Request.Scheme)!,
47+
"self",
48+
"GET"),
49+
}
50+
};
51+
}
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using MyBGList.DTO.v2;
3+
4+
namespace MyBGList.Controllers.v2
5+
{
6+
[Route("v{version:apiVersion}/[controller]")]
7+
[ApiController]
8+
[ApiVersion("2.0")]
9+
public class BoardGamesController : ControllerBase
10+
{
11+
private readonly ILogger<BoardGamesController> _logger;
12+
13+
public BoardGamesController(ILogger<BoardGamesController> logger)
14+
{
15+
_logger = logger;
16+
}
17+
18+
[HttpGet(Name = "GetBoardGames")]
19+
[ResponseCache(Location = ResponseCacheLocation.Client, Duration = 120)]
20+
public RestDTO<BoardGame[]> Get()
21+
{
22+
return new RestDTO<BoardGame[]>()
23+
{
24+
Items = new BoardGame[] {
25+
new BoardGame() {
26+
Id = 1,
27+
Name = "Axis & Allies",
28+
Publisher = "Milton Bradley",
29+
Year = 1981
30+
},
31+
new BoardGame() {
32+
Id = 2,
33+
Name = "Citadel",
34+
Publisher = "Hans im Glück",
35+
Year = 2000
36+
},
37+
new BoardGame() {
38+
Id = 3,
39+
Name = "Terraforming Mars",
40+
Publisher = "FryxGames",
41+
Year = 2016
42+
}
43+
},
44+
Links = new List<DTO.v1.LinkDTO> {
45+
new DTO.v1.LinkDTO(
46+
Url.Action(null, "BoardGames", null, Request.Scheme)!,
47+
"self",
48+
"GET"),
49+
}
50+
};
51+
}
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Microsoft.AspNetCore.Cors;
2+
using Microsoft.AspNetCore.Mvc;
3+
4+
namespace MyBGList.Controllers.v2
5+
{
6+
[Route("v{version:apiVersion}/[controller]/[action]")]
7+
[ApiController]
8+
[ApiVersion("2.0")]
9+
public class CodeOnDemandController : ControllerBase
10+
{
11+
[HttpGet(Name = "Test")]
12+
[EnableCors("AnyOrigin")]
13+
[ResponseCache(NoStore = true)]
14+
public ContentResult Test()
15+
{
16+
return Content("<script>" +
17+
"window.alert('Your client supports JavaScript!" +
18+
"\\r\\n\\r\\n" +
19+
$"Server time (UTC): {DateTime.UtcNow.ToString("o")}" +
20+
"\\r\\n" +
21+
"Client time (UTC): ' + new Date().toISOString());" +
22+
"</script>" +
23+
"<noscript>Your client does not support JavaScript</noscript>",
24+
"text/html");
25+
}
26+
27+
[HttpGet(Name = "Test2")]
28+
[EnableCors("AnyOrigin")]
29+
[ResponseCache(NoStore = true)]
30+
public ContentResult Test2(int? addMinutes = null)
31+
{
32+
var dateTime = DateTime.UtcNow;
33+
if (addMinutes.HasValue)
34+
dateTime = dateTime.AddMinutes(addMinutes.Value);
35+
36+
return Content("<script>" +
37+
"window.alert('Your client supports JavaScript!" +
38+
"\\r\\n\\r\\n" +
39+
$"Server time (UTC): {dateTime.ToString("o")}" +
40+
"\\r\\n" +
41+
"Client time (UTC): ' + new Date().toISOString());" +
42+
"</script>" +
43+
"<noscript>Your client does not support JavaScript</noscript>",
44+
"text/html");
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)