From 8fcb170d89dfef74b5b7d3f2f9fe0f29584b7d1d Mon Sep 17 00:00:00 2001 From: Sayed Ibrahim Hashimi Date: Tue, 21 Sep 2021 13:45:33 -0400 Subject: [PATCH 01/20] upgrade to .net 6 --- Directory.Build.props | 8 ++++---- src/BlazingComponents/BlazingComponents.csproj | 2 +- src/BlazingPizza.Client/BlazingPizza.Client.csproj | 2 +- .../BlazingPizza.ComponentsLibrary.csproj | 2 +- src/BlazingPizza.Server/BlazingPizza.Server.csproj | 2 +- src/BlazingPizza.Server/PizzaStoreContext.cs | 2 +- src/BlazingPizza.Server/SpecialsController.cs | 2 ++ src/BlazingPizza.Shared/BlazingPizza.Shared.csproj | 2 +- 8 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index bb2df7b9..49b8f5e4 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,8 +1,8 @@ - 5.0.0 - 5.0.0 - 5.0.0 - 5.0.0 + 6.0.0-rc.1.21452.15 + 6.0.0-rc.1.21452.15 + 6.0.0-rc.1.21452.10 + 6.0.0-rc.1.21451.13 diff --git a/src/BlazingComponents/BlazingComponents.csproj b/src/BlazingComponents/BlazingComponents.csproj index 6325ad64..cd034c1a 100644 --- a/src/BlazingComponents/BlazingComponents.csproj +++ b/src/BlazingComponents/BlazingComponents.csproj @@ -1,7 +1,7 @@  - net5.0 + net6.0 diff --git a/src/BlazingPizza.Client/BlazingPizza.Client.csproj b/src/BlazingPizza.Client/BlazingPizza.Client.csproj index 5014247d..17486ea0 100644 --- a/src/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/src/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -1,7 +1,7 @@  - net5.0 + net6.0 diff --git a/src/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/src/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 5f51ee3c..32150e78 100644 --- a/src/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/src/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -1,7 +1,7 @@  - net5.0 + net6.0 diff --git a/src/BlazingPizza.Server/BlazingPizza.Server.csproj b/src/BlazingPizza.Server/BlazingPizza.Server.csproj index 6391d520..c32275bf 100644 --- a/src/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/src/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -1,7 +1,7 @@  - net5.0 + net6.0 diff --git a/src/BlazingPizza.Server/PizzaStoreContext.cs b/src/BlazingPizza.Server/PizzaStoreContext.cs index 51e96e1e..7fa06430 100644 --- a/src/BlazingPizza.Server/PizzaStoreContext.cs +++ b/src/BlazingPizza.Server/PizzaStoreContext.cs @@ -1,4 +1,4 @@ -using IdentityServer4.EntityFramework.Options; +using Duende.IdentityServer.EntityFramework.Options; using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; diff --git a/src/BlazingPizza.Server/SpecialsController.cs b/src/BlazingPizza.Server/SpecialsController.cs index a176844c..91b01483 100644 --- a/src/BlazingPizza.Server/SpecialsController.cs +++ b/src/BlazingPizza.Server/SpecialsController.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; @@ -20,6 +21,7 @@ public SpecialsController(PizzaStoreContext db) [HttpGet] public async Task>> GetSpecials() { + var foo = _db.Specials.ToList(); return (await _db.Specials.ToListAsync()).OrderByDescending(s => s.BasePrice).ToList(); } } diff --git a/src/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/src/BlazingPizza.Shared/BlazingPizza.Shared.csproj index 911c57c5..583d66fe 100644 --- a/src/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/src/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -1,7 +1,7 @@  - net5.0 + net6.0 BlazingPizza From 79a04729af2e65c9a601ce5192331acda8e8cfa1 Mon Sep 17 00:00:00 2001 From: Sayed Ibrahim Hashimi Date: Tue, 21 Sep 2021 14:39:25 -0400 Subject: [PATCH 02/20] updating to rc2 --- Directory.Build.props | 8 ++++---- src/nuget.config | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 49b8f5e4..1048d648 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,8 +1,8 @@ - 6.0.0-rc.1.21452.15 - 6.0.0-rc.1.21452.15 - 6.0.0-rc.1.21452.10 - 6.0.0-rc.1.21451.13 + 6.0.0-rc.2.21471.1 + 6.0.0-rc.2.21471.1 + 6.0.0-rc.2.21471.1 + 6.0.0-rc.2.21470.23 diff --git a/src/nuget.config b/src/nuget.config index c128a804..787160cf 100644 --- a/src/nuget.config +++ b/src/nuget.config @@ -1,8 +1,9 @@ - + + From d269b716a1d72bb2149849506b07f59a5b3c4489 Mon Sep 17 00:00:00 2001 From: Sayed Ibrahim Hashimi Date: Tue, 21 Sep 2021 14:40:43 -0400 Subject: [PATCH 03/20] adding gitignore to ignore sqllite temp files --- src/BlazingPizza.Server/.gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 src/BlazingPizza.Server/.gitignore diff --git a/src/BlazingPizza.Server/.gitignore b/src/BlazingPizza.Server/.gitignore new file mode 100644 index 00000000..3323b0a7 --- /dev/null +++ b/src/BlazingPizza.Server/.gitignore @@ -0,0 +1,2 @@ +*.db-shm +*.db-wal \ No newline at end of file From 10d6596f282d138315ec90f148ad2c5ad7fabbeb Mon Sep 17 00:00:00 2001 From: Sayed Ibrahim Hashimi Date: Tue, 21 Sep 2021 14:57:37 -0400 Subject: [PATCH 04/20] removing invalid code that i added on accident --- src/BlazingPizza.Server/SpecialsController.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/BlazingPizza.Server/SpecialsController.cs b/src/BlazingPizza.Server/SpecialsController.cs index 91b01483..9c253eb6 100644 --- a/src/BlazingPizza.Server/SpecialsController.cs +++ b/src/BlazingPizza.Server/SpecialsController.cs @@ -21,7 +21,6 @@ public SpecialsController(PizzaStoreContext db) [HttpGet] public async Task>> GetSpecials() { - var foo = _db.Specials.ToList(); return (await _db.Specials.ToListAsync()).OrderByDescending(s => s.BasePrice).ToList(); } } From 0ee662f2fe2b2e98d49d59a9eda2046d61e5571c Mon Sep 17 00:00:00 2001 From: Sayed Ibrahim Hashimi Date: Tue, 21 Sep 2021 15:05:48 -0400 Subject: [PATCH 05/20] going back to a different rc2 build that works w Hot Reload --- Directory.Build.props | 6 +++--- src/BlazingPizza.Client/Pages/Index.razor | 2 +- src/BlazingPizza.Client/Shared/ConfigurePizzaDialog.razor | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 1048d648..3a7b1f2e 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,8 +1,8 @@ - 6.0.0-rc.2.21471.1 - 6.0.0-rc.2.21471.1 - 6.0.0-rc.2.21471.1 + 6.0.0-rc.2.21470.37 + 6.0.0-rc.2.21470.37 + 6.0.0-rc.2.21470.37 6.0.0-rc.2.21470.23 diff --git a/src/BlazingPizza.Client/Pages/Index.razor b/src/BlazingPizza.Client/Pages/Index.razor index ca5ac084..f1309132 100644 --- a/src/BlazingPizza.Client/Pages/Index.razor +++ b/src/BlazingPizza.Client/Pages/Index.razor @@ -36,7 +36,7 @@ } else { -
Choose a pizza
to get started
+
Choose a pizza2
to get started
}
diff --git a/src/BlazingPizza.Client/Shared/ConfigurePizzaDialog.razor b/src/BlazingPizza.Client/Shared/ConfigurePizzaDialog.razor index 67096b01..f4dd45b4 100644 --- a/src/BlazingPizza.Client/Shared/ConfigurePizzaDialog.razor +++ b/src/BlazingPizza.Client/Shared/ConfigurePizzaDialog.razor @@ -13,7 +13,7 @@
- + @if (toppings == null) { From 70ebe01475096675b42bbb8976debd1ef2974bb0 Mon Sep 17 00:00:00 2001 From: "Jeffrey T. Fritz" Date: Fri, 28 Jan 2022 12:56:39 -0500 Subject: [PATCH 07/20] Started TFM variable --- Directory.Build.props | 9 +++++---- src/BlazingComponents/BlazingComponents.csproj | 2 +- src/BlazingPizza.Client/BlazingPizza.Client.csproj | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 3a7b1f2e..a8b3d094 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,8 +1,9 @@ - 6.0.0-rc.2.21470.37 - 6.0.0-rc.2.21470.37 - 6.0.0-rc.2.21470.37 - 6.0.0-rc.2.21470.23 + 6.0.0 + 6.0.0 + 6.0.0 + net6.0 + 6.0.0 diff --git a/src/BlazingComponents/BlazingComponents.csproj b/src/BlazingComponents/BlazingComponents.csproj index cd034c1a..e0a4b76a 100644 --- a/src/BlazingComponents/BlazingComponents.csproj +++ b/src/BlazingComponents/BlazingComponents.csproj @@ -1,7 +1,7 @@  - net6.0 + $(TargetFrameworkVersion) diff --git a/src/BlazingPizza.Client/BlazingPizza.Client.csproj b/src/BlazingPizza.Client/BlazingPizza.Client.csproj index 17486ea0..168bb22a 100644 --- a/src/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/src/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -1,7 +1,7 @@  - net6.0 + $(TargetFrameworkVersion) From 915346032dca9363ce2e551ece741d3f310a63fc Mon Sep 17 00:00:00 2001 From: "Jeffrey T. Fritz" Date: Fri, 28 Jan 2022 13:09:35 -0500 Subject: [PATCH 08/20] Updated all projects to NET6 and Duende IdentityFramework --- .../BlazingPizza.Client/BlazingPizza.Client.csproj | 2 +- .../BlazingPizza.ComponentsLibrary.csproj | 2 +- .../BlazingPizza.Server/BlazingPizza.Server.csproj | 2 +- .../00-get-started/BlazingPizza.Server/PizzaStoreContext.cs | 2 +- .../BlazingPizza.Shared/BlazingPizza.Shared.csproj | 2 +- .../BlazingPizza.Client/BlazingPizza.Client.csproj | 2 +- .../BlazingPizza.ComponentsLibrary.csproj | 2 +- .../BlazingPizza.Server/BlazingPizza.Server.csproj | 2 +- .../BlazingPizza.Server/PizzaStoreContext.cs | 2 +- .../BlazingPizza.Shared/BlazingPizza.Shared.csproj | 2 +- .../BlazingPizza.Client/BlazingPizza.Client.csproj | 2 +- .../BlazingPizza.ComponentsLibrary.csproj | 2 +- .../BlazingPizza.Server/BlazingPizza.Server.csproj | 2 +- .../BlazingPizza.Server/PizzaStoreContext.cs | 2 +- .../BlazingPizza.Shared/BlazingPizza.Shared.csproj | 2 +- .../BlazingPizza.Client/BlazingPizza.Client.csproj | 2 +- .../BlazingPizza.ComponentsLibrary.csproj | 2 +- .../BlazingPizza.Server/BlazingPizza.Server.csproj | 2 +- .../BlazingPizza.Server/PizzaStoreContext.cs | 2 +- .../BlazingPizza.Shared/BlazingPizza.Shared.csproj | 2 +- .../BlazingPizza.Client/BlazingPizza.Client.csproj | 2 +- .../BlazingPizza.ComponentsLibrary.csproj | 2 +- .../BlazingPizza.Server/BlazingPizza.Server.csproj | 2 +- .../BlazingPizza.Server/PizzaStoreContext.cs | 2 +- .../BlazingPizza.Shared/BlazingPizza.Shared.csproj | 2 +- .../BlazingPizza.Client/BlazingPizza.Client.csproj | 2 +- .../BlazingPizza.ComponentsLibrary.csproj | 2 +- .../BlazingPizza.Server/BlazingPizza.Server.csproj | 2 +- .../BlazingPizza.Server/PizzaStoreContext.cs | 2 +- .../BlazingPizza.Shared/BlazingPizza.Shared.csproj | 2 +- .../BlazingPizza.Client/BlazingPizza.Client.csproj | 2 +- .../BlazingPizza.ComponentsLibrary.csproj | 2 +- .../BlazingPizza.Server/BlazingPizza.Server.csproj | 2 +- .../BlazingPizza.Server/PizzaStoreContext.cs | 2 +- .../BlazingPizza.Shared/BlazingPizza.Shared.csproj | 2 +- .../BlazingPizza.Client/BlazingPizza.Client.csproj | 2 +- .../BlazingPizza.ComponentsLibrary.csproj | 2 +- .../BlazingPizza.Server/BlazingPizza.Server.csproj | 2 +- .../BlazingPizza.Server/PizzaStoreContext.cs | 2 +- .../BlazingPizza.Shared/BlazingPizza.Shared.csproj | 2 +- .../BlazingComponents/BlazingComponents.csproj | 2 +- .../BlazingPizza.Client/BlazingPizza.Client.csproj | 2 +- .../BlazingPizza.ComponentsLibrary.csproj | 2 +- .../BlazingPizza.Server/BlazingPizza.Server.csproj | 2 +- .../BlazingPizza.Server/PizzaStoreContext.cs | 2 +- .../BlazingPizza.Shared/BlazingPizza.Shared.csproj | 2 +- .../BlazingComponents/BlazingComponents.csproj | 2 +- .../BlazingPizza.Client/BlazingPizza.Client.csproj | 2 +- .../BlazingPizza.ComponentsLibrary.csproj | 2 +- .../BlazingPizza.Server/BlazingPizza.Server.csproj | 2 +- .../BlazingPizza.Server/PizzaStoreContext.cs | 2 +- .../BlazingPizza.Shared/BlazingPizza.Shared.csproj | 2 +- .../BlazingPizza.ComponentsLibrary.csproj | 2 +- src/BlazingPizza.Server/BlazingPizza.Server.csproj | 2 +- src/BlazingPizza.Shared/BlazingPizza.Shared.csproj | 2 +- src/nuget.config | 1 - 56 files changed, 55 insertions(+), 56 deletions(-) diff --git a/save-points/00-get-started/BlazingPizza.Client/BlazingPizza.Client.csproj b/save-points/00-get-started/BlazingPizza.Client/BlazingPizza.Client.csproj index 04df2ddd..bfef7295 100644 --- a/save-points/00-get-started/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/save-points/00-get-started/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/00-get-started/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/save-points/00-get-started/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 5f51ee3c..61ebf623 100644 --- a/save-points/00-get-started/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/save-points/00-get-started/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/00-get-started/BlazingPizza.Server/BlazingPizza.Server.csproj b/save-points/00-get-started/BlazingPizza.Server/BlazingPizza.Server.csproj index fd7e3c51..b9c74fc4 100644 --- a/save-points/00-get-started/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/save-points/00-get-started/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/00-get-started/BlazingPizza.Server/PizzaStoreContext.cs b/save-points/00-get-started/BlazingPizza.Server/PizzaStoreContext.cs index f79c1c66..fae5acb4 100644 --- a/save-points/00-get-started/BlazingPizza.Server/PizzaStoreContext.cs +++ b/save-points/00-get-started/BlazingPizza.Server/PizzaStoreContext.cs @@ -1,4 +1,4 @@ -using IdentityServer4.EntityFramework.Options; +using IDuende.IdentityServerEEntityFramework.Options using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; diff --git a/save-points/00-get-started/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/save-points/00-get-started/BlazingPizza.Shared/BlazingPizza.Shared.csproj index 911c57c5..f7b7dd02 100644 --- a/save-points/00-get-started/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/save-points/00-get-started/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) BlazingPizza diff --git a/save-points/01-Components-and-layout/BlazingPizza.Client/BlazingPizza.Client.csproj b/save-points/01-Components-and-layout/BlazingPizza.Client/BlazingPizza.Client.csproj index a833c6be..663677a1 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/save-points/01-Components-and-layout/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 5f51ee3c..61ebf623 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/BlazingPizza.Server.csproj b/save-points/01-Components-and-layout/BlazingPizza.Server/BlazingPizza.Server.csproj index fd7e3c51..b9c74fc4 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/PizzaStoreContext.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/PizzaStoreContext.cs index f79c1c66..9485bd12 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Server/PizzaStoreContext.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/PizzaStoreContext.cs @@ -1,4 +1,4 @@ -using IdentityServer4.EntityFramework.Options; +using Duende.IdentityServer.EntityFramework.Options; using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; diff --git a/save-points/01-Components-and-layout/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/save-points/01-Components-and-layout/BlazingPizza.Shared/BlazingPizza.Shared.csproj index 911c57c5..f7b7dd02 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/save-points/01-Components-and-layout/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) BlazingPizza diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Client/BlazingPizza.Client.csproj b/save-points/02-customize-a-pizza/BlazingPizza.Client/BlazingPizza.Client.csproj index c50ce7e0..cd5da247 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/save-points/02-customize-a-pizza/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/02-customize-a-pizza/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/save-points/02-customize-a-pizza/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 5f51ee3c..61ebf623 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/save-points/02-customize-a-pizza/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/BlazingPizza.Server.csproj b/save-points/02-customize-a-pizza/BlazingPizza.Server/BlazingPizza.Server.csproj index fd7e3c51..b9c74fc4 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/PizzaStoreContext.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/PizzaStoreContext.cs index f79c1c66..9485bd12 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Server/PizzaStoreContext.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/PizzaStoreContext.cs @@ -1,4 +1,4 @@ -using IdentityServer4.EntityFramework.Options; +using Duende.IdentityServer.EntityFramework.Options; using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/save-points/02-customize-a-pizza/BlazingPizza.Shared/BlazingPizza.Shared.csproj index 911c57c5..f7b7dd02 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/save-points/02-customize-a-pizza/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) BlazingPizza diff --git a/save-points/03-show-order-status/BlazingPizza.Client/BlazingPizza.Client.csproj b/save-points/03-show-order-status/BlazingPizza.Client/BlazingPizza.Client.csproj index a833c6be..663677a1 100644 --- a/save-points/03-show-order-status/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/save-points/03-show-order-status/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 5f51ee3c..61ebf623 100644 --- a/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/03-show-order-status/BlazingPizza.Server/BlazingPizza.Server.csproj b/save-points/03-show-order-status/BlazingPizza.Server/BlazingPizza.Server.csproj index fd7e3c51..b9c74fc4 100644 --- a/save-points/03-show-order-status/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/save-points/03-show-order-status/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/03-show-order-status/BlazingPizza.Server/PizzaStoreContext.cs b/save-points/03-show-order-status/BlazingPizza.Server/PizzaStoreContext.cs index f79c1c66..9485bd12 100644 --- a/save-points/03-show-order-status/BlazingPizza.Server/PizzaStoreContext.cs +++ b/save-points/03-show-order-status/BlazingPizza.Server/PizzaStoreContext.cs @@ -1,4 +1,4 @@ -using IdentityServer4.EntityFramework.Options; +using Duende.IdentityServer.EntityFramework.Options; using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; diff --git a/save-points/03-show-order-status/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/save-points/03-show-order-status/BlazingPizza.Shared/BlazingPizza.Shared.csproj index 911c57c5..f7b7dd02 100644 --- a/save-points/03-show-order-status/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/save-points/03-show-order-status/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) BlazingPizza diff --git a/save-points/04-refactor-state-management/BlazingPizza.Client/BlazingPizza.Client.csproj b/save-points/04-refactor-state-management/BlazingPizza.Client/BlazingPizza.Client.csproj index a833c6be..663677a1 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/save-points/04-refactor-state-management/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 5f51ee3c..61ebf623 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/BlazingPizza.Server.csproj b/save-points/04-refactor-state-management/BlazingPizza.Server/BlazingPizza.Server.csproj index fd7e3c51..b9c74fc4 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/PizzaStoreContext.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/PizzaStoreContext.cs index f79c1c66..9485bd12 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Server/PizzaStoreContext.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/PizzaStoreContext.cs @@ -1,4 +1,4 @@ -using IdentityServer4.EntityFramework.Options; +using Duende.IdentityServer.EntityFramework.Options; using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; diff --git a/save-points/04-refactor-state-management/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/save-points/04-refactor-state-management/BlazingPizza.Shared/BlazingPizza.Shared.csproj index 911c57c5..f7b7dd02 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/save-points/04-refactor-state-management/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) BlazingPizza diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Client/BlazingPizza.Client.csproj b/save-points/05-checkout-with-validation/BlazingPizza.Client/BlazingPizza.Client.csproj index a833c6be..663677a1 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/save-points/05-checkout-with-validation/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 5f51ee3c..61ebf623 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/BlazingPizza.Server.csproj b/save-points/05-checkout-with-validation/BlazingPizza.Server/BlazingPizza.Server.csproj index fd7e3c51..b9c74fc4 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/PizzaStoreContext.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/PizzaStoreContext.cs index f79c1c66..9485bd12 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Server/PizzaStoreContext.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/PizzaStoreContext.cs @@ -1,4 +1,4 @@ -using IdentityServer4.EntityFramework.Options; +using Duende.IdentityServer.EntityFramework.Options; using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/save-points/05-checkout-with-validation/BlazingPizza.Shared/BlazingPizza.Shared.csproj index 911c57c5..f7b7dd02 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/save-points/05-checkout-with-validation/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) BlazingPizza diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Client/BlazingPizza.Client.csproj b/save-points/06-authentication-and-authorization/BlazingPizza.Client/BlazingPizza.Client.csproj index a833c6be..663677a1 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 5f51ee3c..61ebf623 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/BlazingPizza.Server.csproj b/save-points/06-authentication-and-authorization/BlazingPizza.Server/BlazingPizza.Server.csproj index fd7e3c51..b9c74fc4 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/PizzaStoreContext.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/PizzaStoreContext.cs index f79c1c66..9485bd12 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Server/PizzaStoreContext.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/PizzaStoreContext.cs @@ -1,4 +1,4 @@ -using IdentityServer4.EntityFramework.Options; +using Duende.IdentityServer.EntityFramework.Options; using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/BlazingPizza.Shared.csproj index 911c57c5..f7b7dd02 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) BlazingPizza diff --git a/save-points/07-javascript-interop/BlazingPizza.Client/BlazingPizza.Client.csproj b/save-points/07-javascript-interop/BlazingPizza.Client/BlazingPizza.Client.csproj index a833c6be..663677a1 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/save-points/07-javascript-interop/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 5f51ee3c..61ebf623 100644 --- a/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/BlazingPizza.Server.csproj b/save-points/07-javascript-interop/BlazingPizza.Server/BlazingPizza.Server.csproj index fd7e3c51..b9c74fc4 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/save-points/07-javascript-interop/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/PizzaStoreContext.cs b/save-points/07-javascript-interop/BlazingPizza.Server/PizzaStoreContext.cs index f79c1c66..9485bd12 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Server/PizzaStoreContext.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Server/PizzaStoreContext.cs @@ -1,4 +1,4 @@ -using IdentityServer4.EntityFramework.Options; +using Duende.IdentityServer.EntityFramework.Options; using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; diff --git a/save-points/07-javascript-interop/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/save-points/07-javascript-interop/BlazingPizza.Shared/BlazingPizza.Shared.csproj index 911c57c5..f7b7dd02 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/save-points/07-javascript-interop/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) BlazingPizza diff --git a/save-points/08-templated-components/BlazingComponents/BlazingComponents.csproj b/save-points/08-templated-components/BlazingComponents/BlazingComponents.csproj index 6325ad64..e0a4b76a 100644 --- a/save-points/08-templated-components/BlazingComponents/BlazingComponents.csproj +++ b/save-points/08-templated-components/BlazingComponents/BlazingComponents.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/08-templated-components/BlazingPizza.Client/BlazingPizza.Client.csproj b/save-points/08-templated-components/BlazingPizza.Client/BlazingPizza.Client.csproj index c6ff02af..7fecc21b 100644 --- a/save-points/08-templated-components/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/save-points/08-templated-components/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 5f51ee3c..61ebf623 100644 --- a/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/08-templated-components/BlazingPizza.Server/BlazingPizza.Server.csproj b/save-points/08-templated-components/BlazingPizza.Server/BlazingPizza.Server.csproj index fd7e3c51..b9c74fc4 100644 --- a/save-points/08-templated-components/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/save-points/08-templated-components/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/08-templated-components/BlazingPizza.Server/PizzaStoreContext.cs b/save-points/08-templated-components/BlazingPizza.Server/PizzaStoreContext.cs index f79c1c66..9485bd12 100644 --- a/save-points/08-templated-components/BlazingPizza.Server/PizzaStoreContext.cs +++ b/save-points/08-templated-components/BlazingPizza.Server/PizzaStoreContext.cs @@ -1,4 +1,4 @@ -using IdentityServer4.EntityFramework.Options; +using Duende.IdentityServer.EntityFramework.Options; using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; diff --git a/save-points/08-templated-components/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/save-points/08-templated-components/BlazingPizza.Shared/BlazingPizza.Shared.csproj index 911c57c5..f7b7dd02 100644 --- a/save-points/08-templated-components/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/save-points/08-templated-components/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) BlazingPizza diff --git a/save-points/09-progressive-web-app/BlazingComponents/BlazingComponents.csproj b/save-points/09-progressive-web-app/BlazingComponents/BlazingComponents.csproj index df017b6f..89335194 100644 --- a/save-points/09-progressive-web-app/BlazingComponents/BlazingComponents.csproj +++ b/save-points/09-progressive-web-app/BlazingComponents/BlazingComponents.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + $(TargetFrameworkVersion) 3.0 diff --git a/save-points/09-progressive-web-app/BlazingPizza.Client/BlazingPizza.Client.csproj b/save-points/09-progressive-web-app/BlazingPizza.Client/BlazingPizza.Client.csproj index c6ff02af..7fecc21b 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/save-points/09-progressive-web-app/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/09-progressive-web-app/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/save-points/09-progressive-web-app/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 255af646..1ec992ad 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/save-points/09-progressive-web-app/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/BlazingPizza.Server.csproj b/save-points/09-progressive-web-app/BlazingPizza.Server/BlazingPizza.Server.csproj index 6391d520..e1e7aaef 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/PizzaStoreContext.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/PizzaStoreContext.cs index f79c1c66..9485bd12 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Server/PizzaStoreContext.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/PizzaStoreContext.cs @@ -1,4 +1,4 @@ -using IdentityServer4.EntityFramework.Options; +using Duende.IdentityServer.EntityFramework.Options; using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; diff --git a/save-points/09-progressive-web-app/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/save-points/09-progressive-web-app/BlazingPizza.Shared/BlazingPizza.Shared.csproj index 911c57c5..f7b7dd02 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/save-points/09-progressive-web-app/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) BlazingPizza diff --git a/src/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/src/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 32150e78..61ebf623 100644 --- a/src/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/src/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -1,7 +1,7 @@  - net6.0 + $(TargetFrameworkVersion) diff --git a/src/BlazingPizza.Server/BlazingPizza.Server.csproj b/src/BlazingPizza.Server/BlazingPizza.Server.csproj index c32275bf..e1e7aaef 100644 --- a/src/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/src/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -1,7 +1,7 @@  - net6.0 + $(TargetFrameworkVersion) diff --git a/src/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/src/BlazingPizza.Shared/BlazingPizza.Shared.csproj index 583d66fe..f7b7dd02 100644 --- a/src/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/src/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -1,7 +1,7 @@  - net6.0 + $(TargetFrameworkVersion) BlazingPizza diff --git a/src/nuget.config b/src/nuget.config index 787160cf..719ff50f 100644 --- a/src/nuget.config +++ b/src/nuget.config @@ -4,6 +4,5 @@ - From 08ce819fc2b511a00852fc2abd847050ce32dd37 Mon Sep 17 00:00:00 2001 From: "Jeffrey T. Fritz" Date: Fri, 28 Jan 2022 14:54:02 -0500 Subject: [PATCH 09/20] Upgraded finished project to .NET 6 with C# 10 features Added generated JSON Serialization Added EF compiled models --- src/nuget.config => nuget.config | 16 +- .../BlazingPizza.Client.csproj | 1 + .../BlazingPizza.Client/Program.cs | 24 +- .../BlazingPizza.ComponentsLibrary.csproj | 1 + .../LocalStorage.cs | 20 +- .../BlazingPizza.Server.csproj | 1 + .../NotificationsController.cs | 43 -- .../OidcConfigurationController.cs | 35 +- .../BlazingPizza.Server/OrdersController.cs | 215 +++++----- .../BlazingPizza.Server/PizzaApiExtensions.cs | 60 +++ .../BlazingPizza.Server/PizzaStoreContext.cs | 49 ++- .../BlazingPizza.Server/PizzasController.cs | 16 - .../BlazingPizza.Server/Program.cs | 93 +++-- .../BlazingPizza.Server/SeedData.cs | 379 +++++++++--------- .../BlazingPizza.Server/SpecialsController.cs | 26 -- .../BlazingPizza.Server/Startup.cs | 70 ---- .../BlazingPizza.Server/ToppingsController.cs | 26 -- .../BlazingPizza.Client.csproj | 1 + .../JSRuntimeExtensions.cs | 16 +- src/BlazingPizza.Client/OrderState.cs | 101 +++-- src/BlazingPizza.Client/OrdersClient.cs | 59 ++- src/BlazingPizza.Client/Pages/Index.razor | 2 +- .../PizzaAuthenticationState.cs | 9 +- src/BlazingPizza.Client/Program.cs | 37 +- .../Shared/ConfigurePizzaDialog.razor | 2 +- .../BlazingPizza.ComponentsLibrary.csproj | 1 + .../LocalStorage.cs | 22 +- .../Map/Marker.cs | 15 +- .../Map/Point.cs | 13 +- .../BlazingPizza.Server.csproj | 1 + .../Models/AddressEntityType.cs | 92 +++++ .../Models/DeviceFlowCodesEntityType.cs | 114 ++++++ .../IdentityRoleClaimstringEntityType.cs | 85 ++++ .../Models/IdentityRoleEntityType.cs | 78 ++++ .../IdentityUserClaimstringEntityType.cs | 85 ++++ .../IdentityUserLoginstringEntityType.cs | 86 ++++ .../IdentityUserRolestringEntityType.cs | 82 ++++ .../IdentityUserTokenstringEntityType.cs | 84 ++++ .../Models/KeyEntityType.cs | 96 +++++ .../Models/LatLongEntityType.cs | 80 ++++ .../NotificationSubscriptionEntityType.cs | 77 ++++ .../Models/OrderEntityType.cs | 86 ++++ .../Models/PersistedGrantEntityType.cs | 127 ++++++ .../Models/PizzaEntityType.cs | 111 +++++ .../Models/PizzaSpecialEntityType.cs | 76 ++++ .../Models/PizzaStoreContextModel.cs | 28 ++ .../Models/PizzaStoreContextModelBuilder.cs | 69 ++++ .../Models/PizzaStoreUserEntityType.cs | 156 +++++++ .../Models/PizzaToppingEntityType.cs | 96 +++++ .../Models/ToppingEntityType.cs | 62 +++ .../NotificationsController.cs | 43 -- .../OidcConfigurationController.cs | 33 +- src/BlazingPizza.Server/OrdersController.cs | 249 ++++++------ src/BlazingPizza.Server/PizzaApiExtensions.cs | 60 +++ src/BlazingPizza.Server/PizzaStoreContext.cs | 47 ++- src/BlazingPizza.Server/PizzaStoreUser.cs | 9 +- src/BlazingPizza.Server/PizzasController.cs | 16 - src/BlazingPizza.Server/Program.cs | 94 +++-- src/BlazingPizza.Server/SeedData.cs | 379 +++++++++--------- src/BlazingPizza.Server/SpecialsController.cs | 27 -- src/BlazingPizza.Server/Startup.cs | 70 ---- src/BlazingPizza.Server/ToppingsController.cs | 26 -- src/BlazingPizza.Shared/Address.cs | 33 +- .../BlazingPizza.Shared.csproj | 5 + src/BlazingPizza.Shared/LatLong.cs | 43 +- .../NotificationSubscription.cs | 17 +- src/BlazingPizza.Shared/Order.cs | 37 +- src/BlazingPizza.Shared/OrderWithStatus.cs | 133 +++--- src/BlazingPizza.Shared/Pizza.cs | 62 +-- src/BlazingPizza.Shared/PizzaSpecial.cs | 27 +- src/BlazingPizza.Shared/PizzaTopping.cs | 18 +- src/BlazingPizza.Shared/Topping.cs | 18 +- src/BlazingPizza.Shared/UserInfo.cs | 14 +- 73 files changed, 3061 insertions(+), 1523 deletions(-) rename src/nuget.config => nuget.config (97%) delete mode 100644 save-points/00-get-started/BlazingPizza.Server/NotificationsController.cs create mode 100644 save-points/00-get-started/BlazingPizza.Server/PizzaApiExtensions.cs delete mode 100644 save-points/00-get-started/BlazingPizza.Server/PizzasController.cs delete mode 100644 save-points/00-get-started/BlazingPizza.Server/SpecialsController.cs delete mode 100644 save-points/00-get-started/BlazingPizza.Server/Startup.cs delete mode 100644 save-points/00-get-started/BlazingPizza.Server/ToppingsController.cs create mode 100644 src/BlazingPizza.Server/Models/AddressEntityType.cs create mode 100644 src/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs create mode 100644 src/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs create mode 100644 src/BlazingPizza.Server/Models/IdentityRoleEntityType.cs create mode 100644 src/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs create mode 100644 src/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs create mode 100644 src/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs create mode 100644 src/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs create mode 100644 src/BlazingPizza.Server/Models/KeyEntityType.cs create mode 100644 src/BlazingPizza.Server/Models/LatLongEntityType.cs create mode 100644 src/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs create mode 100644 src/BlazingPizza.Server/Models/OrderEntityType.cs create mode 100644 src/BlazingPizza.Server/Models/PersistedGrantEntityType.cs create mode 100644 src/BlazingPizza.Server/Models/PizzaEntityType.cs create mode 100644 src/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs create mode 100644 src/BlazingPizza.Server/Models/PizzaStoreContextModel.cs create mode 100644 src/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs create mode 100644 src/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs create mode 100644 src/BlazingPizza.Server/Models/PizzaToppingEntityType.cs create mode 100644 src/BlazingPizza.Server/Models/ToppingEntityType.cs delete mode 100644 src/BlazingPizza.Server/NotificationsController.cs create mode 100644 src/BlazingPizza.Server/PizzaApiExtensions.cs delete mode 100644 src/BlazingPizza.Server/PizzasController.cs delete mode 100644 src/BlazingPizza.Server/SpecialsController.cs delete mode 100644 src/BlazingPizza.Server/Startup.cs delete mode 100644 src/BlazingPizza.Server/ToppingsController.cs diff --git a/src/nuget.config b/nuget.config similarity index 97% rename from src/nuget.config rename to nuget.config index 719ff50f..023d22cf 100644 --- a/src/nuget.config +++ b/nuget.config @@ -1,8 +1,8 @@ - - - - - - - - + + + + + + + + diff --git a/save-points/00-get-started/BlazingPizza.Client/BlazingPizza.Client.csproj b/save-points/00-get-started/BlazingPizza.Client/BlazingPizza.Client.csproj index bfef7295..86250f68 100644 --- a/save-points/00-get-started/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/save-points/00-get-started/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -2,6 +2,7 @@ $(TargetFrameworkVersion) + true diff --git a/save-points/00-get-started/BlazingPizza.Client/Program.cs b/save-points/00-get-started/BlazingPizza.Client/Program.cs index 48147d6f..ab7dd4d9 100644 --- a/save-points/00-get-started/BlazingPizza.Client/Program.cs +++ b/save-points/00-get-started/BlazingPizza.Client/Program.cs @@ -1,21 +1,9 @@ -using Microsoft.AspNetCore.Components.WebAssembly.Hosting; -using Microsoft.Extensions.DependencyInjection; -using System; -using System.Net.Http; -using System.Threading.Tasks; +using BlazingPizza.Client; +using Microsoft.AspNetCore.Components.WebAssembly.Hosting; -namespace BlazingPizza.Client -{ - public class Program - { - public static async Task Main(string[] args) - { - var builder = WebAssemblyHostBuilder.CreateDefault(args); - builder.RootComponents.Add("#app"); +var builder = WebAssemblyHostBuilder.CreateDefault(args); +builder.RootComponents.Add("#app"); - builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); +builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); - await builder.Build().RunAsync(); - } - } -} +await builder.Build().RunAsync(); diff --git a/save-points/00-get-started/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/save-points/00-get-started/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 61ebf623..cb996b1b 100644 --- a/save-points/00-get-started/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/save-points/00-get-started/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -2,6 +2,7 @@ $(TargetFrameworkVersion) + true diff --git a/save-points/00-get-started/BlazingPizza.ComponentsLibrary/LocalStorage.cs b/save-points/00-get-started/BlazingPizza.ComponentsLibrary/LocalStorage.cs index f36b098e..1b91cef9 100644 --- a/save-points/00-get-started/BlazingPizza.ComponentsLibrary/LocalStorage.cs +++ b/save-points/00-get-started/BlazingPizza.ComponentsLibrary/LocalStorage.cs @@ -1,17 +1,15 @@ using Microsoft.JSInterop; -using System.Threading.Tasks; -namespace BlazingPizza.ComponentsLibrary +namespace BlazingPizza.ComponentsLibrary; + +public static class LocalStorage { - public static class LocalStorage - { - public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) - => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); + public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) + => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); - public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object value) - => jsRuntime.InvokeVoidAsync("blazorLocalStorage.set", key, value); + public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object value) + => jsRuntime.InvokeVoidAsync("blazorLocalStorage.set", key, value); - public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key) - => jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key); - } + public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key) + => jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key); } diff --git a/save-points/00-get-started/BlazingPizza.Server/BlazingPizza.Server.csproj b/save-points/00-get-started/BlazingPizza.Server/BlazingPizza.Server.csproj index b9c74fc4..227890e1 100644 --- a/save-points/00-get-started/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/save-points/00-get-started/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -2,6 +2,7 @@ $(TargetFrameworkVersion) + true diff --git a/save-points/00-get-started/BlazingPizza.Server/NotificationsController.cs b/save-points/00-get-started/BlazingPizza.Server/NotificationsController.cs deleted file mode 100644 index bb3b96ff..00000000 --- a/save-points/00-get-started/BlazingPizza.Server/NotificationsController.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("notifications")] - [ApiController] - [Authorize] - public class NotificationsController : Controller - { - private readonly PizzaStoreContext _db; - - public NotificationsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpPut("subscribe")] - public async Task Subscribe(NotificationSubscription subscription) - { - // We're storing at most one subscription per user, so delete old ones. - // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. - var userId = GetUserId(); - var oldSubscriptions = _db.NotificationSubscriptions.Where(e => e.UserId == userId); - _db.NotificationSubscriptions.RemoveRange(oldSubscriptions); - - // Store new subscription - subscription.UserId = userId; - _db.NotificationSubscriptions.Attach(subscription); - - await _db.SaveChangesAsync(); - return subscription; - } - - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } - } -} diff --git a/save-points/00-get-started/BlazingPizza.Server/OidcConfigurationController.cs b/save-points/00-get-started/BlazingPizza.Server/OidcConfigurationController.cs index c074debf..b7654075 100644 --- a/save-points/00-get-started/BlazingPizza.Server/OidcConfigurationController.cs +++ b/save-points/00-get-started/BlazingPizza.Server/OidcConfigurationController.cs @@ -1,26 +1,21 @@ using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class OidcConfigurationController : Controller { - public class OidcConfigurationController : Controller - { - public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) - { - ClientRequestParametersProvider = clientRequestParametersProvider; - } + public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) + { + ClientRequestParametersProvider = clientRequestParametersProvider; + } - public IClientRequestParametersProvider ClientRequestParametersProvider { get; } + public IClientRequestParametersProvider ClientRequestParametersProvider { get; } - [HttpGet("_configuration/{clientId}")] - public IActionResult GetClientRequestParameters([FromRoute]string clientId) - { - var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); - return Ok(parameters); - } - } -} + [HttpGet("_configuration/{clientId}")] + public IActionResult GetClientRequestParameters([FromRoute] string clientId) + { + var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); + return Ok(parameters); + } +} \ No newline at end of file diff --git a/save-points/00-get-started/BlazingPizza.Server/OrdersController.cs b/save-points/00-get-started/BlazingPizza.Server/OrdersController.cs index 2b8bc99b..54ff6114 100644 --- a/save-points/00-get-started/BlazingPizza.Server/OrdersController.cs +++ b/save-points/00-get-started/BlazingPizza.Server/OrdersController.cs @@ -1,114 +1,109 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; +using System.Security.Claims; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +[Route("orders")] +[ApiController] +// [Authorize] +public class OrdersController : Controller { - [Route("orders")] - [ApiController] - // [Authorize] - public class OrdersController : Controller - { - private readonly PizzaStoreContext _db; - - public OrdersController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetOrders() - { - var orders = await _db.Orders - // .Where(o => o.UserId == GetUserId()) - .Include(o => o.DeliveryLocation) - .Include(o => o.Pizzas).ThenInclude(p => p.Special) - .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) - .OrderByDescending(o => o.CreatedTime) - .ToListAsync(); - - return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); - } - - [HttpGet("{orderId}")] - public async Task> GetOrderWithStatus(int orderId) - { - var order = await _db.Orders - .Where(o => o.OrderId == orderId) - // .Where(o => o.UserId == GetUserId()) - .Include(o => o.DeliveryLocation) - .Include(o => o.Pizzas).ThenInclude(p => p.Special) - .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) - .SingleOrDefaultAsync(); - - if (order == null) - { - return NotFound(); - } - - return OrderWithStatus.FromOrder(order); - } - - [HttpPost] - public async Task> PlaceOrder(Order order) - { - order.CreatedTime = DateTime.Now; - order.DeliveryLocation = new LatLong(51.5001, -0.1239); - // order.UserId = GetUserId(); - - // Enforce existence of Pizza.SpecialId and Topping.ToppingId - // in the database - prevent the submitter from making up - // new specials and toppings - foreach (var pizza in order.Pizzas) - { - pizza.SpecialId = pizza.Special.Id; - pizza.Special = null; - - foreach (var topping in pizza.Toppings) - { - topping.ToppingId = topping.Topping.Id; - topping.Topping = null; - } - } - - _db.Orders.Attach(order); - await _db.SaveChangesAsync(); - - // In the background, send push notifications if possible - var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); - if (subscription != null) - { - _ = TrackAndSendNotificationsAsync(order, subscription); - } - - return order.OrderId; - } - - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } - - private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription subscription) - { - // In a realistic case, some other backend process would track - // order delivery progress and send us notifications when it - // changes. Since we don't have any such process here, fake it. - await Task.Delay(OrderWithStatus.PreparationDuration); - await SendNotificationAsync(order, subscription, "Your order has been dispatched!"); - - await Task.Delay(OrderWithStatus.DeliveryDuration); - await SendNotificationAsync(order, subscription, "Your order is now delivered. Enjoy!"); - } - - private static Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) - { - // This will be implemented later - return Task.CompletedTask; - } - } -} + private readonly PizzaStoreContext _db; + + public OrdersController(PizzaStoreContext db) + { + _db = db; + } + + [HttpGet] + public async Task>> GetOrders() + { + var orders = await _db.Orders + // .Where(o => o.UserId == GetUserId()) + .Include(o => o.DeliveryLocation) + .Include(o => o.Pizzas).ThenInclude(p => p.Special) + .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) + .OrderByDescending(o => o.CreatedTime) + .ToListAsync(); + + return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); + } + + [HttpGet("{orderId}")] + public async Task> GetOrderWithStatus(int orderId) + { + var order = await _db.Orders + .Where(o => o.OrderId == orderId) + // .Where(o => o.UserId == GetUserId()) + .Include(o => o.DeliveryLocation) + .Include(o => o.Pizzas).ThenInclude(p => p.Special) + .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) + .SingleOrDefaultAsync(); + + if (order == null) + { + return NotFound(); + } + + return OrderWithStatus.FromOrder(order); + } + + [HttpPost] + public async Task> PlaceOrder(Order order) + { + order.CreatedTime = DateTime.Now; + order.DeliveryLocation = new LatLong(51.5001, -0.1239); + // order.UserId = GetUserId(); + + // Enforce existence of Pizza.SpecialId and Topping.ToppingId + // in the database - prevent the submitter from making up + // new specials and toppings + foreach (var pizza in order.Pizzas) + { + pizza.SpecialId = pizza.Special.Id; + pizza.Special = null; + + foreach (var topping in pizza.Toppings) + { + topping.ToppingId = topping.Topping.Id; + topping.Topping = null; + } + } + + _db.Orders.Attach(order); + await _db.SaveChangesAsync(); + + // In the background, send push notifications if possible + var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); + if (subscription != null) + { + _ = TrackAndSendNotificationsAsync(order, subscription); + } + + return order.OrderId; + } + + private string GetUserId() + { + return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); + } + + private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription subscription) + { + // In a realistic case, some other backend process would track + // order delivery progress and send us notifications when it + // changes. Since we don't have any such process here, fake it. + await Task.Delay(OrderWithStatus.PreparationDuration); + await SendNotificationAsync(order, subscription, "Your order has been dispatched!"); + + await Task.Delay(OrderWithStatus.DeliveryDuration); + await SendNotificationAsync(order, subscription, "Your order is now delivered. Enjoy!"); + } + + private static Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) + { + // This will be implemented later + return Task.CompletedTask; + } +} \ No newline at end of file diff --git a/save-points/00-get-started/BlazingPizza.Server/PizzaApiExtensions.cs b/save-points/00-get-started/BlazingPizza.Server/PizzaApiExtensions.cs new file mode 100644 index 00000000..bf6b7bde --- /dev/null +++ b/save-points/00-get-started/BlazingPizza.Server/PizzaApiExtensions.cs @@ -0,0 +1,60 @@ +using System.Security.Claims; +using Microsoft.AspNetCore.Authorization; +using Microsoft.EntityFrameworkCore; + +namespace BlazingPizza.Server; + +public static class PizzaApiExtensions +{ + + public static WebApplication MapPizzaApi(this WebApplication app) + { + + // Subscribe to notifications + app.MapPut("/notifications/subscribe", [Authorize] async ( + HttpContext context, + PizzaStoreContext db, + NotificationSubscription subscription) => + { + + // We're storing at most one subscription per user, so delete old ones. + // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. + var userId = GetUserId(context); + var oldSubscriptions = db.NotificationSubscriptions.Where(e => e.UserId == userId); + db.NotificationSubscriptions.RemoveRange(oldSubscriptions); + + // Store new subscription + subscription.UserId = userId; + db.NotificationSubscriptions.Attach(subscription); + + await db.SaveChangesAsync(); + return Results.Ok(subscription); + + }); + + // Specials + app.MapGet("/specials", async (PizzaStoreContext db) => + { + + var specials = await db.Specials.ToListAsync(); + return Results.Ok(specials); + + }); + + // Toppings + app.MapGet("/toppings", async (PizzaStoreContext db) => + { + var toppings = await db.Toppings.OrderBy(t => t.Name).ToListAsync(); + return Results.Ok(toppings); + }); + + return app; + + } + + private static string GetUserId(HttpContext context) + { + return context.User.FindFirstValue(ClaimTypes.NameIdentifier); + } + +} \ No newline at end of file diff --git a/save-points/00-get-started/BlazingPizza.Server/PizzaStoreContext.cs b/save-points/00-get-started/BlazingPizza.Server/PizzaStoreContext.cs index fae5acb4..921b2824 100644 --- a/save-points/00-get-started/BlazingPizza.Server/PizzaStoreContext.cs +++ b/save-points/00-get-started/BlazingPizza.Server/PizzaStoreContext.cs @@ -1,39 +1,38 @@ -using IDuende.IdentityServerEEntityFramework.Options +using Duende.IdentityServer.EntityFramework.Options; using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class PizzaStoreContext : ApiAuthorizationDbContext { - public class PizzaStoreContext : ApiAuthorizationDbContext - { - public PizzaStoreContext( - DbContextOptions options, - IOptions operationalStoreOptions) : base(options, operationalStoreOptions) - { - } + public PizzaStoreContext( + DbContextOptions options, + IOptions operationalStoreOptions) : base(options, operationalStoreOptions) + { + } - public DbSet Orders { get; set; } + public DbSet Orders { get; set; } - public DbSet Pizzas { get; set; } + public DbSet Pizzas { get; set; } - public DbSet Specials { get; set; } + public DbSet Specials { get; set; } - public DbSet Toppings { get; set; } + public DbSet Toppings { get; set; } - public DbSet NotificationSubscriptions { get; set; } + public DbSet NotificationSubscriptions { get; set; } - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - base.OnModelCreating(modelBuilder); + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); - // Configuring a many-to-many special -> topping relationship that is friendly for serialization - modelBuilder.Entity().HasKey(pst => new { pst.PizzaId, pst.ToppingId }); - modelBuilder.Entity().HasOne().WithMany(ps => ps.Toppings); - modelBuilder.Entity().HasOne(pst => pst.Topping).WithMany(); + // Configuring a many-to-many special -> topping relationship that is friendly for serialization + modelBuilder.Entity().HasKey(pst => new { pst.PizzaId, pst.ToppingId }); + modelBuilder.Entity().HasOne().WithMany(ps => ps.Toppings); + modelBuilder.Entity().HasOne(pst => pst.Topping).WithMany(); - // Inline the Lat-Long pairs in Order rather than having a FK to another table - modelBuilder.Entity().OwnsOne(o => o.DeliveryLocation); - } - } + // Inline the Lat-Long pairs in Order rather than having a FK to another table + modelBuilder.Entity().OwnsOne(o => o.DeliveryLocation); + } } \ No newline at end of file diff --git a/save-points/00-get-started/BlazingPizza.Server/PizzasController.cs b/save-points/00-get-started/BlazingPizza.Server/PizzasController.cs deleted file mode 100644 index c082552c..00000000 --- a/save-points/00-get-started/BlazingPizza.Server/PizzasController.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("pizzas")] - [ApiController] - public class PizzasController : Controller - { - private readonly PizzaStoreContext _db; - - public PizzasController(PizzaStoreContext db) - { - _db = db; - } - } -} diff --git a/save-points/00-get-started/BlazingPizza.Server/Program.cs b/save-points/00-get-started/BlazingPizza.Server/Program.cs index 40a47641..3fe5d78f 100644 --- a/save-points/00-get-started/BlazingPizza.Server/Program.cs +++ b/save-points/00-get-started/BlazingPizza.Server/Program.cs @@ -1,33 +1,66 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; +using Microsoft.AspNetCore.Authentication; +using Microsoft.EntityFrameworkCore; +using BlazingPizza.Server; -namespace BlazingPizza.Server +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddControllersWithViews() + .AddJsonOptions(options => { + options.JsonSerializerOptions.AddContext(); + }); +builder.Services.AddRazorPages(); + +builder.Services.AddDbContext(options => + options.UseSqlite("Data Source=pizza.db")); + +builder.Services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) + .AddEntityFrameworkStores(); + +builder.Services.AddIdentityServer() + .AddApiAuthorization(); + +builder.Services.AddAuthentication() + .AddIdentityServerJwt(); + +var app = builder.Build(); + +// Initialize the database +var scopeFactory = app.Services.GetRequiredService(); +using (var scope = scopeFactory.CreateScope()) +{ + var db = scope.ServiceProvider.GetRequiredService(); + if (db.Database.EnsureCreated()) + { + SeedData.Initialize(db); + } +} + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseWebAssemblyDebugging(); +} +else { - public class Program - { - public static void Main(string[] args) - { - var host = CreateHostBuilder(args).Build(); - - // Initialize the database - var scopeFactory = host.Services.GetRequiredService(); - using (var scope = scopeFactory.CreateScope()) - { - var db = scope.ServiceProvider.GetRequiredService(); - if (db.Database.EnsureCreated()) - { - SeedData.Initialize(db); - } - } - - host.Run(); - } - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); - } + app.UseExceptionHandler("/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); } + +app.UseHttpsRedirection(); +app.UseBlazorFrameworkFiles(); +app.UseStaticFiles(); + +app.UseRouting(); + +app.UseAuthentication(); +app.UseIdentityServer(); +app.UseAuthorization(); + +app.MapPizzaApi(); + +app.MapRazorPages(); +app.MapControllers(); +app.MapFallbackToFile("index.html"); + +app.Run(); \ No newline at end of file diff --git a/save-points/00-get-started/BlazingPizza.Server/SeedData.cs b/save-points/00-get-started/BlazingPizza.Server/SeedData.cs index 7c86a5b2..a1e47973 100644 --- a/save-points/00-get-started/BlazingPizza.Server/SeedData.cs +++ b/save-points/00-get-started/BlazingPizza.Server/SeedData.cs @@ -1,193 +1,192 @@ -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public static class SeedData { - public static class SeedData - { - public static void Initialize(PizzaStoreContext db) - { - var toppings = new Topping[] - { - new Topping() - { - Name = "Extra cheese", - Price = 2.50m, - }, - new Topping() - { - Name = "American bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "British bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "Canadian bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "Tea and crumpets", - Price = 5.00m - }, - new Topping() - { - Name = "Fresh-baked scones", - Price = 4.50m, - }, - new Topping() - { - Name = "Bell peppers", - Price = 1.00m, - }, - new Topping() - { - Name = "Onions", - Price = 1.00m, - }, - new Topping() - { - Name = "Mushrooms", - Price = 1.00m, - }, - new Topping() - { - Name = "Pepperoni", - Price = 1.00m, - }, - new Topping() - { - Name = "Duck sausage", - Price = 3.20m, - }, - new Topping() - { - Name = "Venison meatballs", - Price = 2.50m, - }, - new Topping() - { - Name = "Served on a silver platter", - Price = 250.99m, - }, - new Topping() - { - Name = "Lobster on top", - Price = 64.50m, - }, - new Topping() - { - Name = "Sturgeon caviar", - Price = 101.75m, - }, - new Topping() - { - Name = "Artichoke hearts", - Price = 3.40m, - }, - new Topping() - { - Name = "Fresh tomatoes", - Price = 1.50m, - }, - new Topping() - { - Name = "Basil", - Price = 1.50m, - }, - new Topping() - { - Name = "Steak (medium-rare)", - Price = 8.50m, - }, - new Topping() - { - Name = "Blazing hot peppers", - Price = 4.20m, - }, - new Topping() - { - Name = "Buffalo chicken", - Price = 5.00m, - }, - new Topping() - { - Name = "Blue cheese", - Price = 2.50m, - }, - }; + public static void Initialize(PizzaStoreContext db) + { + var toppings = new Topping[] + { + new Topping() + { + Name = "Extra cheese", + Price = 2.50m, + }, + new Topping() + { + Name = "American bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "British bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "Canadian bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "Tea and crumpets", + Price = 5.00m + }, + new Topping() + { + Name = "Fresh-baked scones", + Price = 4.50m, + }, + new Topping() + { + Name = "Bell peppers", + Price = 1.00m, + }, + new Topping() + { + Name = "Onions", + Price = 1.00m, + }, + new Topping() + { + Name = "Mushrooms", + Price = 1.00m, + }, + new Topping() + { + Name = "Pepperoni", + Price = 1.00m, + }, + new Topping() + { + Name = "Duck sausage", + Price = 3.20m, + }, + new Topping() + { + Name = "Venison meatballs", + Price = 2.50m, + }, + new Topping() + { + Name = "Served on a silver platter", + Price = 250.99m, + }, + new Topping() + { + Name = "Lobster on top", + Price = 64.50m, + }, + new Topping() + { + Name = "Sturgeon caviar", + Price = 101.75m, + }, + new Topping() + { + Name = "Artichoke hearts", + Price = 3.40m, + }, + new Topping() + { + Name = "Fresh tomatoes", + Price = 1.50m, + }, + new Topping() + { + Name = "Basil", + Price = 1.50m, + }, + new Topping() + { + Name = "Steak (medium-rare)", + Price = 8.50m, + }, + new Topping() + { + Name = "Blazing hot peppers", + Price = 4.20m, + }, + new Topping() + { + Name = "Buffalo chicken", + Price = 5.00m, + }, + new Topping() + { + Name = "Blue cheese", + Price = 2.50m, + }, + }; - var specials = new PizzaSpecial[] - { - new PizzaSpecial() - { - Name = "Basic Cheese Pizza", - Description = "It's cheesy and delicious. Why wouldn't you want one?", - BasePrice = 9.99m, - ImageUrl = "img/pizzas/cheese.jpg", - }, - new PizzaSpecial() - { - Id = 2, - Name = "The Baconatorizor", - Description = "It has EVERY kind of bacon", - BasePrice = 11.99m, - ImageUrl = "img/pizzas/bacon.jpg", - }, - new PizzaSpecial() - { - Id = 3, - Name = "Classic pepperoni", - Description = "It's the pizza you grew up with, but Blazing hot!", - BasePrice = 10.50m, - ImageUrl = "img/pizzas/pepperoni.jpg", - }, - new PizzaSpecial() - { - Id = 4, - Name = "Buffalo chicken", - Description = "Spicy chicken, hot sauce and bleu cheese, guaranteed to warm you up", - BasePrice = 12.75m, - ImageUrl = "img/pizzas/meaty.jpg", - }, - new PizzaSpecial() - { - Id = 5, - Name = "Mushroom Lovers", - Description = "It has mushrooms. Isn't that obvious?", - BasePrice = 11.00m, - ImageUrl = "img/pizzas/mushroom.jpg", - }, - new PizzaSpecial() - { - Id = 6, - Name = "The Brit", - Description = "When in London...", - BasePrice = 10.25m, - ImageUrl = "img/pizzas/brit.jpg", - }, - new PizzaSpecial() - { - Id = 7, - Name = "Veggie Delight", - Description = "It's like salad, but on a pizza", - BasePrice = 11.50m, - ImageUrl = "img/pizzas/salad.jpg", - }, - new PizzaSpecial() - { - Id = 8, - Name = "Margherita", - Description = "Traditional Italian pizza with tomatoes and basil", - BasePrice = 9.99m, - ImageUrl = "img/pizzas/margherita.jpg", - }, - }; + var specials = new PizzaSpecial[] + { + new PizzaSpecial() + { + Name = "Basic Cheese Pizza", + Description = "It's cheesy and delicious. Why wouldn't you want one?", + BasePrice = 9.99m, + ImageUrl = "img/pizzas/cheese.jpg", + }, + new PizzaSpecial() + { + Id = 2, + Name = "The Baconatorizor", + Description = "It has EVERY kind of bacon", + BasePrice = 11.99m, + ImageUrl = "img/pizzas/bacon.jpg", + }, + new PizzaSpecial() + { + Id = 3, + Name = "Classic pepperoni", + Description = "It's the pizza you grew up with, but Blazing hot!", + BasePrice = 10.50m, + ImageUrl = "img/pizzas/pepperoni.jpg", + }, + new PizzaSpecial() + { + Id = 4, + Name = "Buffalo chicken", + Description = "Spicy chicken, hot sauce and bleu cheese, guaranteed to warm you up", + BasePrice = 12.75m, + ImageUrl = "img/pizzas/meaty.jpg", + }, + new PizzaSpecial() + { + Id = 5, + Name = "Mushroom Lovers", + Description = "It has mushrooms. Isn't that obvious?", + BasePrice = 11.00m, + ImageUrl = "img/pizzas/mushroom.jpg", + }, + new PizzaSpecial() + { + Id = 6, + Name = "The Brit", + Description = "When in London...", + BasePrice = 10.25m, + ImageUrl = "img/pizzas/brit.jpg", + }, + new PizzaSpecial() + { + Id = 7, + Name = "Veggie Delight", + Description = "It's like salad, but on a pizza", + BasePrice = 11.50m, + ImageUrl = "img/pizzas/salad.jpg", + }, + new PizzaSpecial() + { + Id = 8, + Name = "Margherita", + Description = "Traditional Italian pizza with tomatoes and basil", + BasePrice = 9.99m, + ImageUrl = "img/pizzas/margherita.jpg", + }, + }; - db.Toppings.AddRange(toppings); - db.Specials.AddRange(specials); - db.SaveChanges(); - } - } -} + db.Toppings.AddRange(toppings); + db.Specials.AddRange(specials); + db.SaveChanges(); + } +} \ No newline at end of file diff --git a/save-points/00-get-started/BlazingPizza.Server/SpecialsController.cs b/save-points/00-get-started/BlazingPizza.Server/SpecialsController.cs deleted file mode 100644 index a176844c..00000000 --- a/save-points/00-get-started/BlazingPizza.Server/SpecialsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("specials")] - [ApiController] - public class SpecialsController : Controller - { - private readonly PizzaStoreContext _db; - - public SpecialsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetSpecials() - { - return (await _db.Specials.ToListAsync()).OrderByDescending(s => s.BasePrice).ToList(); - } - } -} diff --git a/save-points/00-get-started/BlazingPizza.Server/Startup.cs b/save-points/00-get-started/BlazingPizza.Server/Startup.cs deleted file mode 100644 index ed3fca06..00000000 --- a/save-points/00-get-started/BlazingPizza.Server/Startup.cs +++ /dev/null @@ -1,70 +0,0 @@ -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace BlazingPizza.Server -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - public void ConfigureServices(IServiceCollection services) - { - services.AddControllersWithViews(); - services.AddRazorPages(); - - services.AddDbContext(options => - options.UseSqlite("Data Source=pizza.db")); - - services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) - .AddEntityFrameworkStores(); - - services.AddIdentityServer() - .AddApiAuthorization(); - - services.AddAuthentication() - .AddIdentityServerJwt(); - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - app.UseWebAssemblyDebugging(); - } - else - { - app.UseExceptionHandler("/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); - } - - app.UseHttpsRedirection(); - app.UseBlazorFrameworkFiles(); - app.UseStaticFiles(); - - app.UseRouting(); - - app.UseAuthentication(); - app.UseIdentityServer(); - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - endpoints.MapRazorPages(); - endpoints.MapFallbackToFile("index.html"); - }); - } - } -} \ No newline at end of file diff --git a/save-points/00-get-started/BlazingPizza.Server/ToppingsController.cs b/save-points/00-get-started/BlazingPizza.Server/ToppingsController.cs deleted file mode 100644 index 6a677639..00000000 --- a/save-points/00-get-started/BlazingPizza.Server/ToppingsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("toppings")] - [ApiController] - public class ToppingsController : Controller - { - private readonly PizzaStoreContext _db; - - public ToppingsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetToppings() - { - return await _db.Toppings.OrderBy(t => t.Name).ToListAsync(); - } - } -} diff --git a/src/BlazingPizza.Client/BlazingPizza.Client.csproj b/src/BlazingPizza.Client/BlazingPizza.Client.csproj index 168bb22a..44802d79 100644 --- a/src/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/src/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -2,6 +2,7 @@ $(TargetFrameworkVersion) + true diff --git a/src/BlazingPizza.Client/JSRuntimeExtensions.cs b/src/BlazingPizza.Client/JSRuntimeExtensions.cs index 89da520c..cc242348 100644 --- a/src/BlazingPizza.Client/JSRuntimeExtensions.cs +++ b/src/BlazingPizza.Client/JSRuntimeExtensions.cs @@ -1,13 +1,11 @@ using Microsoft.JSInterop; -using System.Threading.Tasks; -namespace BlazingPizza.Client +namespace BlazingPizza.Client; + +public static class JSRuntimeExtensions { - public static class JSRuntimeExtensions - { - public static ValueTask Confirm(this IJSRuntime jsRuntime, string message) - { - return jsRuntime.InvokeAsync("confirm", message); - } - } + public static ValueTask Confirm(this IJSRuntime jsRuntime, string message) + { + return jsRuntime.InvokeAsync("confirm", message); + } } diff --git a/src/BlazingPizza.Client/OrderState.cs b/src/BlazingPizza.Client/OrderState.cs index 5265ae39..4f47979d 100644 --- a/src/BlazingPizza.Client/OrderState.cs +++ b/src/BlazingPizza.Client/OrderState.cs @@ -1,55 +1,52 @@ -using System.Collections.Generic; +namespace BlazingPizza.Client; -namespace BlazingPizza.Client +public class OrderState { - public class OrderState - { - public bool ShowingConfigureDialog { get; private set; } - - public Pizza ConfiguringPizza { get; private set; } - - public Order Order { get; private set; } = new Order(); - - public void ShowConfigurePizzaDialog(PizzaSpecial special) - { - ConfiguringPizza = new Pizza() - { - Special = special, - SpecialId = special.Id, - Size = Pizza.DefaultSize, - Toppings = new List(), - }; - - ShowingConfigureDialog = true; - } - - public void CancelConfigurePizzaDialog() - { - ConfiguringPizza = null; - ShowingConfigureDialog = false; - } - - public void ConfirmConfigurePizzaDialog() - { - Order.Pizzas.Add(ConfiguringPizza); - ConfiguringPizza = null; - - ShowingConfigureDialog = false; - } - - public void RemoveConfiguredPizza(Pizza pizza) - { - Order.Pizzas.Remove(pizza); - } - - public void ResetOrder() - { - Order = new Order(); - } - - public void ReplaceOrder(Order order) - { - Order = order; - } - } + public bool ShowingConfigureDialog { get; private set; } + + public Pizza ConfiguringPizza { get; private set; } + + public Order Order { get; private set; } = new Order(); + + public void ShowConfigurePizzaDialog(PizzaSpecial special) + { + ConfiguringPizza = new Pizza() + { + Special = special, + SpecialId = special.Id, + Size = Pizza.DefaultSize, + Toppings = new List(), + }; + + ShowingConfigureDialog = true; + } + + public void CancelConfigurePizzaDialog() + { + ConfiguringPizza = null; + ShowingConfigureDialog = false; + } + + public void ConfirmConfigurePizzaDialog() + { + Order.Pizzas.Add(ConfiguringPizza); + ConfiguringPizza = null; + + ShowingConfigureDialog = false; + } + + public void RemoveConfiguredPizza(Pizza pizza) + { + Order.Pizzas.Remove(pizza); + } + + public void ResetOrder() + { + Order = new Order(); + } + + public void ReplaceOrder(Order order) + { + Order = order; + } } diff --git a/src/BlazingPizza.Client/OrdersClient.cs b/src/BlazingPizza.Client/OrdersClient.cs index 01c63572..e63bd045 100644 --- a/src/BlazingPizza.Client/OrdersClient.cs +++ b/src/BlazingPizza.Client/OrdersClient.cs @@ -1,41 +1,36 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Net.Http.Json; -using System.Threading.Tasks; - -namespace BlazingPizza.Client +using System.Net.Http.Json; +using System.Text.Json; + +namespace BlazingPizza.Client; + +public class OrdersClient { - public class OrdersClient - { - private readonly HttpClient httpClient; + private readonly HttpClient httpClient; - public OrdersClient(HttpClient httpClient) - { - this.httpClient = httpClient; - } + public OrdersClient(HttpClient httpClient) + { + this.httpClient = httpClient; + } - public async Task> GetOrders() => - await httpClient.GetFromJsonAsync>("orders"); + public async Task> GetOrders() => + await httpClient.GetFromJsonAsync("orders", OrderContext.Default.ListOrderWithStatus); - public async Task GetOrder(int orderId) => - await httpClient.GetFromJsonAsync($"orders/{orderId}"); + public async Task GetOrder(int orderId) => + await httpClient.GetFromJsonAsync($"orders/{orderId}", OrderContext.Default.OrderWithStatus); - public async Task PlaceOrder(Order order) - { - var response = await httpClient.PostAsJsonAsync("orders", order); - response.EnsureSuccessStatusCode(); - var orderId = await response.Content.ReadFromJsonAsync(); - return orderId; - } + public async Task PlaceOrder(Order order) + { + var response = await httpClient.PostAsJsonAsync("orders", order, OrderContext.Default.Order); + response.EnsureSuccessStatusCode(); + var orderId = await response.Content.ReadFromJsonAsync(); + return orderId; + } - public async Task SubscribeToNotifications(NotificationSubscription subscription) - { - var response = await httpClient.PutAsJsonAsync("notifications/subscribe", subscription); - response.EnsureSuccessStatusCode(); - } - } + public async Task SubscribeToNotifications(NotificationSubscription subscription) + { + var response = await httpClient.PutAsJsonAsync("notifications/subscribe", subscription); + response.EnsureSuccessStatusCode(); + } } diff --git a/src/BlazingPizza.Client/Pages/Index.razor b/src/BlazingPizza.Client/Pages/Index.razor index ca5ac084..f8ff79df 100644 --- a/src/BlazingPizza.Client/Pages/Index.razor +++ b/src/BlazingPizza.Client/Pages/Index.razor @@ -61,7 +61,7 @@ protected override async Task OnInitializedAsync() { - specials = await HttpClient.GetFromJsonAsync>("specials"); + specials = await HttpClient.GetFromJsonAsync("specials", BlazingPizza.OrderContext.Default.ListPizzaSpecial); } async Task RemovePizza(Pizza configuredPizza) diff --git a/src/BlazingPizza.Client/PizzaAuthenticationState.cs b/src/BlazingPizza.Client/PizzaAuthenticationState.cs index 3f295928..f5bfef65 100644 --- a/src/BlazingPizza.Client/PizzaAuthenticationState.cs +++ b/src/BlazingPizza.Client/PizzaAuthenticationState.cs @@ -1,9 +1,8 @@ using Microsoft.AspNetCore.Components.WebAssembly.Authentication; -namespace BlazingPizza.Client +namespace BlazingPizza.Client; + +public class PizzaAuthenticationState : RemoteAuthenticationState { - public class PizzaAuthenticationState : RemoteAuthenticationState - { - public Order Order { get; set; } - } + public Order Order { get; set; } } diff --git a/src/BlazingPizza.Client/Program.cs b/src/BlazingPizza.Client/Program.cs index afeee128..41eedccb 100644 --- a/src/BlazingPizza.Client/Program.cs +++ b/src/BlazingPizza.Client/Program.cs @@ -1,31 +1,20 @@ using Microsoft.AspNetCore.Components.WebAssembly.Authentication; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; using Microsoft.Extensions.DependencyInjection; -using System; -using System.Net.Http; -using System.Threading.Tasks; +using BlazingPizza.Client; -namespace BlazingPizza.Client -{ - public class Program - { - public static async Task Main(string[] args) - { - var builder = WebAssemblyHostBuilder.CreateDefault(args); - builder.RootComponents.Add("#app"); +var builder = WebAssemblyHostBuilder.CreateDefault(args); +builder.RootComponents.Add("#app"); - builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); - builder.Services.AddHttpClient(client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)) - .AddHttpMessageHandler(); - builder.Services.AddScoped(); +builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); +builder.Services.AddHttpClient(client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)) + .AddHttpMessageHandler(); +builder.Services.AddScoped(); - // Add auth services - builder.Services.AddApiAuthorization(options => - { - options.AuthenticationPaths.LogOutSucceededPath = ""; - }); +// Add auth services +builder.Services.AddApiAuthorization(options => +{ + options.AuthenticationPaths.LogOutSucceededPath = ""; +}); - await builder.Build().RunAsync(); - } - } -} +await builder.Build().RunAsync(); diff --git a/src/BlazingPizza.Client/Shared/ConfigurePizzaDialog.razor b/src/BlazingPizza.Client/Shared/ConfigurePizzaDialog.razor index 67096b01..f10c7990 100644 --- a/src/BlazingPizza.Client/Shared/ConfigurePizzaDialog.razor +++ b/src/BlazingPizza.Client/Shared/ConfigurePizzaDialog.razor @@ -65,7 +65,7 @@ protected async override Task OnInitializedAsync() { - toppings = await HttpClient.GetFromJsonAsync>("toppings"); + toppings = await HttpClient.GetFromJsonAsync("toppings", BlazingPizza.OrderContext.Default.ListTopping); } void ToppingSelected(ChangeEventArgs e) diff --git a/src/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/src/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 61ebf623..cb996b1b 100644 --- a/src/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/src/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -2,6 +2,7 @@ $(TargetFrameworkVersion) + true diff --git a/src/BlazingPizza.ComponentsLibrary/LocalStorage.cs b/src/BlazingPizza.ComponentsLibrary/LocalStorage.cs index f36b098e..bb84f13c 100644 --- a/src/BlazingPizza.ComponentsLibrary/LocalStorage.cs +++ b/src/BlazingPizza.ComponentsLibrary/LocalStorage.cs @@ -1,17 +1,15 @@ using Microsoft.JSInterop; -using System.Threading.Tasks; -namespace BlazingPizza.ComponentsLibrary +namespace BlazingPizza.ComponentsLibrary; + +public static class LocalStorage { - public static class LocalStorage - { - public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) - => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); + public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) + => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); - public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object value) - => jsRuntime.InvokeVoidAsync("blazorLocalStorage.set", key, value); + public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object value) + => jsRuntime.InvokeVoidAsync("blazorLocalStorage.set", key, value); - public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key) - => jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key); - } -} + public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key) + => jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key); +} \ No newline at end of file diff --git a/src/BlazingPizza.ComponentsLibrary/Map/Marker.cs b/src/BlazingPizza.ComponentsLibrary/Map/Marker.cs index 63006067..a8e78f2a 100644 --- a/src/BlazingPizza.ComponentsLibrary/Map/Marker.cs +++ b/src/BlazingPizza.ComponentsLibrary/Map/Marker.cs @@ -1,13 +1,12 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Marker { - public class Marker - { - public string Description { get; set; } + public string Description { get; set; } - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } + public double Y { get; set; } - public bool ShowPopup { get; set; } - } + public bool ShowPopup { get; set; } } diff --git a/src/BlazingPizza.ComponentsLibrary/Map/Point.cs b/src/BlazingPizza.ComponentsLibrary/Map/Point.cs index 03841826..349046d4 100644 --- a/src/BlazingPizza.ComponentsLibrary/Map/Point.cs +++ b/src/BlazingPizza.ComponentsLibrary/Map/Point.cs @@ -1,9 +1,8 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Point { - public class Point - { - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } - } -} + public double Y { get; set; } +} \ No newline at end of file diff --git a/src/BlazingPizza.Server/BlazingPizza.Server.csproj b/src/BlazingPizza.Server/BlazingPizza.Server.csproj index e1e7aaef..abd2317b 100644 --- a/src/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/src/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -2,6 +2,7 @@ $(TargetFrameworkVersion) + true diff --git a/src/BlazingPizza.Server/Models/AddressEntityType.cs b/src/BlazingPizza.Server/Models/AddressEntityType.cs new file mode 100644 index 00000000..82db81b6 --- /dev/null +++ b/src/BlazingPizza.Server/Models/AddressEntityType.cs @@ -0,0 +1,92 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class AddressEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Address", + typeof(Address), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Address).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var city = runtimeEntityType.AddProperty( + "City", + typeof(string), + propertyInfo: typeof(Address).GetProperty("City", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var line1 = runtimeEntityType.AddProperty( + "Line1", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line1", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var line2 = runtimeEntityType.AddProperty( + "Line2", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line2", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var postalCode = runtimeEntityType.AddProperty( + "PostalCode", + typeof(string), + propertyInfo: typeof(Address).GetProperty("PostalCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var region = runtimeEntityType.AddProperty( + "Region", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Region", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Address"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/src/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs b/src/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs new file mode 100644 index 00000000..1dd4563b --- /dev/null +++ b/src/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs @@ -0,0 +1,114 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class DeviceFlowCodesEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.DeviceFlowCodes", + typeof(DeviceFlowCodes), + baseEntityType); + + var userCode = runtimeEntityType.AddProperty( + "UserCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("UserCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var deviceCode = runtimeEntityType.AddProperty( + "DeviceCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("DeviceCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var key = runtimeEntityType.AddKey( + new[] { userCode }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deviceCode }, + unique: true); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "DeviceCodes"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/src/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs b/src/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs new file mode 100644 index 00000000..8946b261 --- /dev/null +++ b/src/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRoleClaim", + typeof(IdentityRoleClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoleClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/src/BlazingPizza.Server/Models/IdentityRoleEntityType.cs b/src/BlazingPizza.Server/Models/IdentityRoleEntityType.cs new file mode 100644 index 00000000..2f1fec2b --- /dev/null +++ b/src/BlazingPizza.Server/Models/IdentityRoleEntityType.cs @@ -0,0 +1,78 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRole", + typeof(IdentityRole), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedName = runtimeEntityType.AddProperty( + "NormalizedName", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("NormalizedName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedName }, + unique: true); + index.AddAnnotation("Relational:Name", "RoleNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/src/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs b/src/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs new file mode 100644 index 00000000..55418a1e --- /dev/null +++ b/src/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserClaim", + typeof(IdentityUserClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityUserClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/src/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs b/src/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs new file mode 100644 index 00000000..3ca029bd --- /dev/null +++ b/src/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserLoginstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserLogin", + typeof(IdentityUserLogin), + baseEntityType); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerKey = runtimeEntityType.AddProperty( + "ProviderKey", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderKey", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerDisplayName = runtimeEntityType.AddProperty( + "ProviderDisplayName", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderDisplayName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { loginProvider, providerKey }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserLogins"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/src/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs b/src/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs new file mode 100644 index 00000000..70078d7a --- /dev/null +++ b/src/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs @@ -0,0 +1,82 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserRolestringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserRole", + typeof(IdentityUserRole), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { userId, roleId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/src/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs b/src/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs new file mode 100644 index 00000000..93ba6d31 --- /dev/null +++ b/src/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs @@ -0,0 +1,84 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserTokenstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserToken", + typeof(IdentityUserToken), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var value = runtimeEntityType.AddProperty( + "Value", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Value", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { userId, loginProvider, name }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserTokens"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/src/BlazingPizza.Server/Models/KeyEntityType.cs b/src/BlazingPizza.Server/Models/KeyEntityType.cs new file mode 100644 index 00000000..f6c6b4c7 --- /dev/null +++ b/src/BlazingPizza.Server/Models/KeyEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class KeyEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.Key", + typeof(Key), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var algorithm = runtimeEntityType.AddProperty( + "Algorithm", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Algorithm", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var created = runtimeEntityType.AddProperty( + "Created", + typeof(DateTime), + propertyInfo: typeof(Key).GetProperty("Created", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var dataProtected = runtimeEntityType.AddProperty( + "DataProtected", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("DataProtected", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var isX509Certificate = runtimeEntityType.AddProperty( + "IsX509Certificate", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("IsX509Certificate", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var use = runtimeEntityType.AddProperty( + "Use", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Use", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var version = runtimeEntityType.AddProperty( + "Version", + typeof(int), + propertyInfo: typeof(Key).GetProperty("Version", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { use }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Keys"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/src/BlazingPizza.Server/Models/LatLongEntityType.cs b/src/BlazingPizza.Server/Models/LatLongEntityType.cs new file mode 100644 index 00000000..3fd254bd --- /dev/null +++ b/src/BlazingPizza.Server/Models/LatLongEntityType.cs @@ -0,0 +1,80 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class LatLongEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.LatLong", + typeof(LatLong), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var latitude = runtimeEntityType.AddProperty( + "Latitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Latitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var longitude = runtimeEntityType.AddProperty( + "Longitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Longitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + unique: true, + required: true, + ownership: true); + + var deliveryLocation = principalEntityType.AddNavigation("DeliveryLocation", + runtimeForeignKey, + onDependent: false, + typeof(LatLong), + propertyInfo: typeof(Order).GetProperty("DeliveryLocation", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + eagerLoaded: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/src/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs b/src/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs new file mode 100644 index 00000000..db236e4c --- /dev/null +++ b/src/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs @@ -0,0 +1,77 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class NotificationSubscriptionEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.NotificationSubscription", + typeof(NotificationSubscription), + baseEntityType); + + var notificationSubscriptionId = runtimeEntityType.AddProperty( + "NotificationSubscriptionId", + typeof(int), + propertyInfo: typeof(NotificationSubscription).GetProperty("NotificationSubscriptionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var auth = runtimeEntityType.AddProperty( + "Auth", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Auth", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var p256dh = runtimeEntityType.AddProperty( + "P256dh", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("P256dh", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var url = runtimeEntityType.AddProperty( + "Url", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Url", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { notificationSubscriptionId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "NotificationSubscriptions"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/src/BlazingPizza.Server/Models/OrderEntityType.cs b/src/BlazingPizza.Server/Models/OrderEntityType.cs new file mode 100644 index 00000000..9d9ec6fd --- /dev/null +++ b/src/BlazingPizza.Server/Models/OrderEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class OrderEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Order", + typeof(Order), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Order).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var createdTime = runtimeEntityType.AddProperty( + "CreatedTime", + typeof(DateTime), + propertyInfo: typeof(Order).GetProperty("CreatedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var deliveryAddressId = runtimeEntityType.AddProperty( + "DeliveryAddressId", + typeof(int?), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(Order).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deliveryAddressId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("DeliveryAddressId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType); + + var deliveryAddress = declaringEntityType.AddNavigation("DeliveryAddress", + runtimeForeignKey, + onDependent: true, + typeof(Address), + propertyInfo: typeof(Order).GetProperty("DeliveryAddress", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/src/BlazingPizza.Server/Models/PersistedGrantEntityType.cs b/src/BlazingPizza.Server/Models/PersistedGrantEntityType.cs new file mode 100644 index 00000000..842d53a5 --- /dev/null +++ b/src/BlazingPizza.Server/Models/PersistedGrantEntityType.cs @@ -0,0 +1,127 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PersistedGrantEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.PersistedGrant", + typeof(PersistedGrant), + baseEntityType); + + var key = runtimeEntityType.AddProperty( + "Key", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Key", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var consumedTime = runtimeEntityType.AddProperty( + "ConsumedTime", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("ConsumedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(PersistedGrant).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var type = runtimeEntityType.AddProperty( + "Type", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Type", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var key0 = runtimeEntityType.AddKey( + new[] { key }); + runtimeEntityType.SetPrimaryKey(key0); + + var index = runtimeEntityType.AddIndex( + new[] { consumedTime }); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + var index1 = runtimeEntityType.AddIndex( + new[] { subjectId, clientId, type }); + + var index2 = runtimeEntityType.AddIndex( + new[] { subjectId, sessionId, type }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PersistedGrants"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/src/BlazingPizza.Server/Models/PizzaEntityType.cs b/src/BlazingPizza.Server/Models/PizzaEntityType.cs new file mode 100644 index 00000000..3a124e63 --- /dev/null +++ b/src/BlazingPizza.Server/Models/PizzaEntityType.cs @@ -0,0 +1,111 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Pizza", + typeof(Pizza), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var size = runtimeEntityType.AddProperty( + "Size", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Size", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var specialId = runtimeEntityType.AddProperty( + "SpecialId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("SpecialId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { orderId }); + + var index0 = runtimeEntityType.AddIndex( + new[] { specialId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var pizzas = principalEntityType.AddNavigation("Pizzas", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Order).GetProperty("Pizzas", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("SpecialId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var special = declaringEntityType.AddNavigation("Special", + runtimeForeignKey, + onDependent: true, + typeof(PizzaSpecial), + propertyInfo: typeof(Pizza).GetProperty("Special", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Pizzas"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/src/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs b/src/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs new file mode 100644 index 00000000..e86b0f50 --- /dev/null +++ b/src/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs @@ -0,0 +1,76 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaSpecialEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaSpecial", + typeof(PizzaSpecial), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(PizzaSpecial).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var basePrice = runtimeEntityType.AddProperty( + "BasePrice", + typeof(decimal), + propertyInfo: typeof(PizzaSpecial).GetProperty("BasePrice", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var imageUrl = runtimeEntityType.AddProperty( + "ImageUrl", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("ImageUrl", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Specials"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/src/BlazingPizza.Server/Models/PizzaStoreContextModel.cs b/src/BlazingPizza.Server/Models/PizzaStoreContextModel.cs new file mode 100644 index 00000000..8b516a68 --- /dev/null +++ b/src/BlazingPizza.Server/Models/PizzaStoreContextModel.cs @@ -0,0 +1,28 @@ +// +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + [DbContext(typeof(PizzaStoreContext))] + public partial class PizzaStoreContextModel : RuntimeModel + { + static PizzaStoreContextModel() + { + var model = new PizzaStoreContextModel(); + model.Initialize(); + model.Customize(); + _instance = model; + } + + private static PizzaStoreContextModel _instance; + public static IModel Instance => _instance; + + partial void Initialize(); + + partial void Customize(); + } +} diff --git a/src/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs b/src/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs new file mode 100644 index 00000000..d46f50f4 --- /dev/null +++ b/src/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs @@ -0,0 +1,69 @@ +// +using System; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + public partial class PizzaStoreContextModel + { + partial void Initialize() + { + var address = AddressEntityType.Create(this); + var latLong = LatLongEntityType.Create(this); + var notificationSubscription = NotificationSubscriptionEntityType.Create(this); + var order = OrderEntityType.Create(this); + var pizza = PizzaEntityType.Create(this); + var pizzaSpecial = PizzaSpecialEntityType.Create(this); + var pizzaTopping = PizzaToppingEntityType.Create(this); + var pizzaStoreUser = PizzaStoreUserEntityType.Create(this); + var topping = ToppingEntityType.Create(this); + var deviceFlowCodes = DeviceFlowCodesEntityType.Create(this); + var key = KeyEntityType.Create(this); + var persistedGrant = PersistedGrantEntityType.Create(this); + var identityRole = IdentityRoleEntityType.Create(this); + var identityRoleClaimstring = IdentityRoleClaimstringEntityType.Create(this); + var identityUserClaimstring = IdentityUserClaimstringEntityType.Create(this); + var identityUserLoginstring = IdentityUserLoginstringEntityType.Create(this); + var identityUserRolestring = IdentityUserRolestringEntityType.Create(this); + var identityUserTokenstring = IdentityUserTokenstringEntityType.Create(this); + + LatLongEntityType.CreateForeignKey1(latLong, order); + OrderEntityType.CreateForeignKey1(order, address); + PizzaEntityType.CreateForeignKey1(pizza, order); + PizzaEntityType.CreateForeignKey2(pizza, pizzaSpecial); + PizzaToppingEntityType.CreateForeignKey1(pizzaTopping, pizza); + PizzaToppingEntityType.CreateForeignKey2(pizzaTopping, topping); + IdentityRoleClaimstringEntityType.CreateForeignKey1(identityRoleClaimstring, identityRole); + IdentityUserClaimstringEntityType.CreateForeignKey1(identityUserClaimstring, pizzaStoreUser); + IdentityUserLoginstringEntityType.CreateForeignKey1(identityUserLoginstring, pizzaStoreUser); + IdentityUserRolestringEntityType.CreateForeignKey1(identityUserRolestring, identityRole); + IdentityUserRolestringEntityType.CreateForeignKey2(identityUserRolestring, pizzaStoreUser); + IdentityUserTokenstringEntityType.CreateForeignKey1(identityUserTokenstring, pizzaStoreUser); + + AddressEntityType.CreateAnnotations(address); + LatLongEntityType.CreateAnnotations(latLong); + NotificationSubscriptionEntityType.CreateAnnotations(notificationSubscription); + OrderEntityType.CreateAnnotations(order); + PizzaEntityType.CreateAnnotations(pizza); + PizzaSpecialEntityType.CreateAnnotations(pizzaSpecial); + PizzaToppingEntityType.CreateAnnotations(pizzaTopping); + PizzaStoreUserEntityType.CreateAnnotations(pizzaStoreUser); + ToppingEntityType.CreateAnnotations(topping); + DeviceFlowCodesEntityType.CreateAnnotations(deviceFlowCodes); + KeyEntityType.CreateAnnotations(key); + PersistedGrantEntityType.CreateAnnotations(persistedGrant); + IdentityRoleEntityType.CreateAnnotations(identityRole); + IdentityRoleClaimstringEntityType.CreateAnnotations(identityRoleClaimstring); + IdentityUserClaimstringEntityType.CreateAnnotations(identityUserClaimstring); + IdentityUserLoginstringEntityType.CreateAnnotations(identityUserLoginstring); + IdentityUserRolestringEntityType.CreateAnnotations(identityUserRolestring); + IdentityUserTokenstringEntityType.CreateAnnotations(identityUserTokenstring); + + AddAnnotation("ProductVersion", "6.0.0"); + } + } +} diff --git a/src/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs b/src/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs new file mode 100644 index 00000000..18b2d96d --- /dev/null +++ b/src/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs @@ -0,0 +1,156 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaStoreUserEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Server.PizzaStoreUser", + typeof(PizzaStoreUser), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var accessFailedCount = runtimeEntityType.AddProperty( + "AccessFailedCount", + typeof(int), + propertyInfo: typeof(IdentityUser).GetProperty("AccessFailedCount", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var email = runtimeEntityType.AddProperty( + "Email", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Email", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var emailConfirmed = runtimeEntityType.AddProperty( + "EmailConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("EmailConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnabled = runtimeEntityType.AddProperty( + "LockoutEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnd = runtimeEntityType.AddProperty( + "LockoutEnd", + typeof(DateTimeOffset?), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnd", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var normalizedEmail = runtimeEntityType.AddProperty( + "NormalizedEmail", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedEmail", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedUserName = runtimeEntityType.AddProperty( + "NormalizedUserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedUserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var passwordHash = runtimeEntityType.AddProperty( + "PasswordHash", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PasswordHash", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumber = runtimeEntityType.AddProperty( + "PhoneNumber", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumber", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumberConfirmed = runtimeEntityType.AddProperty( + "PhoneNumberConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumberConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var securityStamp = runtimeEntityType.AddProperty( + "SecurityStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("SecurityStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var twoFactorEnabled = runtimeEntityType.AddProperty( + "TwoFactorEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("TwoFactorEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var userName = runtimeEntityType.AddProperty( + "UserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("UserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedEmail }); + index.AddAnnotation("Relational:Name", "EmailIndex"); + + var index0 = runtimeEntityType.AddIndex( + new[] { normalizedUserName }, + unique: true); + index0.AddAnnotation("Relational:Name", "UserNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUsers"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/src/BlazingPizza.Server/Models/PizzaToppingEntityType.cs b/src/BlazingPizza.Server/Models/PizzaToppingEntityType.cs new file mode 100644 index 00000000..b97d2a24 --- /dev/null +++ b/src/BlazingPizza.Server/Models/PizzaToppingEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaTopping", + typeof(PizzaTopping), + baseEntityType); + + var pizzaId = runtimeEntityType.AddProperty( + "PizzaId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("PizzaId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var toppingId = runtimeEntityType.AddProperty( + "ToppingId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("ToppingId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { pizzaId, toppingId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { toppingId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("PizzaId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var toppings = principalEntityType.AddNavigation("Toppings", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Pizza).GetProperty("Toppings", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("ToppingId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var topping = declaringEntityType.AddNavigation("Topping", + runtimeForeignKey, + onDependent: true, + typeof(Topping), + propertyInfo: typeof(PizzaTopping).GetProperty("Topping", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PizzaTopping"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/src/BlazingPizza.Server/Models/ToppingEntityType.cs b/src/BlazingPizza.Server/Models/ToppingEntityType.cs new file mode 100644 index 00000000..9295f9bf --- /dev/null +++ b/src/BlazingPizza.Server/Models/ToppingEntityType.cs @@ -0,0 +1,62 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class ToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Topping", + typeof(Topping), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Topping).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Topping).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var price = runtimeEntityType.AddProperty( + "Price", + typeof(decimal), + propertyInfo: typeof(Topping).GetProperty("Price", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Toppings"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/src/BlazingPizza.Server/NotificationsController.cs b/src/BlazingPizza.Server/NotificationsController.cs deleted file mode 100644 index bb3b96ff..00000000 --- a/src/BlazingPizza.Server/NotificationsController.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("notifications")] - [ApiController] - [Authorize] - public class NotificationsController : Controller - { - private readonly PizzaStoreContext _db; - - public NotificationsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpPut("subscribe")] - public async Task Subscribe(NotificationSubscription subscription) - { - // We're storing at most one subscription per user, so delete old ones. - // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. - var userId = GetUserId(); - var oldSubscriptions = _db.NotificationSubscriptions.Where(e => e.UserId == userId); - _db.NotificationSubscriptions.RemoveRange(oldSubscriptions); - - // Store new subscription - subscription.UserId = userId; - _db.NotificationSubscriptions.Attach(subscription); - - await _db.SaveChangesAsync(); - return subscription; - } - - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } - } -} diff --git a/src/BlazingPizza.Server/OidcConfigurationController.cs b/src/BlazingPizza.Server/OidcConfigurationController.cs index c074debf..dc75ecb3 100644 --- a/src/BlazingPizza.Server/OidcConfigurationController.cs +++ b/src/BlazingPizza.Server/OidcConfigurationController.cs @@ -1,26 +1,21 @@ using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class OidcConfigurationController : Controller { - public class OidcConfigurationController : Controller - { - public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) - { - ClientRequestParametersProvider = clientRequestParametersProvider; - } + public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) + { + ClientRequestParametersProvider = clientRequestParametersProvider; + } - public IClientRequestParametersProvider ClientRequestParametersProvider { get; } + public IClientRequestParametersProvider ClientRequestParametersProvider { get; } - [HttpGet("_configuration/{clientId}")] - public IActionResult GetClientRequestParameters([FromRoute]string clientId) - { - var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); - return Ok(parameters); - } - } + [HttpGet("_configuration/{clientId}")] + public IActionResult GetClientRequestParameters([FromRoute] string clientId) + { + var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); + return Ok(parameters); + } } diff --git a/src/BlazingPizza.Server/OrdersController.cs b/src/BlazingPizza.Server/OrdersController.cs index bab775e4..1859decd 100644 --- a/src/BlazingPizza.Server/OrdersController.cs +++ b/src/BlazingPizza.Server/OrdersController.cs @@ -1,135 +1,130 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; +using System.Security.Claims; using System.Text.Json; -using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using WebPush; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +[Route("orders")] +[ApiController] +[Authorize] +public class OrdersController : Controller { - [Route("orders")] - [ApiController] - [Authorize] - public class OrdersController : Controller - { - private readonly PizzaStoreContext _db; - - public OrdersController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetOrders() - { - var orders = await _db.Orders - .Where(o => o.UserId == GetUserId()) - .Include(o => o.DeliveryLocation) - .Include(o => o.Pizzas).ThenInclude(p => p.Special) - .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) - .OrderByDescending(o => o.CreatedTime) - .ToListAsync(); - - return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); - } - - [HttpGet("{orderId}")] - public async Task> GetOrderWithStatus(int orderId) - { - var order = await _db.Orders - .Where(o => o.OrderId == orderId) - .Where(o => o.UserId == GetUserId()) - .Include(o => o.DeliveryLocation) - .Include(o => o.Pizzas).ThenInclude(p => p.Special) - .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) - .SingleOrDefaultAsync(); - - if (order == null) - { - return NotFound(); - } - - return OrderWithStatus.FromOrder(order); - } - - [HttpPost] - public async Task> PlaceOrder(Order order) - { - order.CreatedTime = DateTime.Now; - order.DeliveryLocation = new LatLong(51.5001, -0.1239); - order.UserId = GetUserId(); - - // Enforce existence of Pizza.SpecialId and Topping.ToppingId - // in the database - prevent the submitter from making up - // new specials and toppings - foreach (var pizza in order.Pizzas) - { - pizza.SpecialId = pizza.Special.Id; - pizza.Special = null; - - foreach (var topping in pizza.Toppings) - { - topping.ToppingId = topping.Topping.Id; - topping.Topping = null; - } - } - - _db.Orders.Attach(order); - await _db.SaveChangesAsync(); - - // In the background, send push notifications if possible - var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); - if (subscription != null) - { - _ = TrackAndSendNotificationsAsync(order, subscription); - } - - return order.OrderId; - } - - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } - - private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription subscription) - { - // In a realistic case, some other backend process would track - // order delivery progress and send us notifications when it - // changes. Since we don't have any such process here, fake it. - await Task.Delay(OrderWithStatus.PreparationDuration); - await SendNotificationAsync(order, subscription, "Your order has been dispatched!"); - - await Task.Delay(OrderWithStatus.DeliveryDuration); - await SendNotificationAsync(order, subscription, "Your order is now delivered. Enjoy!"); - } - - private static async Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) - { - // For a real application, generate your own - var publicKey = "BLC8GOevpcpjQiLkO7JmVClQjycvTCYWm6Cq_a7wJZlstGTVZvwGFFHMYfXt6Njyvgx_GlXJeo5cSiZ1y4JOx1o"; - var privateKey = "OrubzSz3yWACscZXjFQrrtDwCKg-TGFuWhluQ2wLXDo"; - - var pushSubscription = new PushSubscription(subscription.Url, subscription.P256dh, subscription.Auth); - var vapidDetails = new VapidDetails("mailto:", publicKey, privateKey); - var webPushClient = new WebPushClient(); - try - { - var payload = JsonSerializer.Serialize(new - { - message, - url = $"myorders/{order.OrderId}", - }); - await webPushClient.SendNotificationAsync(pushSubscription, payload, vapidDetails); - } - catch (Exception ex) - { - Console.Error.WriteLine("Error sending push notification: " + ex.Message); - } - } - } + private readonly PizzaStoreContext _db; + + public OrdersController(PizzaStoreContext db) + { + _db = db; + } + + [HttpGet] + public async Task>> GetOrders() + { + var orders = await _db.Orders + .Where(o => o.UserId == GetUserId()) + .Include(o => o.DeliveryLocation) + .Include(o => o.Pizzas).ThenInclude(p => p.Special) + .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) + .OrderByDescending(o => o.CreatedTime) + .ToListAsync(); + + return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); + } + + [HttpGet("{orderId}")] + public async Task> GetOrderWithStatus(int orderId) + { + var order = await _db.Orders + .Where(o => o.OrderId == orderId) + .Where(o => o.UserId == GetUserId()) + .Include(o => o.DeliveryLocation) + .Include(o => o.Pizzas).ThenInclude(p => p.Special) + .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) + .SingleOrDefaultAsync(); + + if (order == null) + { + return NotFound(); + } + + return OrderWithStatus.FromOrder(order); + } + + [HttpPost] + public async Task> PlaceOrder(Order order) + { + order.CreatedTime = DateTime.Now; + order.DeliveryLocation = new LatLong(51.5001, -0.1239); + order.UserId = GetUserId(); + + // Enforce existence of Pizza.SpecialId and Topping.ToppingId + // in the database - prevent the submitter from making up + // new specials and toppings + foreach (var pizza in order.Pizzas) + { + pizza.SpecialId = pizza.Special.Id; + pizza.Special = null; + + foreach (var topping in pizza.Toppings) + { + topping.ToppingId = topping.Topping.Id; + topping.Topping = null; + } + } + + _db.Orders.Attach(order); + await _db.SaveChangesAsync(); + + // In the background, send push notifications if possible + var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); + if (subscription != null) + { + _ = TrackAndSendNotificationsAsync(order, subscription); + } + + return order.OrderId; + } + + private string GetUserId() + { + return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); + } + + private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription subscription) + { + // In a realistic case, some other backend process would track + // order delivery progress and send us notifications when it + // changes. Since we don't have any such process here, fake it. + await Task.Delay(OrderWithStatus.PreparationDuration); + await SendNotificationAsync(order, subscription, "Your order has been dispatched!"); + + await Task.Delay(OrderWithStatus.DeliveryDuration); + await SendNotificationAsync(order, subscription, "Your order is now delivered. Enjoy!"); + } + + private static async Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) + { + // For a real application, generate your own + var publicKey = "BLC8GOevpcpjQiLkO7JmVClQjycvTCYWm6Cq_a7wJZlstGTVZvwGFFHMYfXt6Njyvgx_GlXJeo5cSiZ1y4JOx1o"; + var privateKey = "OrubzSz3yWACscZXjFQrrtDwCKg-TGFuWhluQ2wLXDo"; + + var pushSubscription = new PushSubscription(subscription.Url, subscription.P256dh, subscription.Auth); + var vapidDetails = new VapidDetails("mailto:", publicKey, privateKey); + var webPushClient = new WebPushClient(); + try + { + var payload = JsonSerializer.Serialize(new + { + message, + url = $"myorders/{order.OrderId}", + }); + await webPushClient.SendNotificationAsync(pushSubscription, payload, vapidDetails); + } + catch (Exception ex) + { + Console.Error.WriteLine("Error sending push notification: " + ex.Message); + } + } } diff --git a/src/BlazingPizza.Server/PizzaApiExtensions.cs b/src/BlazingPizza.Server/PizzaApiExtensions.cs new file mode 100644 index 00000000..bf6b7bde --- /dev/null +++ b/src/BlazingPizza.Server/PizzaApiExtensions.cs @@ -0,0 +1,60 @@ +using System.Security.Claims; +using Microsoft.AspNetCore.Authorization; +using Microsoft.EntityFrameworkCore; + +namespace BlazingPizza.Server; + +public static class PizzaApiExtensions +{ + + public static WebApplication MapPizzaApi(this WebApplication app) + { + + // Subscribe to notifications + app.MapPut("/notifications/subscribe", [Authorize] async ( + HttpContext context, + PizzaStoreContext db, + NotificationSubscription subscription) => + { + + // We're storing at most one subscription per user, so delete old ones. + // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. + var userId = GetUserId(context); + var oldSubscriptions = db.NotificationSubscriptions.Where(e => e.UserId == userId); + db.NotificationSubscriptions.RemoveRange(oldSubscriptions); + + // Store new subscription + subscription.UserId = userId; + db.NotificationSubscriptions.Attach(subscription); + + await db.SaveChangesAsync(); + return Results.Ok(subscription); + + }); + + // Specials + app.MapGet("/specials", async (PizzaStoreContext db) => + { + + var specials = await db.Specials.ToListAsync(); + return Results.Ok(specials); + + }); + + // Toppings + app.MapGet("/toppings", async (PizzaStoreContext db) => + { + var toppings = await db.Toppings.OrderBy(t => t.Name).ToListAsync(); + return Results.Ok(toppings); + }); + + return app; + + } + + private static string GetUserId(HttpContext context) + { + return context.User.FindFirstValue(ClaimTypes.NameIdentifier); + } + +} \ No newline at end of file diff --git a/src/BlazingPizza.Server/PizzaStoreContext.cs b/src/BlazingPizza.Server/PizzaStoreContext.cs index 7fa06430..992baa19 100644 --- a/src/BlazingPizza.Server/PizzaStoreContext.cs +++ b/src/BlazingPizza.Server/PizzaStoreContext.cs @@ -3,37 +3,36 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class PizzaStoreContext : ApiAuthorizationDbContext { - public class PizzaStoreContext : ApiAuthorizationDbContext - { - public PizzaStoreContext( - DbContextOptions options, - IOptions operationalStoreOptions) : base(options, operationalStoreOptions) - { - } + public PizzaStoreContext( + DbContextOptions options, + IOptions operationalStoreOptions) : base(options, operationalStoreOptions) + { + } - public DbSet Orders { get; set; } + public DbSet Orders { get; set; } - public DbSet Pizzas { get; set; } + public DbSet Pizzas { get; set; } - public DbSet Specials { get; set; } + public DbSet Specials { get; set; } - public DbSet Toppings { get; set; } + public DbSet Toppings { get; set; } - public DbSet NotificationSubscriptions { get; set; } + public DbSet NotificationSubscriptions { get; set; } - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - base.OnModelCreating(modelBuilder); + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); - // Configuring a many-to-many special -> topping relationship that is friendly for serialization - modelBuilder.Entity().HasKey(pst => new { pst.PizzaId, pst.ToppingId }); - modelBuilder.Entity().HasOne().WithMany(ps => ps.Toppings); - modelBuilder.Entity().HasOne(pst => pst.Topping).WithMany(); + // Configuring a many-to-many special -> topping relationship that is friendly for serialization + modelBuilder.Entity().HasKey(pst => new { pst.PizzaId, pst.ToppingId }); + modelBuilder.Entity().HasOne().WithMany(ps => ps.Toppings); + modelBuilder.Entity().HasOne(pst => pst.Topping).WithMany(); - // Inline the Lat-Long pairs in Order rather than having a FK to another table - modelBuilder.Entity().OwnsOne(o => o.DeliveryLocation); - } - } + // Inline the Lat-Long pairs in Order rather than having a FK to another table + modelBuilder.Entity().OwnsOne(o => o.DeliveryLocation); + } } diff --git a/src/BlazingPizza.Server/PizzaStoreUser.cs b/src/BlazingPizza.Server/PizzaStoreUser.cs index 171ce83d..7ab40235 100644 --- a/src/BlazingPizza.Server/PizzaStoreUser.cs +++ b/src/BlazingPizza.Server/PizzaStoreUser.cs @@ -1,8 +1,5 @@ using Microsoft.AspNetCore.Identity; -namespace BlazingPizza.Server -{ - public class PizzaStoreUser : IdentityUser - { - } -} \ No newline at end of file +namespace BlazingPizza.Server; + +public class PizzaStoreUser : IdentityUser { } \ No newline at end of file diff --git a/src/BlazingPizza.Server/PizzasController.cs b/src/BlazingPizza.Server/PizzasController.cs deleted file mode 100644 index c082552c..00000000 --- a/src/BlazingPizza.Server/PizzasController.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("pizzas")] - [ApiController] - public class PizzasController : Controller - { - private readonly PizzaStoreContext _db; - - public PizzasController(PizzaStoreContext db) - { - _db = db; - } - } -} diff --git a/src/BlazingPizza.Server/Program.cs b/src/BlazingPizza.Server/Program.cs index 40a47641..4484d8f7 100644 --- a/src/BlazingPizza.Server/Program.cs +++ b/src/BlazingPizza.Server/Program.cs @@ -1,33 +1,67 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; +using Microsoft.AspNetCore.Authentication; +using Microsoft.EntityFrameworkCore; +using BlazingPizza.Server; -namespace BlazingPizza.Server +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddControllersWithViews() + .AddJsonOptions(options => { + options.JsonSerializerOptions.AddContext(); + }); +builder.Services.AddRazorPages(); + +builder.Services.AddDbContext(options => + options.UseSqlite("Data Source=pizza.db") + .UseModel(BlazingPizza.Server.Models.PizzaStoreContextModel.Instance)); + +builder.Services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) + .AddEntityFrameworkStores(); + +builder.Services.AddIdentityServer() + .AddApiAuthorization(); + +builder.Services.AddAuthentication() + .AddIdentityServerJwt(); + +var app = builder.Build(); + +// Initialize the database +var scopeFactory = app.Services.GetRequiredService(); +using (var scope = scopeFactory.CreateScope()) +{ + var db = scope.ServiceProvider.GetRequiredService(); + if (db.Database.EnsureCreated()) + { + SeedData.Initialize(db); + } +} + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseWebAssemblyDebugging(); +} +else { - public class Program - { - public static void Main(string[] args) - { - var host = CreateHostBuilder(args).Build(); - - // Initialize the database - var scopeFactory = host.Services.GetRequiredService(); - using (var scope = scopeFactory.CreateScope()) - { - var db = scope.ServiceProvider.GetRequiredService(); - if (db.Database.EnsureCreated()) - { - SeedData.Initialize(db); - } - } - - host.Run(); - } - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); - } + app.UseExceptionHandler("/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); } + +app.UseHttpsRedirection(); +app.UseBlazorFrameworkFiles(); +app.UseStaticFiles(); + +app.UseRouting(); + +app.UseAuthentication(); +app.UseIdentityServer(); +app.UseAuthorization(); + +app.MapPizzaApi(); + +app.MapRazorPages(); +app.MapControllers(); +app.MapFallbackToFile("index.html"); + +app.Run(); \ No newline at end of file diff --git a/src/BlazingPizza.Server/SeedData.cs b/src/BlazingPizza.Server/SeedData.cs index 7c86a5b2..a1e47973 100644 --- a/src/BlazingPizza.Server/SeedData.cs +++ b/src/BlazingPizza.Server/SeedData.cs @@ -1,193 +1,192 @@ -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public static class SeedData { - public static class SeedData - { - public static void Initialize(PizzaStoreContext db) - { - var toppings = new Topping[] - { - new Topping() - { - Name = "Extra cheese", - Price = 2.50m, - }, - new Topping() - { - Name = "American bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "British bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "Canadian bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "Tea and crumpets", - Price = 5.00m - }, - new Topping() - { - Name = "Fresh-baked scones", - Price = 4.50m, - }, - new Topping() - { - Name = "Bell peppers", - Price = 1.00m, - }, - new Topping() - { - Name = "Onions", - Price = 1.00m, - }, - new Topping() - { - Name = "Mushrooms", - Price = 1.00m, - }, - new Topping() - { - Name = "Pepperoni", - Price = 1.00m, - }, - new Topping() - { - Name = "Duck sausage", - Price = 3.20m, - }, - new Topping() - { - Name = "Venison meatballs", - Price = 2.50m, - }, - new Topping() - { - Name = "Served on a silver platter", - Price = 250.99m, - }, - new Topping() - { - Name = "Lobster on top", - Price = 64.50m, - }, - new Topping() - { - Name = "Sturgeon caviar", - Price = 101.75m, - }, - new Topping() - { - Name = "Artichoke hearts", - Price = 3.40m, - }, - new Topping() - { - Name = "Fresh tomatoes", - Price = 1.50m, - }, - new Topping() - { - Name = "Basil", - Price = 1.50m, - }, - new Topping() - { - Name = "Steak (medium-rare)", - Price = 8.50m, - }, - new Topping() - { - Name = "Blazing hot peppers", - Price = 4.20m, - }, - new Topping() - { - Name = "Buffalo chicken", - Price = 5.00m, - }, - new Topping() - { - Name = "Blue cheese", - Price = 2.50m, - }, - }; + public static void Initialize(PizzaStoreContext db) + { + var toppings = new Topping[] + { + new Topping() + { + Name = "Extra cheese", + Price = 2.50m, + }, + new Topping() + { + Name = "American bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "British bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "Canadian bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "Tea and crumpets", + Price = 5.00m + }, + new Topping() + { + Name = "Fresh-baked scones", + Price = 4.50m, + }, + new Topping() + { + Name = "Bell peppers", + Price = 1.00m, + }, + new Topping() + { + Name = "Onions", + Price = 1.00m, + }, + new Topping() + { + Name = "Mushrooms", + Price = 1.00m, + }, + new Topping() + { + Name = "Pepperoni", + Price = 1.00m, + }, + new Topping() + { + Name = "Duck sausage", + Price = 3.20m, + }, + new Topping() + { + Name = "Venison meatballs", + Price = 2.50m, + }, + new Topping() + { + Name = "Served on a silver platter", + Price = 250.99m, + }, + new Topping() + { + Name = "Lobster on top", + Price = 64.50m, + }, + new Topping() + { + Name = "Sturgeon caviar", + Price = 101.75m, + }, + new Topping() + { + Name = "Artichoke hearts", + Price = 3.40m, + }, + new Topping() + { + Name = "Fresh tomatoes", + Price = 1.50m, + }, + new Topping() + { + Name = "Basil", + Price = 1.50m, + }, + new Topping() + { + Name = "Steak (medium-rare)", + Price = 8.50m, + }, + new Topping() + { + Name = "Blazing hot peppers", + Price = 4.20m, + }, + new Topping() + { + Name = "Buffalo chicken", + Price = 5.00m, + }, + new Topping() + { + Name = "Blue cheese", + Price = 2.50m, + }, + }; - var specials = new PizzaSpecial[] - { - new PizzaSpecial() - { - Name = "Basic Cheese Pizza", - Description = "It's cheesy and delicious. Why wouldn't you want one?", - BasePrice = 9.99m, - ImageUrl = "img/pizzas/cheese.jpg", - }, - new PizzaSpecial() - { - Id = 2, - Name = "The Baconatorizor", - Description = "It has EVERY kind of bacon", - BasePrice = 11.99m, - ImageUrl = "img/pizzas/bacon.jpg", - }, - new PizzaSpecial() - { - Id = 3, - Name = "Classic pepperoni", - Description = "It's the pizza you grew up with, but Blazing hot!", - BasePrice = 10.50m, - ImageUrl = "img/pizzas/pepperoni.jpg", - }, - new PizzaSpecial() - { - Id = 4, - Name = "Buffalo chicken", - Description = "Spicy chicken, hot sauce and bleu cheese, guaranteed to warm you up", - BasePrice = 12.75m, - ImageUrl = "img/pizzas/meaty.jpg", - }, - new PizzaSpecial() - { - Id = 5, - Name = "Mushroom Lovers", - Description = "It has mushrooms. Isn't that obvious?", - BasePrice = 11.00m, - ImageUrl = "img/pizzas/mushroom.jpg", - }, - new PizzaSpecial() - { - Id = 6, - Name = "The Brit", - Description = "When in London...", - BasePrice = 10.25m, - ImageUrl = "img/pizzas/brit.jpg", - }, - new PizzaSpecial() - { - Id = 7, - Name = "Veggie Delight", - Description = "It's like salad, but on a pizza", - BasePrice = 11.50m, - ImageUrl = "img/pizzas/salad.jpg", - }, - new PizzaSpecial() - { - Id = 8, - Name = "Margherita", - Description = "Traditional Italian pizza with tomatoes and basil", - BasePrice = 9.99m, - ImageUrl = "img/pizzas/margherita.jpg", - }, - }; + var specials = new PizzaSpecial[] + { + new PizzaSpecial() + { + Name = "Basic Cheese Pizza", + Description = "It's cheesy and delicious. Why wouldn't you want one?", + BasePrice = 9.99m, + ImageUrl = "img/pizzas/cheese.jpg", + }, + new PizzaSpecial() + { + Id = 2, + Name = "The Baconatorizor", + Description = "It has EVERY kind of bacon", + BasePrice = 11.99m, + ImageUrl = "img/pizzas/bacon.jpg", + }, + new PizzaSpecial() + { + Id = 3, + Name = "Classic pepperoni", + Description = "It's the pizza you grew up with, but Blazing hot!", + BasePrice = 10.50m, + ImageUrl = "img/pizzas/pepperoni.jpg", + }, + new PizzaSpecial() + { + Id = 4, + Name = "Buffalo chicken", + Description = "Spicy chicken, hot sauce and bleu cheese, guaranteed to warm you up", + BasePrice = 12.75m, + ImageUrl = "img/pizzas/meaty.jpg", + }, + new PizzaSpecial() + { + Id = 5, + Name = "Mushroom Lovers", + Description = "It has mushrooms. Isn't that obvious?", + BasePrice = 11.00m, + ImageUrl = "img/pizzas/mushroom.jpg", + }, + new PizzaSpecial() + { + Id = 6, + Name = "The Brit", + Description = "When in London...", + BasePrice = 10.25m, + ImageUrl = "img/pizzas/brit.jpg", + }, + new PizzaSpecial() + { + Id = 7, + Name = "Veggie Delight", + Description = "It's like salad, but on a pizza", + BasePrice = 11.50m, + ImageUrl = "img/pizzas/salad.jpg", + }, + new PizzaSpecial() + { + Id = 8, + Name = "Margherita", + Description = "Traditional Italian pizza with tomatoes and basil", + BasePrice = 9.99m, + ImageUrl = "img/pizzas/margherita.jpg", + }, + }; - db.Toppings.AddRange(toppings); - db.Specials.AddRange(specials); - db.SaveChanges(); - } - } -} + db.Toppings.AddRange(toppings); + db.Specials.AddRange(specials); + db.SaveChanges(); + } +} \ No newline at end of file diff --git a/src/BlazingPizza.Server/SpecialsController.cs b/src/BlazingPizza.Server/SpecialsController.cs deleted file mode 100644 index 9c253eb6..00000000 --- a/src/BlazingPizza.Server/SpecialsController.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("specials")] - [ApiController] - public class SpecialsController : Controller - { - private readonly PizzaStoreContext _db; - - public SpecialsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetSpecials() - { - return (await _db.Specials.ToListAsync()).OrderByDescending(s => s.BasePrice).ToList(); - } - } -} diff --git a/src/BlazingPizza.Server/Startup.cs b/src/BlazingPizza.Server/Startup.cs deleted file mode 100644 index 053acade..00000000 --- a/src/BlazingPizza.Server/Startup.cs +++ /dev/null @@ -1,70 +0,0 @@ -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace BlazingPizza.Server -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - public void ConfigureServices(IServiceCollection services) - { - services.AddControllersWithViews(); - services.AddRazorPages(); - - services.AddDbContext(options => - options.UseSqlite("Data Source=pizza.db")); - - services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) - .AddEntityFrameworkStores(); - - services.AddIdentityServer() - .AddApiAuthorization(); - - services.AddAuthentication() - .AddIdentityServerJwt(); - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - app.UseWebAssemblyDebugging(); - } - else - { - app.UseExceptionHandler("/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); - } - - app.UseHttpsRedirection(); - app.UseBlazorFrameworkFiles(); - app.UseStaticFiles(); - - app.UseRouting(); - - app.UseAuthentication(); - app.UseIdentityServer(); - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapRazorPages(); - endpoints.MapControllers(); - endpoints.MapFallbackToFile("index.html"); - }); - } - } -} diff --git a/src/BlazingPizza.Server/ToppingsController.cs b/src/BlazingPizza.Server/ToppingsController.cs deleted file mode 100644 index 6a677639..00000000 --- a/src/BlazingPizza.Server/ToppingsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("toppings")] - [ApiController] - public class ToppingsController : Controller - { - private readonly PizzaStoreContext _db; - - public ToppingsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetToppings() - { - return await _db.Toppings.OrderBy(t => t.Name).ToListAsync(); - } - } -} diff --git a/src/BlazingPizza.Shared/Address.cs b/src/BlazingPizza.Shared/Address.cs index d76bc52a..79be9c5b 100644 --- a/src/BlazingPizza.Shared/Address.cs +++ b/src/BlazingPizza.Shared/Address.cs @@ -1,27 +1,24 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class Address { - public class Address - { - public int Id { get; set; } + public int Id { get; set; } - [Required, MaxLength(100)] - public string Name { get; set; } + [Required, MaxLength(100)] + public string Name { get; set; } - [Required, MaxLength(100)] - public string Line1 { get; set; } + [Required, MaxLength(100)] + public string Line1 { get; set; } - [MaxLength(100)] - public string Line2 { get; set; } + [MaxLength(100)] + public string Line2 { get; set; } - [Required, MaxLength(50)] - public string City { get; set; } + [Required, MaxLength(50)] + public string City { get; set; } - [Required, MaxLength(20)] - public string Region { get; set; } + [Required, MaxLength(20)] + public string Region { get; set; } - [Required, MaxLength(20)] - public string PostalCode { get; set; } - } + [Required, MaxLength(20)] + public string PostalCode { get; set; } } diff --git a/src/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/src/BlazingPizza.Shared/BlazingPizza.Shared.csproj index f7b7dd02..fb17e53b 100644 --- a/src/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/src/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -3,8 +3,13 @@ $(TargetFrameworkVersion) BlazingPizza + true + + + + diff --git a/src/BlazingPizza.Shared/LatLong.cs b/src/BlazingPizza.Shared/LatLong.cs index 9b8c3811..14a94c26 100644 --- a/src/BlazingPizza.Shared/LatLong.cs +++ b/src/BlazingPizza.Shared/LatLong.cs @@ -1,27 +1,26 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class LatLong { - public class LatLong - { - public LatLong() - { - } + public LatLong() + { + } - public LatLong(double latitude, double longitude) : this() - { - Latitude = latitude; - Longitude = longitude; - } + public LatLong(double latitude, double longitude) : this() + { + Latitude = latitude; + Longitude = longitude; + } - public double Latitude { get; set; } + public double Latitude { get; set; } - public double Longitude { get; set; } + public double Longitude { get; set; } - public static LatLong Interpolate(LatLong start, LatLong end, double proportion) - { - // The Earth is flat, right? So no need for spherical interpolation. - return new LatLong( - start.Latitude + (end.Latitude - start.Latitude) * proportion, - start.Longitude + (end.Longitude - start.Longitude) * proportion); - } - } -} + public static LatLong Interpolate(LatLong start, LatLong end, double proportion) + { + // The Earth is flat, right? So no need for spherical interpolation. + return new LatLong( + start.Latitude + (end.Latitude - start.Latitude) * proportion, + start.Longitude + (end.Longitude - start.Longitude) * proportion); + } +} \ No newline at end of file diff --git a/src/BlazingPizza.Shared/NotificationSubscription.cs b/src/BlazingPizza.Shared/NotificationSubscription.cs index 04259c2f..9109ff57 100644 --- a/src/BlazingPizza.Shared/NotificationSubscription.cs +++ b/src/BlazingPizza.Shared/NotificationSubscription.cs @@ -1,17 +1,14 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class NotificationSubscription { - public class NotificationSubscription - { - public int NotificationSubscriptionId { get; set; } + public int NotificationSubscriptionId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public string Url { get; set; } + public string Url { get; set; } - public string P256dh { get; set; } + public string P256dh { get; set; } - public string Auth { get; set; } - } + public string Auth { get; set; } } diff --git a/src/BlazingPizza.Shared/Order.cs b/src/BlazingPizza.Shared/Order.cs index fb003bd6..aca04ca1 100644 --- a/src/BlazingPizza.Shared/Order.cs +++ b/src/BlazingPizza.Shared/Order.cs @@ -1,25 +1,32 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +public class Order { - public class Order - { - public int OrderId { get; set; } + public int OrderId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public DateTime CreatedTime { get; set; } + public DateTime CreatedTime { get; set; } - public Address DeliveryAddress { get; set; } = new Address(); + public Address DeliveryAddress { get; set; } = new Address(); - public LatLong DeliveryLocation { get; set; } + public LatLong DeliveryLocation { get; set; } - public List Pizzas { get; set; } = new List(); + public List Pizzas { get; set; } = new List(); - public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); + public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); - public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); - } + public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Default, PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] +[JsonSerializable(typeof(Order))] +[JsonSerializable(typeof(OrderWithStatus))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Pizza))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Topping))] +public partial class OrderContext : JsonSerializerContext {} \ No newline at end of file diff --git a/src/BlazingPizza.Shared/OrderWithStatus.cs b/src/BlazingPizza.Shared/OrderWithStatus.cs index 021de78c..f5f153b6 100644 --- a/src/BlazingPizza.Shared/OrderWithStatus.cs +++ b/src/BlazingPizza.Shared/OrderWithStatus.cs @@ -1,79 +1,78 @@ -using BlazingPizza.ComponentsLibrary.Map; -using System; -using System.Collections.Generic; +using System.Text.Json.Serialization; +using BlazingPizza.ComponentsLibrary.Map; -namespace BlazingPizza + +namespace BlazingPizza; + +public class OrderWithStatus { - public class OrderWithStatus - { - public readonly static TimeSpan PreparationDuration = TimeSpan.FromSeconds(10); - public readonly static TimeSpan DeliveryDuration = TimeSpan.FromMinutes(1); // Unrealistic, but more interesting to watch + public readonly static TimeSpan PreparationDuration = TimeSpan.FromSeconds(10); + public readonly static TimeSpan DeliveryDuration = TimeSpan.FromMinutes(1); // Unrealistic, but more interesting to watch - public Order Order { get; set; } + public Order Order { get; set; } - public string StatusText { get; set; } + public string StatusText { get; set; } - public bool IsDelivered => StatusText == "Delivered"; + public bool IsDelivered => StatusText == "Delivered"; - public List MapMarkers { get; set; } + public List MapMarkers { get; set; } - public static OrderWithStatus FromOrder(Order order) - { - // To simulate a real backend process, we fake status updates based on the amount - // of time since the order was placed - string statusText; - List mapMarkers; - var dispatchTime = order.CreatedTime.Add(PreparationDuration); + public static OrderWithStatus FromOrder(Order order) + { + // To simulate a real backend process, we fake status updates based on the amount + // of time since the order was placed + string statusText; + List mapMarkers; + var dispatchTime = order.CreatedTime.Add(PreparationDuration); - if (DateTime.Now < dispatchTime) - { - statusText = "Preparing"; - mapMarkers = new List - { - ToMapMarker("You", order.DeliveryLocation, showPopup: true) - }; - } - else if (DateTime.Now < dispatchTime + DeliveryDuration) - { - statusText = "Out for delivery"; + if (DateTime.Now < dispatchTime) + { + statusText = "Preparing"; + mapMarkers = new List + { + ToMapMarker("You", order.DeliveryLocation, showPopup: true) + }; + } + else if (DateTime.Now < dispatchTime + DeliveryDuration) + { + statusText = "Out for delivery"; - var startPosition = ComputeStartPosition(order); - var proportionOfDeliveryCompleted = Math.Min(1, (DateTime.Now - dispatchTime).TotalMilliseconds / DeliveryDuration.TotalMilliseconds); - var driverPosition = LatLong.Interpolate(startPosition, order.DeliveryLocation, proportionOfDeliveryCompleted); - mapMarkers = new List - { - ToMapMarker("You", order.DeliveryLocation), - ToMapMarker("Driver", driverPosition, showPopup: true), - }; - } - else - { - statusText = "Delivered"; - mapMarkers = new List - { - ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), - }; - } + var startPosition = ComputeStartPosition(order); + var proportionOfDeliveryCompleted = Math.Min(1, (DateTime.Now - dispatchTime).TotalMilliseconds / DeliveryDuration.TotalMilliseconds); + var driverPosition = LatLong.Interpolate(startPosition, order.DeliveryLocation, proportionOfDeliveryCompleted); + mapMarkers = new List + { + ToMapMarker("You", order.DeliveryLocation), + ToMapMarker("Driver", driverPosition, showPopup: true), + }; + } + else + { + statusText = "Delivered"; + mapMarkers = new List + { + ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), + }; + } - return new OrderWithStatus - { - Order = order, - StatusText = statusText, - MapMarkers = mapMarkers, - }; - } + return new OrderWithStatus + { + Order = order, + StatusText = statusText, + MapMarkers = mapMarkers, + }; + } - private static LatLong ComputeStartPosition(Order order) - { - // Random but deterministic based on order ID - var rng = new Random(order.OrderId); - var distance = 0.01 + rng.NextDouble() * 0.02; - var angle = rng.NextDouble() * Math.PI * 2; - var offset = (distance * Math.Cos(angle), distance * Math.Sin(angle)); - return new LatLong(order.DeliveryLocation.Latitude + offset.Item1, order.DeliveryLocation.Longitude + offset.Item2); - } + private static LatLong ComputeStartPosition(Order order) + { + // Random but deterministic based on order ID + var rng = new Random(order.OrderId); + var distance = 0.01 + rng.NextDouble() * 0.02; + var angle = rng.NextDouble() * Math.PI * 2; + var offset = (distance * Math.Cos(angle), distance * Math.Sin(angle)); + return new LatLong(order.DeliveryLocation.Latitude + offset.Item1, order.DeliveryLocation.Longitude + offset.Item2); + } - static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) - => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; - } -} + static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) + => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; +} \ No newline at end of file diff --git a/src/BlazingPizza.Shared/Pizza.cs b/src/BlazingPizza.Shared/Pizza.cs index ec1108a9..459298f4 100644 --- a/src/BlazingPizza.Shared/Pizza.cs +++ b/src/BlazingPizza.Shared/Pizza.cs @@ -1,42 +1,44 @@ -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// /// Represents a customized pizza as part of an order +/// +public class Pizza { - /// - /// Represents a customized pizza as part of an order - /// - public class Pizza - { - public const int DefaultSize = 12; - public const int MinimumSize = 9; - public const int MaximumSize = 17; + public const int DefaultSize = 12; + public const int MinimumSize = 9; + public const int MaximumSize = 17; - public int Id { get; set; } + public int Id { get; set; } - public int OrderId { get; set; } + public int OrderId { get; set; } - public PizzaSpecial Special { get; set; } + public PizzaSpecial Special { get; set; } - public int SpecialId { get; set; } + public int SpecialId { get; set; } - public int Size { get; set; } + public int Size { get; set; } - public List Toppings { get; set; } + public List Toppings { get; set; } - public decimal GetBasePrice() - { - return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; - } + public decimal GetBasePrice() + { + return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; + } - public decimal GetTotalPrice() - { - return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); - } + public decimal GetTotalPrice() + { + return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); + } - public string GetFormattedTotalPrice() - { - return GetTotalPrice().ToString("0.00"); - } - } + public string GetFormattedTotalPrice() + { + return GetTotalPrice().ToString("0.00"); + } } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Serialization)] +[JsonSerializable(typeof(Pizza))] +public partial class PizzaContext : JsonSerializerContext {} \ No newline at end of file diff --git a/src/BlazingPizza.Shared/PizzaSpecial.cs b/src/BlazingPizza.Shared/PizzaSpecial.cs index 2f2b3383..9653300c 100644 --- a/src/BlazingPizza.Shared/PizzaSpecial.cs +++ b/src/BlazingPizza.Shared/PizzaSpecial.cs @@ -1,20 +1,19 @@ -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// Represents a pre-configured template for a pizza a user can order +/// +public class PizzaSpecial { - /// - /// Represents a pre-configured template for a pizza a user can order - /// - public class PizzaSpecial - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal BasePrice { get; set; } + public decimal BasePrice { get; set; } - public string Description { get; set; } + public string Description { get; set; } - public string ImageUrl { get; set; } + public string ImageUrl { get; set; } - public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); - } -} + public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); +} \ No newline at end of file diff --git a/src/BlazingPizza.Shared/PizzaTopping.cs b/src/BlazingPizza.Shared/PizzaTopping.cs index f5a6c1ac..0a711647 100644 --- a/src/BlazingPizza.Shared/PizzaTopping.cs +++ b/src/BlazingPizza.Shared/PizzaTopping.cs @@ -1,11 +1,11 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class PizzaTopping { - public class PizzaTopping - { - public Topping Topping { get; set; } + public Topping Topping { get; set; } + + public int ToppingId { get; set; } - public int ToppingId { get; set; } - - public int PizzaId { get; set; } - } -} + public int PizzaId { get; set; } + +} \ No newline at end of file diff --git a/src/BlazingPizza.Shared/Topping.cs b/src/BlazingPizza.Shared/Topping.cs index 61bdeb92..376c311a 100644 --- a/src/BlazingPizza.Shared/Topping.cs +++ b/src/BlazingPizza.Shared/Topping.cs @@ -1,13 +1,13 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class Topping { - public class Topping - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal Price { get; set; } + public decimal Price { get; set; } - public string GetFormattedPrice() => Price.ToString("0.00"); - } -} + public string GetFormattedPrice() => Price.ToString("0.00"); + +} \ No newline at end of file diff --git a/src/BlazingPizza.Shared/UserInfo.cs b/src/BlazingPizza.Shared/UserInfo.cs index 4996ef80..362f8f8e 100644 --- a/src/BlazingPizza.Shared/UserInfo.cs +++ b/src/BlazingPizza.Shared/UserInfo.cs @@ -1,9 +1,9 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class UserInfo { - public class UserInfo - { - public bool IsAuthenticated { get; set; } + public bool IsAuthenticated { get; set; } - public string Name { get; set; } - } -} + public string Name { get; set; } + +} \ No newline at end of file From a5464670195968fa169b320a127f872cdd09f8f4 Mon Sep 17 00:00:00 2001 From: "Jeffrey T. Fritz" Date: Fri, 28 Jan 2022 17:44:38 -0500 Subject: [PATCH 10/20] Finished savepoint 0 and 1 --- .../BlazingPizza.Shared/Address.cs | 27 +- .../BlazingPizza.Shared.csproj | 5 + .../BlazingPizza.Shared/LatLong.cs | 43 +- .../NotificationSubscription.cs | 17 +- .../BlazingPizza.Shared/Order.cs | 37 +- .../BlazingPizza.Shared/OrderWithStatus.cs | 133 +++--- .../BlazingPizza.Shared/Pizza.cs | 62 +-- .../BlazingPizza.Shared/PizzaSpecial.cs | 27 +- .../BlazingPizza.Shared/PizzaTopping.cs | 18 +- .../BlazingPizza.Shared/Topping.cs | 18 +- .../BlazingPizza.Shared/UserInfo.cs | 14 +- .../BlazingPizza.Client.csproj | 1 + .../BlazingPizza.Client/Pages/Index.razor | 2 +- .../BlazingPizza.Client/Program.cs | 24 +- .../BlazingPizza.ComponentsLibrary.csproj | 1 + .../LocalStorage.cs | 22 +- .../BlazingPizza.Server.csproj | 1 + .../Models/AddressEntityType.cs | 92 +++++ .../Models/DeviceFlowCodesEntityType.cs | 114 ++++++ .../IdentityRoleClaimstringEntityType.cs | 85 ++++ .../Models/IdentityRoleEntityType.cs | 78 ++++ .../IdentityUserClaimstringEntityType.cs | 85 ++++ .../IdentityUserLoginstringEntityType.cs | 86 ++++ .../IdentityUserRolestringEntityType.cs | 82 ++++ .../IdentityUserTokenstringEntityType.cs | 84 ++++ .../Models/KeyEntityType.cs | 96 +++++ .../Models/LatLongEntityType.cs | 80 ++++ .../NotificationSubscriptionEntityType.cs | 77 ++++ .../Models/OrderEntityType.cs | 86 ++++ .../Models/PersistedGrantEntityType.cs | 127 ++++++ .../Models/PizzaEntityType.cs | 111 +++++ .../Models/PizzaSpecialEntityType.cs | 76 ++++ .../Models/PizzaStoreContextModel.cs | 28 ++ .../Models/PizzaStoreContextModelBuilder.cs | 69 ++++ .../Models/PizzaStoreUserEntityType.cs | 156 +++++++ .../Models/PizzaToppingEntityType.cs | 96 +++++ .../Models/ToppingEntityType.cs | 62 +++ .../NotificationsController.cs | 43 -- .../OidcConfigurationController.cs | 35 +- .../BlazingPizza.Server/OrdersController.cs | 215 +++++----- .../BlazingPizza.Server/PizzaApiExtensions.cs | 60 +++ .../BlazingPizza.Server/PizzaStoreContext.cs | 51 ++- .../BlazingPizza.Server/PizzasController.cs | 16 - .../BlazingPizza.Server/Program.cs | 94 +++-- .../BlazingPizza.Server/SeedData.cs | 379 +++++++++--------- .../BlazingPizza.Server/SpecialsController.cs | 26 -- .../BlazingPizza.Server/Startup.cs | 71 ---- .../BlazingPizza.Server/ToppingsController.cs | 26 -- .../BlazingPizza.Shared/Address.cs | 27 +- .../BlazingPizza.Shared.csproj | 5 + .../BlazingPizza.Shared/LatLong.cs | 43 +- .../NotificationSubscription.cs | 17 +- .../BlazingPizza.Shared/Order.cs | 37 +- .../BlazingPizza.Shared/OrderWithStatus.cs | 133 +++--- .../BlazingPizza.Shared/Pizza.cs | 62 +-- .../BlazingPizza.Shared/PizzaSpecial.cs | 27 +- .../BlazingPizza.Shared/PizzaTopping.cs | 18 +- .../BlazingPizza.Shared/Topping.cs | 18 +- .../BlazingPizza.Shared/UserInfo.cs | 14 +- 59 files changed, 2660 insertions(+), 979 deletions(-) create mode 100644 save-points/01-Components-and-layout/BlazingPizza.Server/Models/AddressEntityType.cs create mode 100644 save-points/01-Components-and-layout/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs create mode 100644 save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs create mode 100644 save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityRoleEntityType.cs create mode 100644 save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs create mode 100644 save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs create mode 100644 save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs create mode 100644 save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs create mode 100644 save-points/01-Components-and-layout/BlazingPizza.Server/Models/KeyEntityType.cs create mode 100644 save-points/01-Components-and-layout/BlazingPizza.Server/Models/LatLongEntityType.cs create mode 100644 save-points/01-Components-and-layout/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs create mode 100644 save-points/01-Components-and-layout/BlazingPizza.Server/Models/OrderEntityType.cs create mode 100644 save-points/01-Components-and-layout/BlazingPizza.Server/Models/PersistedGrantEntityType.cs create mode 100644 save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaEntityType.cs create mode 100644 save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs create mode 100644 save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaStoreContextModel.cs create mode 100644 save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs create mode 100644 save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs create mode 100644 save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaToppingEntityType.cs create mode 100644 save-points/01-Components-and-layout/BlazingPizza.Server/Models/ToppingEntityType.cs delete mode 100644 save-points/01-Components-and-layout/BlazingPizza.Server/NotificationsController.cs create mode 100644 save-points/01-Components-and-layout/BlazingPizza.Server/PizzaApiExtensions.cs delete mode 100644 save-points/01-Components-and-layout/BlazingPizza.Server/PizzasController.cs delete mode 100644 save-points/01-Components-and-layout/BlazingPizza.Server/SpecialsController.cs delete mode 100644 save-points/01-Components-and-layout/BlazingPizza.Server/Startup.cs delete mode 100644 save-points/01-Components-and-layout/BlazingPizza.Server/ToppingsController.cs diff --git a/save-points/00-get-started/BlazingPizza.Shared/Address.cs b/save-points/00-get-started/BlazingPizza.Shared/Address.cs index e5c0ef0d..79be9c5b 100644 --- a/save-points/00-get-started/BlazingPizza.Shared/Address.cs +++ b/save-points/00-get-started/BlazingPizza.Shared/Address.cs @@ -1,21 +1,24 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class Address { - public class Address - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + [Required, MaxLength(100)] + public string Name { get; set; } - public string Line1 { get; set; } + [Required, MaxLength(100)] + public string Line1 { get; set; } - public string Line2 { get; set; } + [MaxLength(100)] + public string Line2 { get; set; } - public string City { get; set; } + [Required, MaxLength(50)] + public string City { get; set; } - public string Region { get; set; } + [Required, MaxLength(20)] + public string Region { get; set; } - public string PostalCode { get; set; } - } + [Required, MaxLength(20)] + public string PostalCode { get; set; } } diff --git a/save-points/00-get-started/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/save-points/00-get-started/BlazingPizza.Shared/BlazingPizza.Shared.csproj index f7b7dd02..fb17e53b 100644 --- a/save-points/00-get-started/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/save-points/00-get-started/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -3,8 +3,13 @@ $(TargetFrameworkVersion) BlazingPizza + true + + + + diff --git a/save-points/00-get-started/BlazingPizza.Shared/LatLong.cs b/save-points/00-get-started/BlazingPizza.Shared/LatLong.cs index 9b8c3811..14a94c26 100644 --- a/save-points/00-get-started/BlazingPizza.Shared/LatLong.cs +++ b/save-points/00-get-started/BlazingPizza.Shared/LatLong.cs @@ -1,27 +1,26 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class LatLong { - public class LatLong - { - public LatLong() - { - } + public LatLong() + { + } - public LatLong(double latitude, double longitude) : this() - { - Latitude = latitude; - Longitude = longitude; - } + public LatLong(double latitude, double longitude) : this() + { + Latitude = latitude; + Longitude = longitude; + } - public double Latitude { get; set; } + public double Latitude { get; set; } - public double Longitude { get; set; } + public double Longitude { get; set; } - public static LatLong Interpolate(LatLong start, LatLong end, double proportion) - { - // The Earth is flat, right? So no need for spherical interpolation. - return new LatLong( - start.Latitude + (end.Latitude - start.Latitude) * proportion, - start.Longitude + (end.Longitude - start.Longitude) * proportion); - } - } -} + public static LatLong Interpolate(LatLong start, LatLong end, double proportion) + { + // The Earth is flat, right? So no need for spherical interpolation. + return new LatLong( + start.Latitude + (end.Latitude - start.Latitude) * proportion, + start.Longitude + (end.Longitude - start.Longitude) * proportion); + } +} \ No newline at end of file diff --git a/save-points/00-get-started/BlazingPizza.Shared/NotificationSubscription.cs b/save-points/00-get-started/BlazingPizza.Shared/NotificationSubscription.cs index 04259c2f..9109ff57 100644 --- a/save-points/00-get-started/BlazingPizza.Shared/NotificationSubscription.cs +++ b/save-points/00-get-started/BlazingPizza.Shared/NotificationSubscription.cs @@ -1,17 +1,14 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class NotificationSubscription { - public class NotificationSubscription - { - public int NotificationSubscriptionId { get; set; } + public int NotificationSubscriptionId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public string Url { get; set; } + public string Url { get; set; } - public string P256dh { get; set; } + public string P256dh { get; set; } - public string Auth { get; set; } - } + public string Auth { get; set; } } diff --git a/save-points/00-get-started/BlazingPizza.Shared/Order.cs b/save-points/00-get-started/BlazingPizza.Shared/Order.cs index fb003bd6..aca04ca1 100644 --- a/save-points/00-get-started/BlazingPizza.Shared/Order.cs +++ b/save-points/00-get-started/BlazingPizza.Shared/Order.cs @@ -1,25 +1,32 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +public class Order { - public class Order - { - public int OrderId { get; set; } + public int OrderId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public DateTime CreatedTime { get; set; } + public DateTime CreatedTime { get; set; } - public Address DeliveryAddress { get; set; } = new Address(); + public Address DeliveryAddress { get; set; } = new Address(); - public LatLong DeliveryLocation { get; set; } + public LatLong DeliveryLocation { get; set; } - public List Pizzas { get; set; } = new List(); + public List Pizzas { get; set; } = new List(); - public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); + public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); - public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); - } + public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Default, PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] +[JsonSerializable(typeof(Order))] +[JsonSerializable(typeof(OrderWithStatus))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Pizza))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Topping))] +public partial class OrderContext : JsonSerializerContext {} \ No newline at end of file diff --git a/save-points/00-get-started/BlazingPizza.Shared/OrderWithStatus.cs b/save-points/00-get-started/BlazingPizza.Shared/OrderWithStatus.cs index 021de78c..f5f153b6 100644 --- a/save-points/00-get-started/BlazingPizza.Shared/OrderWithStatus.cs +++ b/save-points/00-get-started/BlazingPizza.Shared/OrderWithStatus.cs @@ -1,79 +1,78 @@ -using BlazingPizza.ComponentsLibrary.Map; -using System; -using System.Collections.Generic; +using System.Text.Json.Serialization; +using BlazingPizza.ComponentsLibrary.Map; -namespace BlazingPizza + +namespace BlazingPizza; + +public class OrderWithStatus { - public class OrderWithStatus - { - public readonly static TimeSpan PreparationDuration = TimeSpan.FromSeconds(10); - public readonly static TimeSpan DeliveryDuration = TimeSpan.FromMinutes(1); // Unrealistic, but more interesting to watch + public readonly static TimeSpan PreparationDuration = TimeSpan.FromSeconds(10); + public readonly static TimeSpan DeliveryDuration = TimeSpan.FromMinutes(1); // Unrealistic, but more interesting to watch - public Order Order { get; set; } + public Order Order { get; set; } - public string StatusText { get; set; } + public string StatusText { get; set; } - public bool IsDelivered => StatusText == "Delivered"; + public bool IsDelivered => StatusText == "Delivered"; - public List MapMarkers { get; set; } + public List MapMarkers { get; set; } - public static OrderWithStatus FromOrder(Order order) - { - // To simulate a real backend process, we fake status updates based on the amount - // of time since the order was placed - string statusText; - List mapMarkers; - var dispatchTime = order.CreatedTime.Add(PreparationDuration); + public static OrderWithStatus FromOrder(Order order) + { + // To simulate a real backend process, we fake status updates based on the amount + // of time since the order was placed + string statusText; + List mapMarkers; + var dispatchTime = order.CreatedTime.Add(PreparationDuration); - if (DateTime.Now < dispatchTime) - { - statusText = "Preparing"; - mapMarkers = new List - { - ToMapMarker("You", order.DeliveryLocation, showPopup: true) - }; - } - else if (DateTime.Now < dispatchTime + DeliveryDuration) - { - statusText = "Out for delivery"; + if (DateTime.Now < dispatchTime) + { + statusText = "Preparing"; + mapMarkers = new List + { + ToMapMarker("You", order.DeliveryLocation, showPopup: true) + }; + } + else if (DateTime.Now < dispatchTime + DeliveryDuration) + { + statusText = "Out for delivery"; - var startPosition = ComputeStartPosition(order); - var proportionOfDeliveryCompleted = Math.Min(1, (DateTime.Now - dispatchTime).TotalMilliseconds / DeliveryDuration.TotalMilliseconds); - var driverPosition = LatLong.Interpolate(startPosition, order.DeliveryLocation, proportionOfDeliveryCompleted); - mapMarkers = new List - { - ToMapMarker("You", order.DeliveryLocation), - ToMapMarker("Driver", driverPosition, showPopup: true), - }; - } - else - { - statusText = "Delivered"; - mapMarkers = new List - { - ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), - }; - } + var startPosition = ComputeStartPosition(order); + var proportionOfDeliveryCompleted = Math.Min(1, (DateTime.Now - dispatchTime).TotalMilliseconds / DeliveryDuration.TotalMilliseconds); + var driverPosition = LatLong.Interpolate(startPosition, order.DeliveryLocation, proportionOfDeliveryCompleted); + mapMarkers = new List + { + ToMapMarker("You", order.DeliveryLocation), + ToMapMarker("Driver", driverPosition, showPopup: true), + }; + } + else + { + statusText = "Delivered"; + mapMarkers = new List + { + ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), + }; + } - return new OrderWithStatus - { - Order = order, - StatusText = statusText, - MapMarkers = mapMarkers, - }; - } + return new OrderWithStatus + { + Order = order, + StatusText = statusText, + MapMarkers = mapMarkers, + }; + } - private static LatLong ComputeStartPosition(Order order) - { - // Random but deterministic based on order ID - var rng = new Random(order.OrderId); - var distance = 0.01 + rng.NextDouble() * 0.02; - var angle = rng.NextDouble() * Math.PI * 2; - var offset = (distance * Math.Cos(angle), distance * Math.Sin(angle)); - return new LatLong(order.DeliveryLocation.Latitude + offset.Item1, order.DeliveryLocation.Longitude + offset.Item2); - } + private static LatLong ComputeStartPosition(Order order) + { + // Random but deterministic based on order ID + var rng = new Random(order.OrderId); + var distance = 0.01 + rng.NextDouble() * 0.02; + var angle = rng.NextDouble() * Math.PI * 2; + var offset = (distance * Math.Cos(angle), distance * Math.Sin(angle)); + return new LatLong(order.DeliveryLocation.Latitude + offset.Item1, order.DeliveryLocation.Longitude + offset.Item2); + } - static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) - => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; - } -} + static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) + => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; +} \ No newline at end of file diff --git a/save-points/00-get-started/BlazingPizza.Shared/Pizza.cs b/save-points/00-get-started/BlazingPizza.Shared/Pizza.cs index ec1108a9..459298f4 100644 --- a/save-points/00-get-started/BlazingPizza.Shared/Pizza.cs +++ b/save-points/00-get-started/BlazingPizza.Shared/Pizza.cs @@ -1,42 +1,44 @@ -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// /// Represents a customized pizza as part of an order +/// +public class Pizza { - /// - /// Represents a customized pizza as part of an order - /// - public class Pizza - { - public const int DefaultSize = 12; - public const int MinimumSize = 9; - public const int MaximumSize = 17; + public const int DefaultSize = 12; + public const int MinimumSize = 9; + public const int MaximumSize = 17; - public int Id { get; set; } + public int Id { get; set; } - public int OrderId { get; set; } + public int OrderId { get; set; } - public PizzaSpecial Special { get; set; } + public PizzaSpecial Special { get; set; } - public int SpecialId { get; set; } + public int SpecialId { get; set; } - public int Size { get; set; } + public int Size { get; set; } - public List Toppings { get; set; } + public List Toppings { get; set; } - public decimal GetBasePrice() - { - return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; - } + public decimal GetBasePrice() + { + return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; + } - public decimal GetTotalPrice() - { - return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); - } + public decimal GetTotalPrice() + { + return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); + } - public string GetFormattedTotalPrice() - { - return GetTotalPrice().ToString("0.00"); - } - } + public string GetFormattedTotalPrice() + { + return GetTotalPrice().ToString("0.00"); + } } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Serialization)] +[JsonSerializable(typeof(Pizza))] +public partial class PizzaContext : JsonSerializerContext {} \ No newline at end of file diff --git a/save-points/00-get-started/BlazingPizza.Shared/PizzaSpecial.cs b/save-points/00-get-started/BlazingPizza.Shared/PizzaSpecial.cs index 2f2b3383..9653300c 100644 --- a/save-points/00-get-started/BlazingPizza.Shared/PizzaSpecial.cs +++ b/save-points/00-get-started/BlazingPizza.Shared/PizzaSpecial.cs @@ -1,20 +1,19 @@ -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// Represents a pre-configured template for a pizza a user can order +/// +public class PizzaSpecial { - /// - /// Represents a pre-configured template for a pizza a user can order - /// - public class PizzaSpecial - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal BasePrice { get; set; } + public decimal BasePrice { get; set; } - public string Description { get; set; } + public string Description { get; set; } - public string ImageUrl { get; set; } + public string ImageUrl { get; set; } - public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); - } -} + public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); +} \ No newline at end of file diff --git a/save-points/00-get-started/BlazingPizza.Shared/PizzaTopping.cs b/save-points/00-get-started/BlazingPizza.Shared/PizzaTopping.cs index f5a6c1ac..0a711647 100644 --- a/save-points/00-get-started/BlazingPizza.Shared/PizzaTopping.cs +++ b/save-points/00-get-started/BlazingPizza.Shared/PizzaTopping.cs @@ -1,11 +1,11 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class PizzaTopping { - public class PizzaTopping - { - public Topping Topping { get; set; } + public Topping Topping { get; set; } + + public int ToppingId { get; set; } - public int ToppingId { get; set; } - - public int PizzaId { get; set; } - } -} + public int PizzaId { get; set; } + +} \ No newline at end of file diff --git a/save-points/00-get-started/BlazingPizza.Shared/Topping.cs b/save-points/00-get-started/BlazingPizza.Shared/Topping.cs index 61bdeb92..376c311a 100644 --- a/save-points/00-get-started/BlazingPizza.Shared/Topping.cs +++ b/save-points/00-get-started/BlazingPizza.Shared/Topping.cs @@ -1,13 +1,13 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class Topping { - public class Topping - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal Price { get; set; } + public decimal Price { get; set; } - public string GetFormattedPrice() => Price.ToString("0.00"); - } -} + public string GetFormattedPrice() => Price.ToString("0.00"); + +} \ No newline at end of file diff --git a/save-points/00-get-started/BlazingPizza.Shared/UserInfo.cs b/save-points/00-get-started/BlazingPizza.Shared/UserInfo.cs index 4996ef80..362f8f8e 100644 --- a/save-points/00-get-started/BlazingPizza.Shared/UserInfo.cs +++ b/save-points/00-get-started/BlazingPizza.Shared/UserInfo.cs @@ -1,9 +1,9 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class UserInfo { - public class UserInfo - { - public bool IsAuthenticated { get; set; } + public bool IsAuthenticated { get; set; } - public string Name { get; set; } - } -} + public string Name { get; set; } + +} \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Client/BlazingPizza.Client.csproj b/save-points/01-Components-and-layout/BlazingPizza.Client/BlazingPizza.Client.csproj index 663677a1..f9ebe283 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/save-points/01-Components-and-layout/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -2,6 +2,7 @@ $(TargetFrameworkVersion) + true diff --git a/save-points/01-Components-and-layout/BlazingPizza.Client/Pages/Index.razor b/save-points/01-Components-and-layout/BlazingPizza.Client/Pages/Index.razor index 68649ba9..03d6e160 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Client/Pages/Index.razor +++ b/save-points/01-Components-and-layout/BlazingPizza.Client/Pages/Index.razor @@ -24,6 +24,6 @@ protected override async Task OnInitializedAsync() { - specials = await HttpClient.GetFromJsonAsync>("specials"); + specials = await HttpClient.GetFromJsonAsync("specials", BlazingPizza.OrderContext.Default.ListPizzaSpecial); } } diff --git a/save-points/01-Components-and-layout/BlazingPizza.Client/Program.cs b/save-points/01-Components-and-layout/BlazingPizza.Client/Program.cs index 48147d6f..ab7dd4d9 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Client/Program.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Client/Program.cs @@ -1,21 +1,9 @@ -using Microsoft.AspNetCore.Components.WebAssembly.Hosting; -using Microsoft.Extensions.DependencyInjection; -using System; -using System.Net.Http; -using System.Threading.Tasks; +using BlazingPizza.Client; +using Microsoft.AspNetCore.Components.WebAssembly.Hosting; -namespace BlazingPizza.Client -{ - public class Program - { - public static async Task Main(string[] args) - { - var builder = WebAssemblyHostBuilder.CreateDefault(args); - builder.RootComponents.Add("#app"); +var builder = WebAssemblyHostBuilder.CreateDefault(args); +builder.RootComponents.Add("#app"); - builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); +builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); - await builder.Build().RunAsync(); - } - } -} +await builder.Build().RunAsync(); diff --git a/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 61ebf623..cb996b1b 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -2,6 +2,7 @@ $(TargetFrameworkVersion) + true diff --git a/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/LocalStorage.cs b/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/LocalStorage.cs index f36b098e..bb84f13c 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/LocalStorage.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/LocalStorage.cs @@ -1,17 +1,15 @@ using Microsoft.JSInterop; -using System.Threading.Tasks; -namespace BlazingPizza.ComponentsLibrary +namespace BlazingPizza.ComponentsLibrary; + +public static class LocalStorage { - public static class LocalStorage - { - public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) - => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); + public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) + => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); - public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object value) - => jsRuntime.InvokeVoidAsync("blazorLocalStorage.set", key, value); + public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object value) + => jsRuntime.InvokeVoidAsync("blazorLocalStorage.set", key, value); - public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key) - => jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key); - } -} + public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key) + => jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key); +} \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/BlazingPizza.Server.csproj b/save-points/01-Components-and-layout/BlazingPizza.Server/BlazingPizza.Server.csproj index b9c74fc4..227890e1 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -2,6 +2,7 @@ $(TargetFrameworkVersion) + true diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/AddressEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/AddressEntityType.cs new file mode 100644 index 00000000..82db81b6 --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/AddressEntityType.cs @@ -0,0 +1,92 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class AddressEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Address", + typeof(Address), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Address).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var city = runtimeEntityType.AddProperty( + "City", + typeof(string), + propertyInfo: typeof(Address).GetProperty("City", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var line1 = runtimeEntityType.AddProperty( + "Line1", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line1", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var line2 = runtimeEntityType.AddProperty( + "Line2", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line2", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var postalCode = runtimeEntityType.AddProperty( + "PostalCode", + typeof(string), + propertyInfo: typeof(Address).GetProperty("PostalCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var region = runtimeEntityType.AddProperty( + "Region", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Region", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Address"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs new file mode 100644 index 00000000..1dd4563b --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs @@ -0,0 +1,114 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class DeviceFlowCodesEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.DeviceFlowCodes", + typeof(DeviceFlowCodes), + baseEntityType); + + var userCode = runtimeEntityType.AddProperty( + "UserCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("UserCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var deviceCode = runtimeEntityType.AddProperty( + "DeviceCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("DeviceCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var key = runtimeEntityType.AddKey( + new[] { userCode }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deviceCode }, + unique: true); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "DeviceCodes"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs new file mode 100644 index 00000000..8946b261 --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRoleClaim", + typeof(IdentityRoleClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoleClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityRoleEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityRoleEntityType.cs new file mode 100644 index 00000000..2f1fec2b --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityRoleEntityType.cs @@ -0,0 +1,78 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRole", + typeof(IdentityRole), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedName = runtimeEntityType.AddProperty( + "NormalizedName", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("NormalizedName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedName }, + unique: true); + index.AddAnnotation("Relational:Name", "RoleNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs new file mode 100644 index 00000000..55418a1e --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserClaim", + typeof(IdentityUserClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityUserClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs new file mode 100644 index 00000000..3ca029bd --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserLoginstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserLogin", + typeof(IdentityUserLogin), + baseEntityType); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerKey = runtimeEntityType.AddProperty( + "ProviderKey", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderKey", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerDisplayName = runtimeEntityType.AddProperty( + "ProviderDisplayName", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderDisplayName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { loginProvider, providerKey }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserLogins"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs new file mode 100644 index 00000000..70078d7a --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs @@ -0,0 +1,82 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserRolestringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserRole", + typeof(IdentityUserRole), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { userId, roleId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs new file mode 100644 index 00000000..93ba6d31 --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs @@ -0,0 +1,84 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserTokenstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserToken", + typeof(IdentityUserToken), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var value = runtimeEntityType.AddProperty( + "Value", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Value", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { userId, loginProvider, name }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserTokens"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/KeyEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/KeyEntityType.cs new file mode 100644 index 00000000..f6c6b4c7 --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/KeyEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class KeyEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.Key", + typeof(Key), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var algorithm = runtimeEntityType.AddProperty( + "Algorithm", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Algorithm", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var created = runtimeEntityType.AddProperty( + "Created", + typeof(DateTime), + propertyInfo: typeof(Key).GetProperty("Created", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var dataProtected = runtimeEntityType.AddProperty( + "DataProtected", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("DataProtected", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var isX509Certificate = runtimeEntityType.AddProperty( + "IsX509Certificate", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("IsX509Certificate", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var use = runtimeEntityType.AddProperty( + "Use", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Use", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var version = runtimeEntityType.AddProperty( + "Version", + typeof(int), + propertyInfo: typeof(Key).GetProperty("Version", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { use }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Keys"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/LatLongEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/LatLongEntityType.cs new file mode 100644 index 00000000..3fd254bd --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/LatLongEntityType.cs @@ -0,0 +1,80 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class LatLongEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.LatLong", + typeof(LatLong), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var latitude = runtimeEntityType.AddProperty( + "Latitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Latitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var longitude = runtimeEntityType.AddProperty( + "Longitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Longitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + unique: true, + required: true, + ownership: true); + + var deliveryLocation = principalEntityType.AddNavigation("DeliveryLocation", + runtimeForeignKey, + onDependent: false, + typeof(LatLong), + propertyInfo: typeof(Order).GetProperty("DeliveryLocation", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + eagerLoaded: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs new file mode 100644 index 00000000..db236e4c --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs @@ -0,0 +1,77 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class NotificationSubscriptionEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.NotificationSubscription", + typeof(NotificationSubscription), + baseEntityType); + + var notificationSubscriptionId = runtimeEntityType.AddProperty( + "NotificationSubscriptionId", + typeof(int), + propertyInfo: typeof(NotificationSubscription).GetProperty("NotificationSubscriptionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var auth = runtimeEntityType.AddProperty( + "Auth", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Auth", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var p256dh = runtimeEntityType.AddProperty( + "P256dh", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("P256dh", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var url = runtimeEntityType.AddProperty( + "Url", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Url", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { notificationSubscriptionId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "NotificationSubscriptions"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/OrderEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/OrderEntityType.cs new file mode 100644 index 00000000..9d9ec6fd --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/OrderEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class OrderEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Order", + typeof(Order), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Order).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var createdTime = runtimeEntityType.AddProperty( + "CreatedTime", + typeof(DateTime), + propertyInfo: typeof(Order).GetProperty("CreatedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var deliveryAddressId = runtimeEntityType.AddProperty( + "DeliveryAddressId", + typeof(int?), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(Order).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deliveryAddressId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("DeliveryAddressId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType); + + var deliveryAddress = declaringEntityType.AddNavigation("DeliveryAddress", + runtimeForeignKey, + onDependent: true, + typeof(Address), + propertyInfo: typeof(Order).GetProperty("DeliveryAddress", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PersistedGrantEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PersistedGrantEntityType.cs new file mode 100644 index 00000000..842d53a5 --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PersistedGrantEntityType.cs @@ -0,0 +1,127 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PersistedGrantEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.PersistedGrant", + typeof(PersistedGrant), + baseEntityType); + + var key = runtimeEntityType.AddProperty( + "Key", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Key", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var consumedTime = runtimeEntityType.AddProperty( + "ConsumedTime", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("ConsumedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(PersistedGrant).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var type = runtimeEntityType.AddProperty( + "Type", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Type", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var key0 = runtimeEntityType.AddKey( + new[] { key }); + runtimeEntityType.SetPrimaryKey(key0); + + var index = runtimeEntityType.AddIndex( + new[] { consumedTime }); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + var index1 = runtimeEntityType.AddIndex( + new[] { subjectId, clientId, type }); + + var index2 = runtimeEntityType.AddIndex( + new[] { subjectId, sessionId, type }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PersistedGrants"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaEntityType.cs new file mode 100644 index 00000000..3a124e63 --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaEntityType.cs @@ -0,0 +1,111 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Pizza", + typeof(Pizza), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var size = runtimeEntityType.AddProperty( + "Size", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Size", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var specialId = runtimeEntityType.AddProperty( + "SpecialId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("SpecialId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { orderId }); + + var index0 = runtimeEntityType.AddIndex( + new[] { specialId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var pizzas = principalEntityType.AddNavigation("Pizzas", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Order).GetProperty("Pizzas", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("SpecialId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var special = declaringEntityType.AddNavigation("Special", + runtimeForeignKey, + onDependent: true, + typeof(PizzaSpecial), + propertyInfo: typeof(Pizza).GetProperty("Special", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Pizzas"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs new file mode 100644 index 00000000..e86b0f50 --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs @@ -0,0 +1,76 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaSpecialEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaSpecial", + typeof(PizzaSpecial), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(PizzaSpecial).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var basePrice = runtimeEntityType.AddProperty( + "BasePrice", + typeof(decimal), + propertyInfo: typeof(PizzaSpecial).GetProperty("BasePrice", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var imageUrl = runtimeEntityType.AddProperty( + "ImageUrl", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("ImageUrl", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Specials"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaStoreContextModel.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaStoreContextModel.cs new file mode 100644 index 00000000..8b516a68 --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaStoreContextModel.cs @@ -0,0 +1,28 @@ +// +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + [DbContext(typeof(PizzaStoreContext))] + public partial class PizzaStoreContextModel : RuntimeModel + { + static PizzaStoreContextModel() + { + var model = new PizzaStoreContextModel(); + model.Initialize(); + model.Customize(); + _instance = model; + } + + private static PizzaStoreContextModel _instance; + public static IModel Instance => _instance; + + partial void Initialize(); + + partial void Customize(); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs new file mode 100644 index 00000000..d46f50f4 --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs @@ -0,0 +1,69 @@ +// +using System; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + public partial class PizzaStoreContextModel + { + partial void Initialize() + { + var address = AddressEntityType.Create(this); + var latLong = LatLongEntityType.Create(this); + var notificationSubscription = NotificationSubscriptionEntityType.Create(this); + var order = OrderEntityType.Create(this); + var pizza = PizzaEntityType.Create(this); + var pizzaSpecial = PizzaSpecialEntityType.Create(this); + var pizzaTopping = PizzaToppingEntityType.Create(this); + var pizzaStoreUser = PizzaStoreUserEntityType.Create(this); + var topping = ToppingEntityType.Create(this); + var deviceFlowCodes = DeviceFlowCodesEntityType.Create(this); + var key = KeyEntityType.Create(this); + var persistedGrant = PersistedGrantEntityType.Create(this); + var identityRole = IdentityRoleEntityType.Create(this); + var identityRoleClaimstring = IdentityRoleClaimstringEntityType.Create(this); + var identityUserClaimstring = IdentityUserClaimstringEntityType.Create(this); + var identityUserLoginstring = IdentityUserLoginstringEntityType.Create(this); + var identityUserRolestring = IdentityUserRolestringEntityType.Create(this); + var identityUserTokenstring = IdentityUserTokenstringEntityType.Create(this); + + LatLongEntityType.CreateForeignKey1(latLong, order); + OrderEntityType.CreateForeignKey1(order, address); + PizzaEntityType.CreateForeignKey1(pizza, order); + PizzaEntityType.CreateForeignKey2(pizza, pizzaSpecial); + PizzaToppingEntityType.CreateForeignKey1(pizzaTopping, pizza); + PizzaToppingEntityType.CreateForeignKey2(pizzaTopping, topping); + IdentityRoleClaimstringEntityType.CreateForeignKey1(identityRoleClaimstring, identityRole); + IdentityUserClaimstringEntityType.CreateForeignKey1(identityUserClaimstring, pizzaStoreUser); + IdentityUserLoginstringEntityType.CreateForeignKey1(identityUserLoginstring, pizzaStoreUser); + IdentityUserRolestringEntityType.CreateForeignKey1(identityUserRolestring, identityRole); + IdentityUserRolestringEntityType.CreateForeignKey2(identityUserRolestring, pizzaStoreUser); + IdentityUserTokenstringEntityType.CreateForeignKey1(identityUserTokenstring, pizzaStoreUser); + + AddressEntityType.CreateAnnotations(address); + LatLongEntityType.CreateAnnotations(latLong); + NotificationSubscriptionEntityType.CreateAnnotations(notificationSubscription); + OrderEntityType.CreateAnnotations(order); + PizzaEntityType.CreateAnnotations(pizza); + PizzaSpecialEntityType.CreateAnnotations(pizzaSpecial); + PizzaToppingEntityType.CreateAnnotations(pizzaTopping); + PizzaStoreUserEntityType.CreateAnnotations(pizzaStoreUser); + ToppingEntityType.CreateAnnotations(topping); + DeviceFlowCodesEntityType.CreateAnnotations(deviceFlowCodes); + KeyEntityType.CreateAnnotations(key); + PersistedGrantEntityType.CreateAnnotations(persistedGrant); + IdentityRoleEntityType.CreateAnnotations(identityRole); + IdentityRoleClaimstringEntityType.CreateAnnotations(identityRoleClaimstring); + IdentityUserClaimstringEntityType.CreateAnnotations(identityUserClaimstring); + IdentityUserLoginstringEntityType.CreateAnnotations(identityUserLoginstring); + IdentityUserRolestringEntityType.CreateAnnotations(identityUserRolestring); + IdentityUserTokenstringEntityType.CreateAnnotations(identityUserTokenstring); + + AddAnnotation("ProductVersion", "6.0.0"); + } + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs new file mode 100644 index 00000000..18b2d96d --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs @@ -0,0 +1,156 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaStoreUserEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Server.PizzaStoreUser", + typeof(PizzaStoreUser), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var accessFailedCount = runtimeEntityType.AddProperty( + "AccessFailedCount", + typeof(int), + propertyInfo: typeof(IdentityUser).GetProperty("AccessFailedCount", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var email = runtimeEntityType.AddProperty( + "Email", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Email", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var emailConfirmed = runtimeEntityType.AddProperty( + "EmailConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("EmailConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnabled = runtimeEntityType.AddProperty( + "LockoutEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnd = runtimeEntityType.AddProperty( + "LockoutEnd", + typeof(DateTimeOffset?), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnd", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var normalizedEmail = runtimeEntityType.AddProperty( + "NormalizedEmail", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedEmail", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedUserName = runtimeEntityType.AddProperty( + "NormalizedUserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedUserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var passwordHash = runtimeEntityType.AddProperty( + "PasswordHash", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PasswordHash", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumber = runtimeEntityType.AddProperty( + "PhoneNumber", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumber", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumberConfirmed = runtimeEntityType.AddProperty( + "PhoneNumberConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumberConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var securityStamp = runtimeEntityType.AddProperty( + "SecurityStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("SecurityStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var twoFactorEnabled = runtimeEntityType.AddProperty( + "TwoFactorEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("TwoFactorEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var userName = runtimeEntityType.AddProperty( + "UserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("UserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedEmail }); + index.AddAnnotation("Relational:Name", "EmailIndex"); + + var index0 = runtimeEntityType.AddIndex( + new[] { normalizedUserName }, + unique: true); + index0.AddAnnotation("Relational:Name", "UserNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUsers"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaToppingEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaToppingEntityType.cs new file mode 100644 index 00000000..b97d2a24 --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaToppingEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaTopping", + typeof(PizzaTopping), + baseEntityType); + + var pizzaId = runtimeEntityType.AddProperty( + "PizzaId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("PizzaId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var toppingId = runtimeEntityType.AddProperty( + "ToppingId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("ToppingId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { pizzaId, toppingId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { toppingId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("PizzaId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var toppings = principalEntityType.AddNavigation("Toppings", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Pizza).GetProperty("Toppings", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("ToppingId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var topping = declaringEntityType.AddNavigation("Topping", + runtimeForeignKey, + onDependent: true, + typeof(Topping), + propertyInfo: typeof(PizzaTopping).GetProperty("Topping", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PizzaTopping"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/ToppingEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/ToppingEntityType.cs new file mode 100644 index 00000000..9295f9bf --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/ToppingEntityType.cs @@ -0,0 +1,62 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class ToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Topping", + typeof(Topping), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Topping).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Topping).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var price = runtimeEntityType.AddProperty( + "Price", + typeof(decimal), + propertyInfo: typeof(Topping).GetProperty("Price", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Toppings"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/NotificationsController.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/NotificationsController.cs deleted file mode 100644 index bb3b96ff..00000000 --- a/save-points/01-Components-and-layout/BlazingPizza.Server/NotificationsController.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("notifications")] - [ApiController] - [Authorize] - public class NotificationsController : Controller - { - private readonly PizzaStoreContext _db; - - public NotificationsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpPut("subscribe")] - public async Task Subscribe(NotificationSubscription subscription) - { - // We're storing at most one subscription per user, so delete old ones. - // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. - var userId = GetUserId(); - var oldSubscriptions = _db.NotificationSubscriptions.Where(e => e.UserId == userId); - _db.NotificationSubscriptions.RemoveRange(oldSubscriptions); - - // Store new subscription - subscription.UserId = userId; - _db.NotificationSubscriptions.Attach(subscription); - - await _db.SaveChangesAsync(); - return subscription; - } - - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } - } -} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/OidcConfigurationController.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/OidcConfigurationController.cs index c074debf..b7654075 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Server/OidcConfigurationController.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/OidcConfigurationController.cs @@ -1,26 +1,21 @@ using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class OidcConfigurationController : Controller { - public class OidcConfigurationController : Controller - { - public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) - { - ClientRequestParametersProvider = clientRequestParametersProvider; - } + public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) + { + ClientRequestParametersProvider = clientRequestParametersProvider; + } - public IClientRequestParametersProvider ClientRequestParametersProvider { get; } + public IClientRequestParametersProvider ClientRequestParametersProvider { get; } - [HttpGet("_configuration/{clientId}")] - public IActionResult GetClientRequestParameters([FromRoute]string clientId) - { - var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); - return Ok(parameters); - } - } -} + [HttpGet("_configuration/{clientId}")] + public IActionResult GetClientRequestParameters([FromRoute] string clientId) + { + var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); + return Ok(parameters); + } +} \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/OrdersController.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/OrdersController.cs index 2b8bc99b..54ff6114 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Server/OrdersController.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/OrdersController.cs @@ -1,114 +1,109 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; +using System.Security.Claims; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +[Route("orders")] +[ApiController] +// [Authorize] +public class OrdersController : Controller { - [Route("orders")] - [ApiController] - // [Authorize] - public class OrdersController : Controller - { - private readonly PizzaStoreContext _db; - - public OrdersController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetOrders() - { - var orders = await _db.Orders - // .Where(o => o.UserId == GetUserId()) - .Include(o => o.DeliveryLocation) - .Include(o => o.Pizzas).ThenInclude(p => p.Special) - .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) - .OrderByDescending(o => o.CreatedTime) - .ToListAsync(); - - return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); - } - - [HttpGet("{orderId}")] - public async Task> GetOrderWithStatus(int orderId) - { - var order = await _db.Orders - .Where(o => o.OrderId == orderId) - // .Where(o => o.UserId == GetUserId()) - .Include(o => o.DeliveryLocation) - .Include(o => o.Pizzas).ThenInclude(p => p.Special) - .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) - .SingleOrDefaultAsync(); - - if (order == null) - { - return NotFound(); - } - - return OrderWithStatus.FromOrder(order); - } - - [HttpPost] - public async Task> PlaceOrder(Order order) - { - order.CreatedTime = DateTime.Now; - order.DeliveryLocation = new LatLong(51.5001, -0.1239); - // order.UserId = GetUserId(); - - // Enforce existence of Pizza.SpecialId and Topping.ToppingId - // in the database - prevent the submitter from making up - // new specials and toppings - foreach (var pizza in order.Pizzas) - { - pizza.SpecialId = pizza.Special.Id; - pizza.Special = null; - - foreach (var topping in pizza.Toppings) - { - topping.ToppingId = topping.Topping.Id; - topping.Topping = null; - } - } - - _db.Orders.Attach(order); - await _db.SaveChangesAsync(); - - // In the background, send push notifications if possible - var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); - if (subscription != null) - { - _ = TrackAndSendNotificationsAsync(order, subscription); - } - - return order.OrderId; - } - - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } - - private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription subscription) - { - // In a realistic case, some other backend process would track - // order delivery progress and send us notifications when it - // changes. Since we don't have any such process here, fake it. - await Task.Delay(OrderWithStatus.PreparationDuration); - await SendNotificationAsync(order, subscription, "Your order has been dispatched!"); - - await Task.Delay(OrderWithStatus.DeliveryDuration); - await SendNotificationAsync(order, subscription, "Your order is now delivered. Enjoy!"); - } - - private static Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) - { - // This will be implemented later - return Task.CompletedTask; - } - } -} + private readonly PizzaStoreContext _db; + + public OrdersController(PizzaStoreContext db) + { + _db = db; + } + + [HttpGet] + public async Task>> GetOrders() + { + var orders = await _db.Orders + // .Where(o => o.UserId == GetUserId()) + .Include(o => o.DeliveryLocation) + .Include(o => o.Pizzas).ThenInclude(p => p.Special) + .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) + .OrderByDescending(o => o.CreatedTime) + .ToListAsync(); + + return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); + } + + [HttpGet("{orderId}")] + public async Task> GetOrderWithStatus(int orderId) + { + var order = await _db.Orders + .Where(o => o.OrderId == orderId) + // .Where(o => o.UserId == GetUserId()) + .Include(o => o.DeliveryLocation) + .Include(o => o.Pizzas).ThenInclude(p => p.Special) + .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) + .SingleOrDefaultAsync(); + + if (order == null) + { + return NotFound(); + } + + return OrderWithStatus.FromOrder(order); + } + + [HttpPost] + public async Task> PlaceOrder(Order order) + { + order.CreatedTime = DateTime.Now; + order.DeliveryLocation = new LatLong(51.5001, -0.1239); + // order.UserId = GetUserId(); + + // Enforce existence of Pizza.SpecialId and Topping.ToppingId + // in the database - prevent the submitter from making up + // new specials and toppings + foreach (var pizza in order.Pizzas) + { + pizza.SpecialId = pizza.Special.Id; + pizza.Special = null; + + foreach (var topping in pizza.Toppings) + { + topping.ToppingId = topping.Topping.Id; + topping.Topping = null; + } + } + + _db.Orders.Attach(order); + await _db.SaveChangesAsync(); + + // In the background, send push notifications if possible + var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); + if (subscription != null) + { + _ = TrackAndSendNotificationsAsync(order, subscription); + } + + return order.OrderId; + } + + private string GetUserId() + { + return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); + } + + private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription subscription) + { + // In a realistic case, some other backend process would track + // order delivery progress and send us notifications when it + // changes. Since we don't have any such process here, fake it. + await Task.Delay(OrderWithStatus.PreparationDuration); + await SendNotificationAsync(order, subscription, "Your order has been dispatched!"); + + await Task.Delay(OrderWithStatus.DeliveryDuration); + await SendNotificationAsync(order, subscription, "Your order is now delivered. Enjoy!"); + } + + private static Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) + { + // This will be implemented later + return Task.CompletedTask; + } +} \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/PizzaApiExtensions.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/PizzaApiExtensions.cs new file mode 100644 index 00000000..bf6b7bde --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/PizzaApiExtensions.cs @@ -0,0 +1,60 @@ +using System.Security.Claims; +using Microsoft.AspNetCore.Authorization; +using Microsoft.EntityFrameworkCore; + +namespace BlazingPizza.Server; + +public static class PizzaApiExtensions +{ + + public static WebApplication MapPizzaApi(this WebApplication app) + { + + // Subscribe to notifications + app.MapPut("/notifications/subscribe", [Authorize] async ( + HttpContext context, + PizzaStoreContext db, + NotificationSubscription subscription) => + { + + // We're storing at most one subscription per user, so delete old ones. + // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. + var userId = GetUserId(context); + var oldSubscriptions = db.NotificationSubscriptions.Where(e => e.UserId == userId); + db.NotificationSubscriptions.RemoveRange(oldSubscriptions); + + // Store new subscription + subscription.UserId = userId; + db.NotificationSubscriptions.Attach(subscription); + + await db.SaveChangesAsync(); + return Results.Ok(subscription); + + }); + + // Specials + app.MapGet("/specials", async (PizzaStoreContext db) => + { + + var specials = await db.Specials.ToListAsync(); + return Results.Ok(specials); + + }); + + // Toppings + app.MapGet("/toppings", async (PizzaStoreContext db) => + { + var toppings = await db.Toppings.OrderBy(t => t.Name).ToListAsync(); + return Results.Ok(toppings); + }); + + return app; + + } + + private static string GetUserId(HttpContext context) + { + return context.User.FindFirstValue(ClaimTypes.NameIdentifier); + } + +} \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/PizzaStoreContext.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/PizzaStoreContext.cs index 9485bd12..992baa19 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Server/PizzaStoreContext.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/PizzaStoreContext.cs @@ -1,39 +1,38 @@ -using Duende.IdentityServer.EntityFramework.Options; +using Duende.IdentityServer.EntityFramework.Options; using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class PizzaStoreContext : ApiAuthorizationDbContext { - public class PizzaStoreContext : ApiAuthorizationDbContext - { - public PizzaStoreContext( - DbContextOptions options, - IOptions operationalStoreOptions) : base(options, operationalStoreOptions) - { - } + public PizzaStoreContext( + DbContextOptions options, + IOptions operationalStoreOptions) : base(options, operationalStoreOptions) + { + } - public DbSet Orders { get; set; } + public DbSet Orders { get; set; } - public DbSet Pizzas { get; set; } + public DbSet Pizzas { get; set; } - public DbSet Specials { get; set; } + public DbSet Specials { get; set; } - public DbSet Toppings { get; set; } + public DbSet Toppings { get; set; } - public DbSet NotificationSubscriptions { get; set; } + public DbSet NotificationSubscriptions { get; set; } - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - base.OnModelCreating(modelBuilder); + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); - // Configuring a many-to-many special -> topping relationship that is friendly for serialization - modelBuilder.Entity().HasKey(pst => new { pst.PizzaId, pst.ToppingId }); - modelBuilder.Entity().HasOne().WithMany(ps => ps.Toppings); - modelBuilder.Entity().HasOne(pst => pst.Topping).WithMany(); + // Configuring a many-to-many special -> topping relationship that is friendly for serialization + modelBuilder.Entity().HasKey(pst => new { pst.PizzaId, pst.ToppingId }); + modelBuilder.Entity().HasOne().WithMany(ps => ps.Toppings); + modelBuilder.Entity().HasOne(pst => pst.Topping).WithMany(); - // Inline the Lat-Long pairs in Order rather than having a FK to another table - modelBuilder.Entity().OwnsOne(o => o.DeliveryLocation); - } - } -} \ No newline at end of file + // Inline the Lat-Long pairs in Order rather than having a FK to another table + modelBuilder.Entity().OwnsOne(o => o.DeliveryLocation); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/PizzasController.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/PizzasController.cs deleted file mode 100644 index c082552c..00000000 --- a/save-points/01-Components-and-layout/BlazingPizza.Server/PizzasController.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("pizzas")] - [ApiController] - public class PizzasController : Controller - { - private readonly PizzaStoreContext _db; - - public PizzasController(PizzaStoreContext db) - { - _db = db; - } - } -} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Program.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Program.cs index 40a47641..4484d8f7 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Server/Program.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Program.cs @@ -1,33 +1,67 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; +using Microsoft.AspNetCore.Authentication; +using Microsoft.EntityFrameworkCore; +using BlazingPizza.Server; -namespace BlazingPizza.Server +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddControllersWithViews() + .AddJsonOptions(options => { + options.JsonSerializerOptions.AddContext(); + }); +builder.Services.AddRazorPages(); + +builder.Services.AddDbContext(options => + options.UseSqlite("Data Source=pizza.db") + .UseModel(BlazingPizza.Server.Models.PizzaStoreContextModel.Instance)); + +builder.Services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) + .AddEntityFrameworkStores(); + +builder.Services.AddIdentityServer() + .AddApiAuthorization(); + +builder.Services.AddAuthentication() + .AddIdentityServerJwt(); + +var app = builder.Build(); + +// Initialize the database +var scopeFactory = app.Services.GetRequiredService(); +using (var scope = scopeFactory.CreateScope()) +{ + var db = scope.ServiceProvider.GetRequiredService(); + if (db.Database.EnsureCreated()) + { + SeedData.Initialize(db); + } +} + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseWebAssemblyDebugging(); +} +else { - public class Program - { - public static void Main(string[] args) - { - var host = CreateHostBuilder(args).Build(); - - // Initialize the database - var scopeFactory = host.Services.GetRequiredService(); - using (var scope = scopeFactory.CreateScope()) - { - var db = scope.ServiceProvider.GetRequiredService(); - if (db.Database.EnsureCreated()) - { - SeedData.Initialize(db); - } - } - - host.Run(); - } - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); - } + app.UseExceptionHandler("/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); } + +app.UseHttpsRedirection(); +app.UseBlazorFrameworkFiles(); +app.UseStaticFiles(); + +app.UseRouting(); + +app.UseAuthentication(); +app.UseIdentityServer(); +app.UseAuthorization(); + +app.MapPizzaApi(); + +app.MapRazorPages(); +app.MapControllers(); +app.MapFallbackToFile("index.html"); + +app.Run(); \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/SeedData.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/SeedData.cs index 7c86a5b2..a1e47973 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Server/SeedData.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/SeedData.cs @@ -1,193 +1,192 @@ -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public static class SeedData { - public static class SeedData - { - public static void Initialize(PizzaStoreContext db) - { - var toppings = new Topping[] - { - new Topping() - { - Name = "Extra cheese", - Price = 2.50m, - }, - new Topping() - { - Name = "American bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "British bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "Canadian bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "Tea and crumpets", - Price = 5.00m - }, - new Topping() - { - Name = "Fresh-baked scones", - Price = 4.50m, - }, - new Topping() - { - Name = "Bell peppers", - Price = 1.00m, - }, - new Topping() - { - Name = "Onions", - Price = 1.00m, - }, - new Topping() - { - Name = "Mushrooms", - Price = 1.00m, - }, - new Topping() - { - Name = "Pepperoni", - Price = 1.00m, - }, - new Topping() - { - Name = "Duck sausage", - Price = 3.20m, - }, - new Topping() - { - Name = "Venison meatballs", - Price = 2.50m, - }, - new Topping() - { - Name = "Served on a silver platter", - Price = 250.99m, - }, - new Topping() - { - Name = "Lobster on top", - Price = 64.50m, - }, - new Topping() - { - Name = "Sturgeon caviar", - Price = 101.75m, - }, - new Topping() - { - Name = "Artichoke hearts", - Price = 3.40m, - }, - new Topping() - { - Name = "Fresh tomatoes", - Price = 1.50m, - }, - new Topping() - { - Name = "Basil", - Price = 1.50m, - }, - new Topping() - { - Name = "Steak (medium-rare)", - Price = 8.50m, - }, - new Topping() - { - Name = "Blazing hot peppers", - Price = 4.20m, - }, - new Topping() - { - Name = "Buffalo chicken", - Price = 5.00m, - }, - new Topping() - { - Name = "Blue cheese", - Price = 2.50m, - }, - }; + public static void Initialize(PizzaStoreContext db) + { + var toppings = new Topping[] + { + new Topping() + { + Name = "Extra cheese", + Price = 2.50m, + }, + new Topping() + { + Name = "American bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "British bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "Canadian bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "Tea and crumpets", + Price = 5.00m + }, + new Topping() + { + Name = "Fresh-baked scones", + Price = 4.50m, + }, + new Topping() + { + Name = "Bell peppers", + Price = 1.00m, + }, + new Topping() + { + Name = "Onions", + Price = 1.00m, + }, + new Topping() + { + Name = "Mushrooms", + Price = 1.00m, + }, + new Topping() + { + Name = "Pepperoni", + Price = 1.00m, + }, + new Topping() + { + Name = "Duck sausage", + Price = 3.20m, + }, + new Topping() + { + Name = "Venison meatballs", + Price = 2.50m, + }, + new Topping() + { + Name = "Served on a silver platter", + Price = 250.99m, + }, + new Topping() + { + Name = "Lobster on top", + Price = 64.50m, + }, + new Topping() + { + Name = "Sturgeon caviar", + Price = 101.75m, + }, + new Topping() + { + Name = "Artichoke hearts", + Price = 3.40m, + }, + new Topping() + { + Name = "Fresh tomatoes", + Price = 1.50m, + }, + new Topping() + { + Name = "Basil", + Price = 1.50m, + }, + new Topping() + { + Name = "Steak (medium-rare)", + Price = 8.50m, + }, + new Topping() + { + Name = "Blazing hot peppers", + Price = 4.20m, + }, + new Topping() + { + Name = "Buffalo chicken", + Price = 5.00m, + }, + new Topping() + { + Name = "Blue cheese", + Price = 2.50m, + }, + }; - var specials = new PizzaSpecial[] - { - new PizzaSpecial() - { - Name = "Basic Cheese Pizza", - Description = "It's cheesy and delicious. Why wouldn't you want one?", - BasePrice = 9.99m, - ImageUrl = "img/pizzas/cheese.jpg", - }, - new PizzaSpecial() - { - Id = 2, - Name = "The Baconatorizor", - Description = "It has EVERY kind of bacon", - BasePrice = 11.99m, - ImageUrl = "img/pizzas/bacon.jpg", - }, - new PizzaSpecial() - { - Id = 3, - Name = "Classic pepperoni", - Description = "It's the pizza you grew up with, but Blazing hot!", - BasePrice = 10.50m, - ImageUrl = "img/pizzas/pepperoni.jpg", - }, - new PizzaSpecial() - { - Id = 4, - Name = "Buffalo chicken", - Description = "Spicy chicken, hot sauce and bleu cheese, guaranteed to warm you up", - BasePrice = 12.75m, - ImageUrl = "img/pizzas/meaty.jpg", - }, - new PizzaSpecial() - { - Id = 5, - Name = "Mushroom Lovers", - Description = "It has mushrooms. Isn't that obvious?", - BasePrice = 11.00m, - ImageUrl = "img/pizzas/mushroom.jpg", - }, - new PizzaSpecial() - { - Id = 6, - Name = "The Brit", - Description = "When in London...", - BasePrice = 10.25m, - ImageUrl = "img/pizzas/brit.jpg", - }, - new PizzaSpecial() - { - Id = 7, - Name = "Veggie Delight", - Description = "It's like salad, but on a pizza", - BasePrice = 11.50m, - ImageUrl = "img/pizzas/salad.jpg", - }, - new PizzaSpecial() - { - Id = 8, - Name = "Margherita", - Description = "Traditional Italian pizza with tomatoes and basil", - BasePrice = 9.99m, - ImageUrl = "img/pizzas/margherita.jpg", - }, - }; + var specials = new PizzaSpecial[] + { + new PizzaSpecial() + { + Name = "Basic Cheese Pizza", + Description = "It's cheesy and delicious. Why wouldn't you want one?", + BasePrice = 9.99m, + ImageUrl = "img/pizzas/cheese.jpg", + }, + new PizzaSpecial() + { + Id = 2, + Name = "The Baconatorizor", + Description = "It has EVERY kind of bacon", + BasePrice = 11.99m, + ImageUrl = "img/pizzas/bacon.jpg", + }, + new PizzaSpecial() + { + Id = 3, + Name = "Classic pepperoni", + Description = "It's the pizza you grew up with, but Blazing hot!", + BasePrice = 10.50m, + ImageUrl = "img/pizzas/pepperoni.jpg", + }, + new PizzaSpecial() + { + Id = 4, + Name = "Buffalo chicken", + Description = "Spicy chicken, hot sauce and bleu cheese, guaranteed to warm you up", + BasePrice = 12.75m, + ImageUrl = "img/pizzas/meaty.jpg", + }, + new PizzaSpecial() + { + Id = 5, + Name = "Mushroom Lovers", + Description = "It has mushrooms. Isn't that obvious?", + BasePrice = 11.00m, + ImageUrl = "img/pizzas/mushroom.jpg", + }, + new PizzaSpecial() + { + Id = 6, + Name = "The Brit", + Description = "When in London...", + BasePrice = 10.25m, + ImageUrl = "img/pizzas/brit.jpg", + }, + new PizzaSpecial() + { + Id = 7, + Name = "Veggie Delight", + Description = "It's like salad, but on a pizza", + BasePrice = 11.50m, + ImageUrl = "img/pizzas/salad.jpg", + }, + new PizzaSpecial() + { + Id = 8, + Name = "Margherita", + Description = "Traditional Italian pizza with tomatoes and basil", + BasePrice = 9.99m, + ImageUrl = "img/pizzas/margherita.jpg", + }, + }; - db.Toppings.AddRange(toppings); - db.Specials.AddRange(specials); - db.SaveChanges(); - } - } -} + db.Toppings.AddRange(toppings); + db.Specials.AddRange(specials); + db.SaveChanges(); + } +} \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/SpecialsController.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/SpecialsController.cs deleted file mode 100644 index a176844c..00000000 --- a/save-points/01-Components-and-layout/BlazingPizza.Server/SpecialsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("specials")] - [ApiController] - public class SpecialsController : Controller - { - private readonly PizzaStoreContext _db; - - public SpecialsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetSpecials() - { - return (await _db.Specials.ToListAsync()).OrderByDescending(s => s.BasePrice).ToList(); - } - } -} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Startup.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Startup.cs deleted file mode 100644 index 7c4656a7..00000000 --- a/save-points/01-Components-and-layout/BlazingPizza.Server/Startup.cs +++ /dev/null @@ -1,71 +0,0 @@ -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace BlazingPizza.Server -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - public void ConfigureServices(IServiceCollection services) - { - services.AddControllersWithViews(); - services.AddRazorPages(); - - - services.AddDbContext(options => - options.UseSqlite("Data Source=pizza.db")); - - services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) - .AddEntityFrameworkStores(); - - services.AddIdentityServer() - .AddApiAuthorization(); - - services.AddAuthentication() - .AddIdentityServerJwt(); - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - app.UseWebAssemblyDebugging(); - } - else - { - app.UseExceptionHandler("/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); - } - - app.UseHttpsRedirection(); - app.UseBlazorFrameworkFiles(); - app.UseStaticFiles(); - - app.UseRouting(); - - app.UseAuthentication(); - app.UseIdentityServer(); - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - endpoints.MapRazorPages(); - endpoints.MapFallbackToFile("index.html"); - }); - } - } -} \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/ToppingsController.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/ToppingsController.cs deleted file mode 100644 index 6a677639..00000000 --- a/save-points/01-Components-and-layout/BlazingPizza.Server/ToppingsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("toppings")] - [ApiController] - public class ToppingsController : Controller - { - private readonly PizzaStoreContext _db; - - public ToppingsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetToppings() - { - return await _db.Toppings.OrderBy(t => t.Name).ToListAsync(); - } - } -} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Shared/Address.cs b/save-points/01-Components-and-layout/BlazingPizza.Shared/Address.cs index e5c0ef0d..79be9c5b 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Shared/Address.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Shared/Address.cs @@ -1,21 +1,24 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class Address { - public class Address - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + [Required, MaxLength(100)] + public string Name { get; set; } - public string Line1 { get; set; } + [Required, MaxLength(100)] + public string Line1 { get; set; } - public string Line2 { get; set; } + [MaxLength(100)] + public string Line2 { get; set; } - public string City { get; set; } + [Required, MaxLength(50)] + public string City { get; set; } - public string Region { get; set; } + [Required, MaxLength(20)] + public string Region { get; set; } - public string PostalCode { get; set; } - } + [Required, MaxLength(20)] + public string PostalCode { get; set; } } diff --git a/save-points/01-Components-and-layout/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/save-points/01-Components-and-layout/BlazingPizza.Shared/BlazingPizza.Shared.csproj index f7b7dd02..fb17e53b 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/save-points/01-Components-and-layout/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -3,8 +3,13 @@ $(TargetFrameworkVersion) BlazingPizza + true + + + + diff --git a/save-points/01-Components-and-layout/BlazingPizza.Shared/LatLong.cs b/save-points/01-Components-and-layout/BlazingPizza.Shared/LatLong.cs index 9b8c3811..14a94c26 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Shared/LatLong.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Shared/LatLong.cs @@ -1,27 +1,26 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class LatLong { - public class LatLong - { - public LatLong() - { - } + public LatLong() + { + } - public LatLong(double latitude, double longitude) : this() - { - Latitude = latitude; - Longitude = longitude; - } + public LatLong(double latitude, double longitude) : this() + { + Latitude = latitude; + Longitude = longitude; + } - public double Latitude { get; set; } + public double Latitude { get; set; } - public double Longitude { get; set; } + public double Longitude { get; set; } - public static LatLong Interpolate(LatLong start, LatLong end, double proportion) - { - // The Earth is flat, right? So no need for spherical interpolation. - return new LatLong( - start.Latitude + (end.Latitude - start.Latitude) * proportion, - start.Longitude + (end.Longitude - start.Longitude) * proportion); - } - } -} + public static LatLong Interpolate(LatLong start, LatLong end, double proportion) + { + // The Earth is flat, right? So no need for spherical interpolation. + return new LatLong( + start.Latitude + (end.Latitude - start.Latitude) * proportion, + start.Longitude + (end.Longitude - start.Longitude) * proportion); + } +} \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Shared/NotificationSubscription.cs b/save-points/01-Components-and-layout/BlazingPizza.Shared/NotificationSubscription.cs index 04259c2f..9109ff57 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Shared/NotificationSubscription.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Shared/NotificationSubscription.cs @@ -1,17 +1,14 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class NotificationSubscription { - public class NotificationSubscription - { - public int NotificationSubscriptionId { get; set; } + public int NotificationSubscriptionId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public string Url { get; set; } + public string Url { get; set; } - public string P256dh { get; set; } + public string P256dh { get; set; } - public string Auth { get; set; } - } + public string Auth { get; set; } } diff --git a/save-points/01-Components-and-layout/BlazingPizza.Shared/Order.cs b/save-points/01-Components-and-layout/BlazingPizza.Shared/Order.cs index fb003bd6..aca04ca1 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Shared/Order.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Shared/Order.cs @@ -1,25 +1,32 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +public class Order { - public class Order - { - public int OrderId { get; set; } + public int OrderId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public DateTime CreatedTime { get; set; } + public DateTime CreatedTime { get; set; } - public Address DeliveryAddress { get; set; } = new Address(); + public Address DeliveryAddress { get; set; } = new Address(); - public LatLong DeliveryLocation { get; set; } + public LatLong DeliveryLocation { get; set; } - public List Pizzas { get; set; } = new List(); + public List Pizzas { get; set; } = new List(); - public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); + public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); - public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); - } + public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Default, PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] +[JsonSerializable(typeof(Order))] +[JsonSerializable(typeof(OrderWithStatus))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Pizza))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Topping))] +public partial class OrderContext : JsonSerializerContext {} \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Shared/OrderWithStatus.cs b/save-points/01-Components-and-layout/BlazingPizza.Shared/OrderWithStatus.cs index 021de78c..f5f153b6 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Shared/OrderWithStatus.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Shared/OrderWithStatus.cs @@ -1,79 +1,78 @@ -using BlazingPizza.ComponentsLibrary.Map; -using System; -using System.Collections.Generic; +using System.Text.Json.Serialization; +using BlazingPizza.ComponentsLibrary.Map; -namespace BlazingPizza + +namespace BlazingPizza; + +public class OrderWithStatus { - public class OrderWithStatus - { - public readonly static TimeSpan PreparationDuration = TimeSpan.FromSeconds(10); - public readonly static TimeSpan DeliveryDuration = TimeSpan.FromMinutes(1); // Unrealistic, but more interesting to watch + public readonly static TimeSpan PreparationDuration = TimeSpan.FromSeconds(10); + public readonly static TimeSpan DeliveryDuration = TimeSpan.FromMinutes(1); // Unrealistic, but more interesting to watch - public Order Order { get; set; } + public Order Order { get; set; } - public string StatusText { get; set; } + public string StatusText { get; set; } - public bool IsDelivered => StatusText == "Delivered"; + public bool IsDelivered => StatusText == "Delivered"; - public List MapMarkers { get; set; } + public List MapMarkers { get; set; } - public static OrderWithStatus FromOrder(Order order) - { - // To simulate a real backend process, we fake status updates based on the amount - // of time since the order was placed - string statusText; - List mapMarkers; - var dispatchTime = order.CreatedTime.Add(PreparationDuration); + public static OrderWithStatus FromOrder(Order order) + { + // To simulate a real backend process, we fake status updates based on the amount + // of time since the order was placed + string statusText; + List mapMarkers; + var dispatchTime = order.CreatedTime.Add(PreparationDuration); - if (DateTime.Now < dispatchTime) - { - statusText = "Preparing"; - mapMarkers = new List - { - ToMapMarker("You", order.DeliveryLocation, showPopup: true) - }; - } - else if (DateTime.Now < dispatchTime + DeliveryDuration) - { - statusText = "Out for delivery"; + if (DateTime.Now < dispatchTime) + { + statusText = "Preparing"; + mapMarkers = new List + { + ToMapMarker("You", order.DeliveryLocation, showPopup: true) + }; + } + else if (DateTime.Now < dispatchTime + DeliveryDuration) + { + statusText = "Out for delivery"; - var startPosition = ComputeStartPosition(order); - var proportionOfDeliveryCompleted = Math.Min(1, (DateTime.Now - dispatchTime).TotalMilliseconds / DeliveryDuration.TotalMilliseconds); - var driverPosition = LatLong.Interpolate(startPosition, order.DeliveryLocation, proportionOfDeliveryCompleted); - mapMarkers = new List - { - ToMapMarker("You", order.DeliveryLocation), - ToMapMarker("Driver", driverPosition, showPopup: true), - }; - } - else - { - statusText = "Delivered"; - mapMarkers = new List - { - ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), - }; - } + var startPosition = ComputeStartPosition(order); + var proportionOfDeliveryCompleted = Math.Min(1, (DateTime.Now - dispatchTime).TotalMilliseconds / DeliveryDuration.TotalMilliseconds); + var driverPosition = LatLong.Interpolate(startPosition, order.DeliveryLocation, proportionOfDeliveryCompleted); + mapMarkers = new List + { + ToMapMarker("You", order.DeliveryLocation), + ToMapMarker("Driver", driverPosition, showPopup: true), + }; + } + else + { + statusText = "Delivered"; + mapMarkers = new List + { + ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), + }; + } - return new OrderWithStatus - { - Order = order, - StatusText = statusText, - MapMarkers = mapMarkers, - }; - } + return new OrderWithStatus + { + Order = order, + StatusText = statusText, + MapMarkers = mapMarkers, + }; + } - private static LatLong ComputeStartPosition(Order order) - { - // Random but deterministic based on order ID - var rng = new Random(order.OrderId); - var distance = 0.01 + rng.NextDouble() * 0.02; - var angle = rng.NextDouble() * Math.PI * 2; - var offset = (distance * Math.Cos(angle), distance * Math.Sin(angle)); - return new LatLong(order.DeliveryLocation.Latitude + offset.Item1, order.DeliveryLocation.Longitude + offset.Item2); - } + private static LatLong ComputeStartPosition(Order order) + { + // Random but deterministic based on order ID + var rng = new Random(order.OrderId); + var distance = 0.01 + rng.NextDouble() * 0.02; + var angle = rng.NextDouble() * Math.PI * 2; + var offset = (distance * Math.Cos(angle), distance * Math.Sin(angle)); + return new LatLong(order.DeliveryLocation.Latitude + offset.Item1, order.DeliveryLocation.Longitude + offset.Item2); + } - static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) - => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; - } -} + static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) + => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; +} \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Shared/Pizza.cs b/save-points/01-Components-and-layout/BlazingPizza.Shared/Pizza.cs index ec1108a9..459298f4 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Shared/Pizza.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Shared/Pizza.cs @@ -1,42 +1,44 @@ -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// /// Represents a customized pizza as part of an order +/// +public class Pizza { - /// - /// Represents a customized pizza as part of an order - /// - public class Pizza - { - public const int DefaultSize = 12; - public const int MinimumSize = 9; - public const int MaximumSize = 17; + public const int DefaultSize = 12; + public const int MinimumSize = 9; + public const int MaximumSize = 17; - public int Id { get; set; } + public int Id { get; set; } - public int OrderId { get; set; } + public int OrderId { get; set; } - public PizzaSpecial Special { get; set; } + public PizzaSpecial Special { get; set; } - public int SpecialId { get; set; } + public int SpecialId { get; set; } - public int Size { get; set; } + public int Size { get; set; } - public List Toppings { get; set; } + public List Toppings { get; set; } - public decimal GetBasePrice() - { - return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; - } + public decimal GetBasePrice() + { + return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; + } - public decimal GetTotalPrice() - { - return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); - } + public decimal GetTotalPrice() + { + return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); + } - public string GetFormattedTotalPrice() - { - return GetTotalPrice().ToString("0.00"); - } - } + public string GetFormattedTotalPrice() + { + return GetTotalPrice().ToString("0.00"); + } } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Serialization)] +[JsonSerializable(typeof(Pizza))] +public partial class PizzaContext : JsonSerializerContext {} \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Shared/PizzaSpecial.cs b/save-points/01-Components-and-layout/BlazingPizza.Shared/PizzaSpecial.cs index 2f2b3383..9653300c 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Shared/PizzaSpecial.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Shared/PizzaSpecial.cs @@ -1,20 +1,19 @@ -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// Represents a pre-configured template for a pizza a user can order +/// +public class PizzaSpecial { - /// - /// Represents a pre-configured template for a pizza a user can order - /// - public class PizzaSpecial - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal BasePrice { get; set; } + public decimal BasePrice { get; set; } - public string Description { get; set; } + public string Description { get; set; } - public string ImageUrl { get; set; } + public string ImageUrl { get; set; } - public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); - } -} + public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); +} \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Shared/PizzaTopping.cs b/save-points/01-Components-and-layout/BlazingPizza.Shared/PizzaTopping.cs index f5a6c1ac..0a711647 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Shared/PizzaTopping.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Shared/PizzaTopping.cs @@ -1,11 +1,11 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class PizzaTopping { - public class PizzaTopping - { - public Topping Topping { get; set; } + public Topping Topping { get; set; } + + public int ToppingId { get; set; } - public int ToppingId { get; set; } - - public int PizzaId { get; set; } - } -} + public int PizzaId { get; set; } + +} \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Shared/Topping.cs b/save-points/01-Components-and-layout/BlazingPizza.Shared/Topping.cs index 61bdeb92..376c311a 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Shared/Topping.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Shared/Topping.cs @@ -1,13 +1,13 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class Topping { - public class Topping - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal Price { get; set; } + public decimal Price { get; set; } - public string GetFormattedPrice() => Price.ToString("0.00"); - } -} + public string GetFormattedPrice() => Price.ToString("0.00"); + +} \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Shared/UserInfo.cs b/save-points/01-Components-and-layout/BlazingPizza.Shared/UserInfo.cs index 4996ef80..362f8f8e 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Shared/UserInfo.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Shared/UserInfo.cs @@ -1,9 +1,9 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class UserInfo { - public class UserInfo - { - public bool IsAuthenticated { get; set; } + public bool IsAuthenticated { get; set; } - public string Name { get; set; } - } -} + public string Name { get; set; } + +} \ No newline at end of file From 2ef41963f6b4be3e9b2feaf510a350b95a35efd0 Mon Sep 17 00:00:00 2001 From: "Jeffrey T. Fritz" Date: Thu, 3 Mar 2022 14:43:42 -0500 Subject: [PATCH 11/20] Updated savepoint 2, 3, 4, 5, 6, 7, 8, 9 --- .../Map/Marker.cs | 17 +- .../Map/Point.cs | 13 +- .../Map/Marker.cs | 16 +- .../Map/Point.cs | 12 +- .../BlazingPizza.Server/PizzaStoreUser.cs | 6 +- .../BlazingPizza.Client.csproj | 1 + .../BlazingPizza.Client/Program.cs | 24 +- .../BlazingPizza.ComponentsLibrary.csproj | 1 + .../LocalStorage.cs | 24 +- .../BlazingPizza.Server.csproj | 1 + .../Models/AddressEntityType.cs | 92 +++++ .../Models/DeviceFlowCodesEntityType.cs | 114 ++++++ .../IdentityRoleClaimstringEntityType.cs | 85 ++++ .../Models/IdentityRoleEntityType.cs | 78 ++++ .../IdentityUserClaimstringEntityType.cs | 85 ++++ .../IdentityUserLoginstringEntityType.cs | 86 ++++ .../IdentityUserRolestringEntityType.cs | 82 ++++ .../IdentityUserTokenstringEntityType.cs | 84 ++++ .../Models/KeyEntityType.cs | 96 +++++ .../Models/LatLongEntityType.cs | 80 ++++ .../NotificationSubscriptionEntityType.cs | 77 ++++ .../Models/OrderEntityType.cs | 86 ++++ .../Models/PersistedGrantEntityType.cs | 127 ++++++ .../Models/PizzaEntityType.cs | 111 +++++ .../Models/PizzaSpecialEntityType.cs | 76 ++++ .../Models/PizzaStoreContextModel.cs | 28 ++ .../Models/PizzaStoreContextModelBuilder.cs | 69 ++++ .../Models/PizzaStoreUserEntityType.cs | 156 +++++++ .../Models/PizzaToppingEntityType.cs | 96 +++++ .../Models/ToppingEntityType.cs | 62 +++ .../NotificationsController.cs | 43 -- .../OidcConfigurationController.cs | 35 +- .../BlazingPizza.Server/OrdersController.cs | 215 +++++----- .../BlazingPizza.Server/PizzaApiExtensions.cs | 60 +++ .../BlazingPizza.Server/PizzaStoreContext.cs | 49 ++- .../BlazingPizza.Server/PizzaStoreUser.cs | 6 +- .../BlazingPizza.Server/PizzasController.cs | 16 - .../BlazingPizza.Server/Program.cs | 94 +++-- .../BlazingPizza.Server/SeedData.cs | 379 +++++++++--------- .../BlazingPizza.Shared/Address.cs | 27 +- .../BlazingPizza.Shared.csproj | 1 + .../BlazingPizza.Shared/LatLong.cs | 43 +- .../NotificationSubscription.cs | 17 +- .../BlazingPizza.Shared/Order.cs | 37 +- .../BlazingPizza.Shared/OrderWithStatus.cs | 133 +++--- .../BlazingPizza.Shared/Pizza.cs | 62 +-- .../BlazingPizza.Shared/PizzaSpecial.cs | 27 +- .../BlazingPizza.Shared/PizzaTopping.cs | 18 +- .../BlazingPizza.Shared/Topping.cs | 18 +- .../BlazingPizza.Shared/UserInfo.cs | 14 +- .../BlazingPizza.Client.csproj | 1 + .../BlazingPizza.Client/Program.cs | 24 +- .../BlazingPizza.ComponentsLibrary.csproj | 1 + .../LocalStorage.cs | 22 +- .../Map/Marker.cs | 15 +- .../Map/Point.cs | 13 +- .../BlazingPizza.Server.csproj | 1 + .../Models/AddressEntityType.cs | 92 +++++ .../Models/DeviceFlowCodesEntityType.cs | 114 ++++++ .../IdentityRoleClaimstringEntityType.cs | 85 ++++ .../Models/IdentityRoleEntityType.cs | 78 ++++ .../IdentityUserClaimstringEntityType.cs | 85 ++++ .../IdentityUserLoginstringEntityType.cs | 86 ++++ .../IdentityUserRolestringEntityType.cs | 82 ++++ .../IdentityUserTokenstringEntityType.cs | 84 ++++ .../Models/KeyEntityType.cs | 96 +++++ .../Models/LatLongEntityType.cs | 80 ++++ .../NotificationSubscriptionEntityType.cs | 77 ++++ .../Models/OrderEntityType.cs | 86 ++++ .../Models/PersistedGrantEntityType.cs | 127 ++++++ .../Models/PizzaEntityType.cs | 111 +++++ .../Models/PizzaSpecialEntityType.cs | 76 ++++ .../Models/PizzaStoreContextModel.cs | 28 ++ .../Models/PizzaStoreContextModelBuilder.cs | 69 ++++ .../Models/PizzaStoreUserEntityType.cs | 156 +++++++ .../Models/PizzaToppingEntityType.cs | 96 +++++ .../Models/ToppingEntityType.cs | 62 +++ .../NotificationsController.cs | 43 -- .../OidcConfigurationController.cs | 35 +- .../BlazingPizza.Server/OrdersController.cs | 215 +++++----- .../BlazingPizza.Server/PizzaApiExtensions.cs | 60 +++ .../BlazingPizza.Server/PizzaStoreContext.cs | 49 ++- .../BlazingPizza.Server/PizzaStoreUser.cs | 6 +- .../BlazingPizza.Server/PizzasController.cs | 16 - .../BlazingPizza.Server/Program.cs | 94 +++-- .../BlazingPizza.Server/SeedData.cs | 379 +++++++++--------- .../BlazingPizza.Server/SpecialsController.cs | 26 -- .../BlazingPizza.Server/Startup.cs | 70 ---- .../BlazingPizza.Server/ToppingsController.cs | 26 -- .../BlazingPizza.Shared/Address.cs | 27 +- .../BlazingPizza.Shared.csproj | 1 + .../BlazingPizza.Shared/LatLong.cs | 43 +- .../NotificationSubscription.cs | 17 +- .../BlazingPizza.Shared/Order.cs | 37 +- .../BlazingPizza.Shared/OrderWithStatus.cs | 133 +++--- .../BlazingPizza.Shared/Pizza.cs | 62 +-- .../BlazingPizza.Shared/PizzaSpecial.cs | 27 +- .../BlazingPizza.Shared/PizzaTopping.cs | 18 +- .../BlazingPizza.Shared/Topping.cs | 18 +- .../BlazingPizza.Shared/UserInfo.cs | 14 +- .../BlazingPizza.Client.csproj | 1 + .../BlazingPizza.Client/OrderState.cs | 91 ++--- .../BlazingPizza.Client/Program.cs | 26 +- .../BlazingPizza.ComponentsLibrary.csproj | 1 + .../LocalStorage.cs | 22 +- .../Map/Marker.cs | 15 +- .../Map/Point.cs | 13 +- .../BlazingPizza.Server.csproj | 2 + .../Models/AddressEntityType.cs | 92 +++++ .../Models/DeviceFlowCodesEntityType.cs | 114 ++++++ .../IdentityRoleClaimstringEntityType.cs | 85 ++++ .../Models/IdentityRoleEntityType.cs | 78 ++++ .../IdentityUserClaimstringEntityType.cs | 85 ++++ .../IdentityUserLoginstringEntityType.cs | 86 ++++ .../IdentityUserRolestringEntityType.cs | 82 ++++ .../IdentityUserTokenstringEntityType.cs | 84 ++++ .../Models/KeyEntityType.cs | 96 +++++ .../Models/LatLongEntityType.cs | 80 ++++ .../NotificationSubscriptionEntityType.cs | 77 ++++ .../Models/OrderEntityType.cs | 86 ++++ .../Models/PersistedGrantEntityType.cs | 127 ++++++ .../Models/PizzaEntityType.cs | 111 +++++ .../Models/PizzaSpecialEntityType.cs | 76 ++++ .../Models/PizzaStoreContextModel.cs | 28 ++ .../Models/PizzaStoreContextModelBuilder.cs | 69 ++++ .../Models/PizzaStoreUserEntityType.cs | 156 +++++++ .../Models/PizzaToppingEntityType.cs | 96 +++++ .../Models/ToppingEntityType.cs | 62 +++ .../NotificationsController.cs | 43 -- .../OidcConfigurationController.cs | 33 +- .../BlazingPizza.Server/OrdersController.cs | 234 ++++++----- .../BlazingPizza.Server/PizzaApiExtensions.cs | 60 +++ .../BlazingPizza.Server/PizzaStoreContext.cs | 49 ++- .../BlazingPizza.Server/PizzaStoreUser.cs | 9 +- .../BlazingPizza.Server/PizzasController.cs | 16 - .../BlazingPizza.Server/Program.cs | 94 +++-- .../BlazingPizza.Server/SeedData.cs | 379 +++++++++--------- .../BlazingPizza.Server/SpecialsController.cs | 26 -- .../BlazingPizza.Server/Startup.cs | 70 ---- .../BlazingPizza.Server/ToppingsController.cs | 26 -- .../BlazingPizza.Server/pizza.db-shm | Bin 0 -> 32768 bytes .../BlazingPizza.Server/pizza.db-wal | Bin 0 -> 214272 bytes .../BlazingPizza.Shared/Address.cs | 27 +- .../BlazingPizza.Shared.csproj | 1 + .../BlazingPizza.Shared/LatLong.cs | 43 +- .../NotificationSubscription.cs | 17 +- .../BlazingPizza.Shared/Order.cs | 37 +- .../BlazingPizza.Shared/OrderWithStatus.cs | 133 +++--- .../BlazingPizza.Shared/Pizza.cs | 62 +-- .../BlazingPizza.Shared/PizzaSpecial.cs | 27 +- .../BlazingPizza.Shared/PizzaTopping.cs | 18 +- .../BlazingPizza.Shared/Topping.cs | 18 +- .../BlazingPizza.Shared/UserInfo.cs | 14 +- .../BlazingPizza.Client.csproj | 5 +- .../BlazingPizza.Client/OrderState.cs | 96 ++--- .../BlazingPizza.Client/Program.cs | 24 +- .../BlazingPizza.ComponentsLibrary.csproj | 1 + .../LocalStorage.cs | 22 +- .../Map/Marker.cs | 15 +- .../Map/Point.cs | 13 +- .../BlazingPizza.Server.csproj | 2 + .../NotificationsController.cs | 43 -- .../OidcConfigurationController.cs | 33 +- .../BlazingPizza.Server/OrdersController.cs | 234 ++++++----- .../BlazingPizza.Server/PizzaApiExtensions.cs | 60 +++ .../BlazingPizza.Server/PizzaStoreContext.cs | 49 ++- .../BlazingPizza.Server/PizzaStoreUser.cs | 9 +- .../BlazingPizza.Server/PizzasController.cs | 16 - .../BlazingPizza.Server/Program.cs | 94 +++-- .../BlazingPizza.Server/SeedData.cs | 379 +++++++++--------- .../BlazingPizza.Server/SpecialsController.cs | 26 -- .../BlazingPizza.Server/Startup.cs | 70 ---- .../BlazingPizza.Server/ToppingsController.cs | 26 -- .../BlazingPizza.Shared/Address.cs | 33 +- .../BlazingPizza.Shared.csproj | 5 + .../BlazingPizza.Shared/LatLong.cs | 43 +- .../NotificationSubscription.cs | 17 +- .../BlazingPizza.Shared/Order.cs | 37 +- .../BlazingPizza.Shared/OrderWithStatus.cs | 133 +++--- .../BlazingPizza.Shared/Pizza.cs | 62 +-- .../BlazingPizza.Shared/PizzaSpecial.cs | 27 +- .../BlazingPizza.Shared/PizzaTopping.cs | 18 +- .../BlazingPizza.Shared/Topping.cs | 18 +- .../BlazingPizza.Shared/UserInfo.cs | 14 +- .../BlazingPizza.Client.csproj | 5 +- .../BlazingPizza.Client/OrderState.cs | 101 +++-- .../BlazingPizza.Client/OrdersClient.cs | 51 ++- .../PizzaAuthenticationState.cs | 9 +- .../BlazingPizza.Client/Program.cs | 37 +- .../BlazingPizza.ComponentsLibrary.csproj | 1 + .../LocalStorage.cs | 22 +- .../Map/Marker.cs | 15 +- .../Map/Point.cs | 13 +- .../Models/AddressEntityType.cs | 92 +++++ .../Models/DeviceFlowCodesEntityType.cs | 114 ++++++ .../IdentityRoleClaimstringEntityType.cs | 85 ++++ .../Models/IdentityRoleEntityType.cs | 78 ++++ .../IdentityUserClaimstringEntityType.cs | 85 ++++ .../IdentityUserLoginstringEntityType.cs | 86 ++++ .../IdentityUserRolestringEntityType.cs | 82 ++++ .../IdentityUserTokenstringEntityType.cs | 84 ++++ .../Models/KeyEntityType.cs | 96 +++++ .../Models/LatLongEntityType.cs | 80 ++++ .../NotificationSubscriptionEntityType.cs | 77 ++++ .../Models/OrderEntityType.cs | 86 ++++ .../Models/PersistedGrantEntityType.cs | 127 ++++++ .../Models/PizzaEntityType.cs | 111 +++++ .../Models/PizzaSpecialEntityType.cs | 76 ++++ .../Models/PizzaStoreContextModel.cs | 28 ++ .../Models/PizzaStoreContextModelBuilder.cs | 69 ++++ .../Models/PizzaStoreUserEntityType.cs | 156 +++++++ .../Models/PizzaToppingEntityType.cs | 96 +++++ .../Models/ToppingEntityType.cs | 62 +++ .../BlazingPizza.Server/SeedData.cs | 379 +++++++++--------- .../BlazingPizza.Server/SpecialsController.cs | 26 -- .../BlazingPizza.Server/Startup.cs | 70 ---- .../BlazingPizza.Server/ToppingsController.cs | 26 -- .../BlazingPizza.Server/pizza.db-shm | Bin 0 -> 32768 bytes .../BlazingPizza.Server/pizza.db-wal | Bin 0 -> 226632 bytes .../BlazingPizza.Shared/Address.cs | 33 +- .../BlazingPizza.Shared.csproj | 5 + .../BlazingPizza.Shared/LatLong.cs | 43 +- .../NotificationSubscription.cs | 17 +- .../BlazingPizza.Shared/Order.cs | 37 +- .../BlazingPizza.Shared/OrderWithStatus.cs | 133 +++--- .../BlazingPizza.Shared/Pizza.cs | 62 +-- .../BlazingPizza.Shared/PizzaSpecial.cs | 27 +- .../BlazingPizza.Shared/PizzaTopping.cs | 18 +- .../BlazingPizza.Shared/Topping.cs | 18 +- .../BlazingPizza.Shared/UserInfo.cs | 14 +- .../BlazingPizza.Client.csproj | 5 +- .../JSRuntimeExtensions.cs | 16 +- .../BlazingPizza.Client/OrderState.cs | 101 +++-- .../BlazingPizza.Client/OrdersClient.cs | 57 +-- .../PizzaAuthenticationState.cs | 9 +- .../BlazingPizza.Client/Program.cs | 37 +- .../BlazingPizza.ComponentsLibrary.csproj | 1 + .../LocalStorage.cs | 22 +- .../Map/Marker.cs | 15 +- .../Map/Point.cs | 13 +- .../BlazingPizza.Server.csproj | 2 + .../Models/AddressEntityType.cs | 92 +++++ .../Models/DeviceFlowCodesEntityType.cs | 114 ++++++ .../IdentityRoleClaimstringEntityType.cs | 85 ++++ .../Models/IdentityRoleEntityType.cs | 78 ++++ .../IdentityUserClaimstringEntityType.cs | 85 ++++ .../IdentityUserLoginstringEntityType.cs | 86 ++++ .../IdentityUserRolestringEntityType.cs | 82 ++++ .../IdentityUserTokenstringEntityType.cs | 84 ++++ .../Models/KeyEntityType.cs | 96 +++++ .../Models/LatLongEntityType.cs | 80 ++++ .../NotificationSubscriptionEntityType.cs | 77 ++++ .../Models/OrderEntityType.cs | 86 ++++ .../Models/PersistedGrantEntityType.cs | 127 ++++++ .../Models/PizzaEntityType.cs | 111 +++++ .../Models/PizzaSpecialEntityType.cs | 76 ++++ .../Models/PizzaStoreContextModel.cs | 28 ++ .../Models/PizzaStoreContextModelBuilder.cs | 69 ++++ .../Models/PizzaStoreUserEntityType.cs | 156 +++++++ .../Models/PizzaToppingEntityType.cs | 96 +++++ .../Models/ToppingEntityType.cs | 62 +++ .../NotificationsController.cs | 43 -- .../OidcConfigurationController.cs | 33 +- .../BlazingPizza.Server/OrdersController.cs | 233 ++++++----- .../BlazingPizza.Server/PizzaApiExtensions.cs | 60 +++ .../BlazingPizza.Server/PizzaStoreContext.cs | 49 ++- .../BlazingPizza.Server/PizzaStoreUser.cs | 9 +- .../BlazingPizza.Server/PizzasController.cs | 16 - .../BlazingPizza.Server/Program.cs | 94 +++-- .../BlazingPizza.Server/SeedData.cs | 379 +++++++++--------- .../BlazingPizza.Server/SpecialsController.cs | 26 -- .../BlazingPizza.Server/Startup.cs | 70 ---- .../BlazingPizza.Server/ToppingsController.cs | 26 -- .../BlazingPizza.Shared/Address.cs | 33 +- .../BlazingPizza.Shared.csproj | 5 + .../BlazingPizza.Shared/LatLong.cs | 43 +- .../NotificationSubscription.cs | 17 +- .../BlazingPizza.Shared/Order.cs | 37 +- .../BlazingPizza.Shared/OrderWithStatus.cs | 133 +++--- .../BlazingPizza.Shared/Pizza.cs | 62 +-- .../BlazingPizza.Shared/PizzaSpecial.cs | 27 +- .../BlazingPizza.Shared/PizzaTopping.cs | 18 +- .../BlazingPizza.Shared/Topping.cs | 18 +- .../BlazingPizza.Shared/UserInfo.cs | 14 +- .../BlazingPizza.Client.csproj | 4 +- .../JSRuntimeExtensions.cs | 16 +- .../BlazingPizza.Client/OrderState.cs | 101 +++-- .../BlazingPizza.Client/OrdersClient.cs | 57 +-- .../PizzaAuthenticationState.cs | 9 +- .../BlazingPizza.Client/Program.cs | 37 +- .../BlazingPizza.ComponentsLibrary.csproj | 1 + .../LocalStorage.cs | 22 +- .../Map/Marker.cs | 15 +- .../Map/Point.cs | 13 +- .../BlazingPizza.Server.csproj | 2 + .../Models/AddressEntityType.cs | 92 +++++ .../Models/DeviceFlowCodesEntityType.cs | 114 ++++++ .../IdentityRoleClaimstringEntityType.cs | 85 ++++ .../Models/IdentityRoleEntityType.cs | 78 ++++ .../IdentityUserClaimstringEntityType.cs | 85 ++++ .../IdentityUserLoginstringEntityType.cs | 86 ++++ .../IdentityUserRolestringEntityType.cs | 82 ++++ .../IdentityUserTokenstringEntityType.cs | 84 ++++ .../Models/KeyEntityType.cs | 96 +++++ .../Models/LatLongEntityType.cs | 80 ++++ .../NotificationSubscriptionEntityType.cs | 77 ++++ .../Models/OrderEntityType.cs | 86 ++++ .../Models/PersistedGrantEntityType.cs | 127 ++++++ .../Models/PizzaEntityType.cs | 111 +++++ .../Models/PizzaSpecialEntityType.cs | 76 ++++ .../Models/PizzaStoreContextModel.cs | 28 ++ .../Models/PizzaStoreContextModelBuilder.cs | 69 ++++ .../Models/PizzaStoreUserEntityType.cs | 156 +++++++ .../Models/PizzaToppingEntityType.cs | 96 +++++ .../Models/ToppingEntityType.cs | 62 +++ .../NotificationsController.cs | 43 -- .../OidcConfigurationController.cs | 33 +- .../BlazingPizza.Server/OrdersController.cs | 233 ++++++----- .../BlazingPizza.Server/PizzaApiExtensions.cs | 60 +++ .../BlazingPizza.Server/PizzaStoreContext.cs | 49 ++- .../BlazingPizza.Server/PizzaStoreUser.cs | 9 +- .../BlazingPizza.Server/PizzasController.cs | 16 - .../BlazingPizza.Server/Program.cs | 94 +++-- .../BlazingPizza.Server/SeedData.cs | 379 +++++++++--------- .../BlazingPizza.Server/SpecialsController.cs | 26 -- .../BlazingPizza.Server/Startup.cs | 70 ---- .../BlazingPizza.Server/ToppingsController.cs | 26 -- .../BlazingPizza.Server/pizza.db-shm | Bin 0 -> 32768 bytes .../BlazingPizza.Server/pizza.db-wal | Bin 0 -> 226632 bytes .../BlazingPizza.Shared/Address.cs | 33 +- .../BlazingPizza.Shared.csproj | 5 + .../BlazingPizza.Shared/LatLong.cs | 43 +- .../NotificationSubscription.cs | 17 +- .../BlazingPizza.Shared/Order.cs | 37 +- .../BlazingPizza.Shared/OrderWithStatus.cs | 133 +++--- .../BlazingPizza.Shared/Pizza.cs | 62 +-- .../BlazingPizza.Shared/PizzaSpecial.cs | 27 +- .../BlazingPizza.Shared/PizzaTopping.cs | 18 +- .../BlazingPizza.Shared/Topping.cs | 18 +- .../BlazingPizza.Shared/UserInfo.cs | 14 +- .../BlazingPizza.Client.csproj | 1 + .../JSRuntimeExtensions.cs | 16 +- .../BlazingPizza.Client/OrderState.cs | 101 +++-- .../BlazingPizza.Client/OrdersClient.cs | 58 ++- .../PizzaAuthenticationState.cs | 9 +- .../BlazingPizza.Client/Program.cs | 37 +- .../BlazingPizza.ComponentsLibrary.csproj | 1 + .../LocalStorage.cs | 22 +- .../BlazingPizza.Server.csproj | 1 + .../Models/AddressEntityType.cs | 92 +++++ .../Models/DeviceFlowCodesEntityType.cs | 114 ++++++ .../IdentityRoleClaimstringEntityType.cs | 85 ++++ .../Models/IdentityRoleEntityType.cs | 78 ++++ .../IdentityUserClaimstringEntityType.cs | 85 ++++ .../IdentityUserLoginstringEntityType.cs | 86 ++++ .../IdentityUserRolestringEntityType.cs | 82 ++++ .../IdentityUserTokenstringEntityType.cs | 84 ++++ .../Models/KeyEntityType.cs | 96 +++++ .../Models/LatLongEntityType.cs | 80 ++++ .../NotificationSubscriptionEntityType.cs | 77 ++++ .../Models/OrderEntityType.cs | 86 ++++ .../Models/PersistedGrantEntityType.cs | 127 ++++++ .../Models/PizzaEntityType.cs | 111 +++++ .../Models/PizzaSpecialEntityType.cs | 76 ++++ .../Models/PizzaStoreContextModel.cs | 28 ++ .../Models/PizzaStoreContextModelBuilder.cs | 69 ++++ .../Models/PizzaStoreUserEntityType.cs | 156 +++++++ .../Models/PizzaToppingEntityType.cs | 96 +++++ .../Models/ToppingEntityType.cs | 62 +++ .../OidcConfigurationController.cs | 33 +- .../BlazingPizza.Server/OrdersController.cs | 249 ++++++------ .../BlazingPizza.Server/PizzaApiExtensions.cs | 60 +++ .../BlazingPizza.Server/PizzaStoreContext.cs | 51 ++- .../BlazingPizza.Server/PizzaStoreUser.cs | 9 +- .../BlazingPizza.Server/PizzasController.cs | 16 - .../BlazingPizza.Server/Program.cs | 94 +++-- .../BlazingPizza.Server/SeedData.cs | 379 +++++++++--------- .../BlazingPizza.Server/SpecialsController.cs | 26 -- .../BlazingPizza.Server/Startup.cs | 70 ---- .../BlazingPizza.Server/ToppingsController.cs | 26 -- .../BlazingPizza.Shared/Address.cs | 33 +- .../BlazingPizza.Shared.csproj | 5 + .../BlazingPizza.Shared/LatLong.cs | 43 +- .../NotificationSubscription.cs | 17 +- .../BlazingPizza.Shared/Order.cs | 37 +- .../BlazingPizza.Shared/OrderWithStatus.cs | 133 +++--- .../BlazingPizza.Shared/Pizza.cs | 62 +-- .../BlazingPizza.Shared/PizzaSpecial.cs | 27 +- .../BlazingPizza.Shared/PizzaTopping.cs | 18 +- .../BlazingPizza.Shared/Topping.cs | 18 +- .../BlazingPizza.Shared/UserInfo.cs | 14 +- 391 files changed, 18264 insertions(+), 6532 deletions(-) create mode 100644 save-points/02-customize-a-pizza/BlazingPizza.Server/Models/AddressEntityType.cs create mode 100644 save-points/02-customize-a-pizza/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs create mode 100644 save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs create mode 100644 save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityRoleEntityType.cs create mode 100644 save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs create mode 100644 save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs create mode 100644 save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs create mode 100644 save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs create mode 100644 save-points/02-customize-a-pizza/BlazingPizza.Server/Models/KeyEntityType.cs create mode 100644 save-points/02-customize-a-pizza/BlazingPizza.Server/Models/LatLongEntityType.cs create mode 100644 save-points/02-customize-a-pizza/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs create mode 100644 save-points/02-customize-a-pizza/BlazingPizza.Server/Models/OrderEntityType.cs create mode 100644 save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PersistedGrantEntityType.cs create mode 100644 save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaEntityType.cs create mode 100644 save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs create mode 100644 save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaStoreContextModel.cs create mode 100644 save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs create mode 100644 save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs create mode 100644 save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaToppingEntityType.cs create mode 100644 save-points/02-customize-a-pizza/BlazingPizza.Server/Models/ToppingEntityType.cs delete mode 100644 save-points/02-customize-a-pizza/BlazingPizza.Server/NotificationsController.cs create mode 100644 save-points/02-customize-a-pizza/BlazingPizza.Server/PizzaApiExtensions.cs delete mode 100644 save-points/02-customize-a-pizza/BlazingPizza.Server/PizzasController.cs create mode 100644 save-points/03-show-order-status/BlazingPizza.Server/Models/AddressEntityType.cs create mode 100644 save-points/03-show-order-status/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs create mode 100644 save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs create mode 100644 save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityRoleEntityType.cs create mode 100644 save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs create mode 100644 save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs create mode 100644 save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs create mode 100644 save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs create mode 100644 save-points/03-show-order-status/BlazingPizza.Server/Models/KeyEntityType.cs create mode 100644 save-points/03-show-order-status/BlazingPizza.Server/Models/LatLongEntityType.cs create mode 100644 save-points/03-show-order-status/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs create mode 100644 save-points/03-show-order-status/BlazingPizza.Server/Models/OrderEntityType.cs create mode 100644 save-points/03-show-order-status/BlazingPizza.Server/Models/PersistedGrantEntityType.cs create mode 100644 save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaEntityType.cs create mode 100644 save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs create mode 100644 save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaStoreContextModel.cs create mode 100644 save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs create mode 100644 save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs create mode 100644 save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaToppingEntityType.cs create mode 100644 save-points/03-show-order-status/BlazingPizza.Server/Models/ToppingEntityType.cs delete mode 100644 save-points/03-show-order-status/BlazingPizza.Server/NotificationsController.cs create mode 100644 save-points/03-show-order-status/BlazingPizza.Server/PizzaApiExtensions.cs delete mode 100644 save-points/03-show-order-status/BlazingPizza.Server/PizzasController.cs delete mode 100644 save-points/03-show-order-status/BlazingPizza.Server/SpecialsController.cs delete mode 100644 save-points/03-show-order-status/BlazingPizza.Server/Startup.cs delete mode 100644 save-points/03-show-order-status/BlazingPizza.Server/ToppingsController.cs create mode 100644 save-points/04-refactor-state-management/BlazingPizza.Server/Models/AddressEntityType.cs create mode 100644 save-points/04-refactor-state-management/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs create mode 100644 save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs create mode 100644 save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityRoleEntityType.cs create mode 100644 save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs create mode 100644 save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs create mode 100644 save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs create mode 100644 save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs create mode 100644 save-points/04-refactor-state-management/BlazingPizza.Server/Models/KeyEntityType.cs create mode 100644 save-points/04-refactor-state-management/BlazingPizza.Server/Models/LatLongEntityType.cs create mode 100644 save-points/04-refactor-state-management/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs create mode 100644 save-points/04-refactor-state-management/BlazingPizza.Server/Models/OrderEntityType.cs create mode 100644 save-points/04-refactor-state-management/BlazingPizza.Server/Models/PersistedGrantEntityType.cs create mode 100644 save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaEntityType.cs create mode 100644 save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs create mode 100644 save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaStoreContextModel.cs create mode 100644 save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs create mode 100644 save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs create mode 100644 save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaToppingEntityType.cs create mode 100644 save-points/04-refactor-state-management/BlazingPizza.Server/Models/ToppingEntityType.cs delete mode 100644 save-points/04-refactor-state-management/BlazingPizza.Server/NotificationsController.cs create mode 100644 save-points/04-refactor-state-management/BlazingPizza.Server/PizzaApiExtensions.cs delete mode 100644 save-points/04-refactor-state-management/BlazingPizza.Server/PizzasController.cs delete mode 100644 save-points/04-refactor-state-management/BlazingPizza.Server/SpecialsController.cs delete mode 100644 save-points/04-refactor-state-management/BlazingPizza.Server/Startup.cs delete mode 100644 save-points/04-refactor-state-management/BlazingPizza.Server/ToppingsController.cs create mode 100644 save-points/04-refactor-state-management/BlazingPizza.Server/pizza.db-shm create mode 100644 save-points/04-refactor-state-management/BlazingPizza.Server/pizza.db-wal delete mode 100644 save-points/05-checkout-with-validation/BlazingPizza.Server/NotificationsController.cs create mode 100644 save-points/05-checkout-with-validation/BlazingPizza.Server/PizzaApiExtensions.cs delete mode 100644 save-points/05-checkout-with-validation/BlazingPizza.Server/PizzasController.cs delete mode 100644 save-points/05-checkout-with-validation/BlazingPizza.Server/SpecialsController.cs delete mode 100644 save-points/05-checkout-with-validation/BlazingPizza.Server/Startup.cs delete mode 100644 save-points/05-checkout-with-validation/BlazingPizza.Server/ToppingsController.cs create mode 100644 save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/AddressEntityType.cs create mode 100644 save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs create mode 100644 save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs create mode 100644 save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityRoleEntityType.cs create mode 100644 save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs create mode 100644 save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs create mode 100644 save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs create mode 100644 save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs create mode 100644 save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/KeyEntityType.cs create mode 100644 save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/LatLongEntityType.cs create mode 100644 save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs create mode 100644 save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/OrderEntityType.cs create mode 100644 save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PersistedGrantEntityType.cs create mode 100644 save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaEntityType.cs create mode 100644 save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs create mode 100644 save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaStoreContextModel.cs create mode 100644 save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs create mode 100644 save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs create mode 100644 save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaToppingEntityType.cs create mode 100644 save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/ToppingEntityType.cs delete mode 100644 save-points/06-authentication-and-authorization/BlazingPizza.Server/SpecialsController.cs delete mode 100644 save-points/06-authentication-and-authorization/BlazingPizza.Server/Startup.cs delete mode 100644 save-points/06-authentication-and-authorization/BlazingPizza.Server/ToppingsController.cs create mode 100644 save-points/06-authentication-and-authorization/BlazingPizza.Server/pizza.db-shm create mode 100644 save-points/06-authentication-and-authorization/BlazingPizza.Server/pizza.db-wal create mode 100644 save-points/07-javascript-interop/BlazingPizza.Server/Models/AddressEntityType.cs create mode 100644 save-points/07-javascript-interop/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs create mode 100644 save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs create mode 100644 save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityRoleEntityType.cs create mode 100644 save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs create mode 100644 save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs create mode 100644 save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs create mode 100644 save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs create mode 100644 save-points/07-javascript-interop/BlazingPizza.Server/Models/KeyEntityType.cs create mode 100644 save-points/07-javascript-interop/BlazingPizza.Server/Models/LatLongEntityType.cs create mode 100644 save-points/07-javascript-interop/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs create mode 100644 save-points/07-javascript-interop/BlazingPizza.Server/Models/OrderEntityType.cs create mode 100644 save-points/07-javascript-interop/BlazingPizza.Server/Models/PersistedGrantEntityType.cs create mode 100644 save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaEntityType.cs create mode 100644 save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs create mode 100644 save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaStoreContextModel.cs create mode 100644 save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs create mode 100644 save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs create mode 100644 save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaToppingEntityType.cs create mode 100644 save-points/07-javascript-interop/BlazingPizza.Server/Models/ToppingEntityType.cs delete mode 100644 save-points/07-javascript-interop/BlazingPizza.Server/NotificationsController.cs create mode 100644 save-points/07-javascript-interop/BlazingPizza.Server/PizzaApiExtensions.cs delete mode 100644 save-points/07-javascript-interop/BlazingPizza.Server/PizzasController.cs delete mode 100644 save-points/07-javascript-interop/BlazingPizza.Server/SpecialsController.cs delete mode 100644 save-points/07-javascript-interop/BlazingPizza.Server/Startup.cs delete mode 100644 save-points/07-javascript-interop/BlazingPizza.Server/ToppingsController.cs create mode 100644 save-points/08-templated-components/BlazingPizza.Server/Models/AddressEntityType.cs create mode 100644 save-points/08-templated-components/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs create mode 100644 save-points/08-templated-components/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs create mode 100644 save-points/08-templated-components/BlazingPizza.Server/Models/IdentityRoleEntityType.cs create mode 100644 save-points/08-templated-components/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs create mode 100644 save-points/08-templated-components/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs create mode 100644 save-points/08-templated-components/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs create mode 100644 save-points/08-templated-components/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs create mode 100644 save-points/08-templated-components/BlazingPizza.Server/Models/KeyEntityType.cs create mode 100644 save-points/08-templated-components/BlazingPizza.Server/Models/LatLongEntityType.cs create mode 100644 save-points/08-templated-components/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs create mode 100644 save-points/08-templated-components/BlazingPizza.Server/Models/OrderEntityType.cs create mode 100644 save-points/08-templated-components/BlazingPizza.Server/Models/PersistedGrantEntityType.cs create mode 100644 save-points/08-templated-components/BlazingPizza.Server/Models/PizzaEntityType.cs create mode 100644 save-points/08-templated-components/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs create mode 100644 save-points/08-templated-components/BlazingPizza.Server/Models/PizzaStoreContextModel.cs create mode 100644 save-points/08-templated-components/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs create mode 100644 save-points/08-templated-components/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs create mode 100644 save-points/08-templated-components/BlazingPizza.Server/Models/PizzaToppingEntityType.cs create mode 100644 save-points/08-templated-components/BlazingPizza.Server/Models/ToppingEntityType.cs delete mode 100644 save-points/08-templated-components/BlazingPizza.Server/NotificationsController.cs create mode 100644 save-points/08-templated-components/BlazingPizza.Server/PizzaApiExtensions.cs delete mode 100644 save-points/08-templated-components/BlazingPizza.Server/PizzasController.cs delete mode 100644 save-points/08-templated-components/BlazingPizza.Server/SpecialsController.cs delete mode 100644 save-points/08-templated-components/BlazingPizza.Server/Startup.cs delete mode 100644 save-points/08-templated-components/BlazingPizza.Server/ToppingsController.cs create mode 100644 save-points/08-templated-components/BlazingPizza.Server/pizza.db-shm create mode 100644 save-points/08-templated-components/BlazingPizza.Server/pizza.db-wal create mode 100644 save-points/09-progressive-web-app/BlazingPizza.Server/Models/AddressEntityType.cs create mode 100644 save-points/09-progressive-web-app/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs create mode 100644 save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs create mode 100644 save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityRoleEntityType.cs create mode 100644 save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs create mode 100644 save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs create mode 100644 save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs create mode 100644 save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs create mode 100644 save-points/09-progressive-web-app/BlazingPizza.Server/Models/KeyEntityType.cs create mode 100644 save-points/09-progressive-web-app/BlazingPizza.Server/Models/LatLongEntityType.cs create mode 100644 save-points/09-progressive-web-app/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs create mode 100644 save-points/09-progressive-web-app/BlazingPizza.Server/Models/OrderEntityType.cs create mode 100644 save-points/09-progressive-web-app/BlazingPizza.Server/Models/PersistedGrantEntityType.cs create mode 100644 save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaEntityType.cs create mode 100644 save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs create mode 100644 save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaStoreContextModel.cs create mode 100644 save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs create mode 100644 save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs create mode 100644 save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaToppingEntityType.cs create mode 100644 save-points/09-progressive-web-app/BlazingPizza.Server/Models/ToppingEntityType.cs create mode 100644 save-points/09-progressive-web-app/BlazingPizza.Server/PizzaApiExtensions.cs delete mode 100644 save-points/09-progressive-web-app/BlazingPizza.Server/PizzasController.cs delete mode 100644 save-points/09-progressive-web-app/BlazingPizza.Server/SpecialsController.cs delete mode 100644 save-points/09-progressive-web-app/BlazingPizza.Server/Startup.cs delete mode 100644 save-points/09-progressive-web-app/BlazingPizza.Server/ToppingsController.cs diff --git a/save-points/00-get-started/BlazingPizza.ComponentsLibrary/Map/Marker.cs b/save-points/00-get-started/BlazingPizza.ComponentsLibrary/Map/Marker.cs index 63006067..7be5cafb 100644 --- a/save-points/00-get-started/BlazingPizza.ComponentsLibrary/Map/Marker.cs +++ b/save-points/00-get-started/BlazingPizza.ComponentsLibrary/Map/Marker.cs @@ -1,13 +1,12 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Marker { - public class Marker - { - public string Description { get; set; } + public string Description { get; set; } - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } + public double Y { get; set; } - public bool ShowPopup { get; set; } - } -} + public bool ShowPopup { get; set; } +} \ No newline at end of file diff --git a/save-points/00-get-started/BlazingPizza.ComponentsLibrary/Map/Point.cs b/save-points/00-get-started/BlazingPizza.ComponentsLibrary/Map/Point.cs index 03841826..a1040c38 100644 --- a/save-points/00-get-started/BlazingPizza.ComponentsLibrary/Map/Point.cs +++ b/save-points/00-get-started/BlazingPizza.ComponentsLibrary/Map/Point.cs @@ -1,9 +1,8 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Point { - public class Point - { - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } - } -} + public double Y { get; set; } +} \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/Map/Marker.cs b/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/Map/Marker.cs index 63006067..da486e7c 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/Map/Marker.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/Map/Marker.cs @@ -1,13 +1,11 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; +public class Marker { - public class Marker - { - public string Description { get; set; } + public string Description { get; set; } - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } + public double Y { get; set; } - public bool ShowPopup { get; set; } - } -} + public bool ShowPopup { get; set; } +} \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/Map/Point.cs b/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/Map/Point.cs index 03841826..01f420f3 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/Map/Point.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/Map/Point.cs @@ -1,9 +1,9 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Point { - public class Point - { - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } - } + public double Y { get; set; } } +// Compare this snippet from save-points\01-Components-and-layout\BlazingPizza.ComponentsLibrary\Map\Marker.cs: \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/PizzaStoreUser.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/PizzaStoreUser.cs index 171ce83d..d446a679 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Server/PizzaStoreUser.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/PizzaStoreUser.cs @@ -1,8 +1,6 @@ using Microsoft.AspNetCore.Identity; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; +public class PizzaStoreUser : IdentityUser { - public class PizzaStoreUser : IdentityUser - { - } } \ No newline at end of file diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Client/BlazingPizza.Client.csproj b/save-points/02-customize-a-pizza/BlazingPizza.Client/BlazingPizza.Client.csproj index cd5da247..8f007b31 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/save-points/02-customize-a-pizza/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -2,6 +2,7 @@ $(TargetFrameworkVersion) + true diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Client/Program.cs b/save-points/02-customize-a-pizza/BlazingPizza.Client/Program.cs index 48147d6f..ab7dd4d9 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Client/Program.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Client/Program.cs @@ -1,21 +1,9 @@ -using Microsoft.AspNetCore.Components.WebAssembly.Hosting; -using Microsoft.Extensions.DependencyInjection; -using System; -using System.Net.Http; -using System.Threading.Tasks; +using BlazingPizza.Client; +using Microsoft.AspNetCore.Components.WebAssembly.Hosting; -namespace BlazingPizza.Client -{ - public class Program - { - public static async Task Main(string[] args) - { - var builder = WebAssemblyHostBuilder.CreateDefault(args); - builder.RootComponents.Add("#app"); +var builder = WebAssemblyHostBuilder.CreateDefault(args); +builder.RootComponents.Add("#app"); - builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); +builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); - await builder.Build().RunAsync(); - } - } -} +await builder.Build().RunAsync(); diff --git a/save-points/02-customize-a-pizza/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/save-points/02-customize-a-pizza/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 61ebf623..cb996b1b 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/save-points/02-customize-a-pizza/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -2,6 +2,7 @@ $(TargetFrameworkVersion) + true diff --git a/save-points/02-customize-a-pizza/BlazingPizza.ComponentsLibrary/LocalStorage.cs b/save-points/02-customize-a-pizza/BlazingPizza.ComponentsLibrary/LocalStorage.cs index f36b098e..3925ced2 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.ComponentsLibrary/LocalStorage.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.ComponentsLibrary/LocalStorage.cs @@ -1,17 +1,17 @@ using Microsoft.JSInterop; -using System.Threading.Tasks; -namespace BlazingPizza.ComponentsLibrary +namespace BlazingPizza.ComponentsLibrary; + +public static class LocalStorage { - public static class LocalStorage - { - public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) - => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); - public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object value) - => jsRuntime.InvokeVoidAsync("blazorLocalStorage.set", key, value); + public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) + => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); + + public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object value) + => jsRuntime.InvokeVoidAsync("blazorLocalStorage.set", key, value); - public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key) - => jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key); - } -} + public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key) + => jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key); + +} \ No newline at end of file diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/BlazingPizza.Server.csproj b/save-points/02-customize-a-pizza/BlazingPizza.Server/BlazingPizza.Server.csproj index b9c74fc4..227890e1 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -2,6 +2,7 @@ $(TargetFrameworkVersion) + true diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/AddressEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/AddressEntityType.cs new file mode 100644 index 00000000..82db81b6 --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/AddressEntityType.cs @@ -0,0 +1,92 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class AddressEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Address", + typeof(Address), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Address).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var city = runtimeEntityType.AddProperty( + "City", + typeof(string), + propertyInfo: typeof(Address).GetProperty("City", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var line1 = runtimeEntityType.AddProperty( + "Line1", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line1", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var line2 = runtimeEntityType.AddProperty( + "Line2", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line2", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var postalCode = runtimeEntityType.AddProperty( + "PostalCode", + typeof(string), + propertyInfo: typeof(Address).GetProperty("PostalCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var region = runtimeEntityType.AddProperty( + "Region", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Region", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Address"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs new file mode 100644 index 00000000..1dd4563b --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs @@ -0,0 +1,114 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class DeviceFlowCodesEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.DeviceFlowCodes", + typeof(DeviceFlowCodes), + baseEntityType); + + var userCode = runtimeEntityType.AddProperty( + "UserCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("UserCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var deviceCode = runtimeEntityType.AddProperty( + "DeviceCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("DeviceCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var key = runtimeEntityType.AddKey( + new[] { userCode }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deviceCode }, + unique: true); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "DeviceCodes"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs new file mode 100644 index 00000000..8946b261 --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRoleClaim", + typeof(IdentityRoleClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoleClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityRoleEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityRoleEntityType.cs new file mode 100644 index 00000000..2f1fec2b --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityRoleEntityType.cs @@ -0,0 +1,78 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRole", + typeof(IdentityRole), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedName = runtimeEntityType.AddProperty( + "NormalizedName", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("NormalizedName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedName }, + unique: true); + index.AddAnnotation("Relational:Name", "RoleNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs new file mode 100644 index 00000000..55418a1e --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserClaim", + typeof(IdentityUserClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityUserClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs new file mode 100644 index 00000000..3ca029bd --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserLoginstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserLogin", + typeof(IdentityUserLogin), + baseEntityType); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerKey = runtimeEntityType.AddProperty( + "ProviderKey", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderKey", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerDisplayName = runtimeEntityType.AddProperty( + "ProviderDisplayName", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderDisplayName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { loginProvider, providerKey }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserLogins"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs new file mode 100644 index 00000000..70078d7a --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs @@ -0,0 +1,82 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserRolestringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserRole", + typeof(IdentityUserRole), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { userId, roleId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs new file mode 100644 index 00000000..93ba6d31 --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs @@ -0,0 +1,84 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserTokenstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserToken", + typeof(IdentityUserToken), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var value = runtimeEntityType.AddProperty( + "Value", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Value", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { userId, loginProvider, name }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserTokens"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/KeyEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/KeyEntityType.cs new file mode 100644 index 00000000..f6c6b4c7 --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/KeyEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class KeyEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.Key", + typeof(Key), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var algorithm = runtimeEntityType.AddProperty( + "Algorithm", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Algorithm", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var created = runtimeEntityType.AddProperty( + "Created", + typeof(DateTime), + propertyInfo: typeof(Key).GetProperty("Created", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var dataProtected = runtimeEntityType.AddProperty( + "DataProtected", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("DataProtected", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var isX509Certificate = runtimeEntityType.AddProperty( + "IsX509Certificate", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("IsX509Certificate", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var use = runtimeEntityType.AddProperty( + "Use", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Use", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var version = runtimeEntityType.AddProperty( + "Version", + typeof(int), + propertyInfo: typeof(Key).GetProperty("Version", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { use }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Keys"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/LatLongEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/LatLongEntityType.cs new file mode 100644 index 00000000..3fd254bd --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/LatLongEntityType.cs @@ -0,0 +1,80 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class LatLongEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.LatLong", + typeof(LatLong), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var latitude = runtimeEntityType.AddProperty( + "Latitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Latitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var longitude = runtimeEntityType.AddProperty( + "Longitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Longitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + unique: true, + required: true, + ownership: true); + + var deliveryLocation = principalEntityType.AddNavigation("DeliveryLocation", + runtimeForeignKey, + onDependent: false, + typeof(LatLong), + propertyInfo: typeof(Order).GetProperty("DeliveryLocation", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + eagerLoaded: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs new file mode 100644 index 00000000..db236e4c --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs @@ -0,0 +1,77 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class NotificationSubscriptionEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.NotificationSubscription", + typeof(NotificationSubscription), + baseEntityType); + + var notificationSubscriptionId = runtimeEntityType.AddProperty( + "NotificationSubscriptionId", + typeof(int), + propertyInfo: typeof(NotificationSubscription).GetProperty("NotificationSubscriptionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var auth = runtimeEntityType.AddProperty( + "Auth", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Auth", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var p256dh = runtimeEntityType.AddProperty( + "P256dh", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("P256dh", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var url = runtimeEntityType.AddProperty( + "Url", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Url", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { notificationSubscriptionId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "NotificationSubscriptions"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/OrderEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/OrderEntityType.cs new file mode 100644 index 00000000..9d9ec6fd --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/OrderEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class OrderEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Order", + typeof(Order), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Order).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var createdTime = runtimeEntityType.AddProperty( + "CreatedTime", + typeof(DateTime), + propertyInfo: typeof(Order).GetProperty("CreatedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var deliveryAddressId = runtimeEntityType.AddProperty( + "DeliveryAddressId", + typeof(int?), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(Order).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deliveryAddressId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("DeliveryAddressId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType); + + var deliveryAddress = declaringEntityType.AddNavigation("DeliveryAddress", + runtimeForeignKey, + onDependent: true, + typeof(Address), + propertyInfo: typeof(Order).GetProperty("DeliveryAddress", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PersistedGrantEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PersistedGrantEntityType.cs new file mode 100644 index 00000000..842d53a5 --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PersistedGrantEntityType.cs @@ -0,0 +1,127 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PersistedGrantEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.PersistedGrant", + typeof(PersistedGrant), + baseEntityType); + + var key = runtimeEntityType.AddProperty( + "Key", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Key", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var consumedTime = runtimeEntityType.AddProperty( + "ConsumedTime", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("ConsumedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(PersistedGrant).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var type = runtimeEntityType.AddProperty( + "Type", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Type", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var key0 = runtimeEntityType.AddKey( + new[] { key }); + runtimeEntityType.SetPrimaryKey(key0); + + var index = runtimeEntityType.AddIndex( + new[] { consumedTime }); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + var index1 = runtimeEntityType.AddIndex( + new[] { subjectId, clientId, type }); + + var index2 = runtimeEntityType.AddIndex( + new[] { subjectId, sessionId, type }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PersistedGrants"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaEntityType.cs new file mode 100644 index 00000000..3a124e63 --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaEntityType.cs @@ -0,0 +1,111 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Pizza", + typeof(Pizza), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var size = runtimeEntityType.AddProperty( + "Size", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Size", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var specialId = runtimeEntityType.AddProperty( + "SpecialId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("SpecialId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { orderId }); + + var index0 = runtimeEntityType.AddIndex( + new[] { specialId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var pizzas = principalEntityType.AddNavigation("Pizzas", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Order).GetProperty("Pizzas", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("SpecialId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var special = declaringEntityType.AddNavigation("Special", + runtimeForeignKey, + onDependent: true, + typeof(PizzaSpecial), + propertyInfo: typeof(Pizza).GetProperty("Special", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Pizzas"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs new file mode 100644 index 00000000..e86b0f50 --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs @@ -0,0 +1,76 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaSpecialEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaSpecial", + typeof(PizzaSpecial), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(PizzaSpecial).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var basePrice = runtimeEntityType.AddProperty( + "BasePrice", + typeof(decimal), + propertyInfo: typeof(PizzaSpecial).GetProperty("BasePrice", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var imageUrl = runtimeEntityType.AddProperty( + "ImageUrl", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("ImageUrl", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Specials"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaStoreContextModel.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaStoreContextModel.cs new file mode 100644 index 00000000..8b516a68 --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaStoreContextModel.cs @@ -0,0 +1,28 @@ +// +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + [DbContext(typeof(PizzaStoreContext))] + public partial class PizzaStoreContextModel : RuntimeModel + { + static PizzaStoreContextModel() + { + var model = new PizzaStoreContextModel(); + model.Initialize(); + model.Customize(); + _instance = model; + } + + private static PizzaStoreContextModel _instance; + public static IModel Instance => _instance; + + partial void Initialize(); + + partial void Customize(); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs new file mode 100644 index 00000000..d46f50f4 --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs @@ -0,0 +1,69 @@ +// +using System; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + public partial class PizzaStoreContextModel + { + partial void Initialize() + { + var address = AddressEntityType.Create(this); + var latLong = LatLongEntityType.Create(this); + var notificationSubscription = NotificationSubscriptionEntityType.Create(this); + var order = OrderEntityType.Create(this); + var pizza = PizzaEntityType.Create(this); + var pizzaSpecial = PizzaSpecialEntityType.Create(this); + var pizzaTopping = PizzaToppingEntityType.Create(this); + var pizzaStoreUser = PizzaStoreUserEntityType.Create(this); + var topping = ToppingEntityType.Create(this); + var deviceFlowCodes = DeviceFlowCodesEntityType.Create(this); + var key = KeyEntityType.Create(this); + var persistedGrant = PersistedGrantEntityType.Create(this); + var identityRole = IdentityRoleEntityType.Create(this); + var identityRoleClaimstring = IdentityRoleClaimstringEntityType.Create(this); + var identityUserClaimstring = IdentityUserClaimstringEntityType.Create(this); + var identityUserLoginstring = IdentityUserLoginstringEntityType.Create(this); + var identityUserRolestring = IdentityUserRolestringEntityType.Create(this); + var identityUserTokenstring = IdentityUserTokenstringEntityType.Create(this); + + LatLongEntityType.CreateForeignKey1(latLong, order); + OrderEntityType.CreateForeignKey1(order, address); + PizzaEntityType.CreateForeignKey1(pizza, order); + PizzaEntityType.CreateForeignKey2(pizza, pizzaSpecial); + PizzaToppingEntityType.CreateForeignKey1(pizzaTopping, pizza); + PizzaToppingEntityType.CreateForeignKey2(pizzaTopping, topping); + IdentityRoleClaimstringEntityType.CreateForeignKey1(identityRoleClaimstring, identityRole); + IdentityUserClaimstringEntityType.CreateForeignKey1(identityUserClaimstring, pizzaStoreUser); + IdentityUserLoginstringEntityType.CreateForeignKey1(identityUserLoginstring, pizzaStoreUser); + IdentityUserRolestringEntityType.CreateForeignKey1(identityUserRolestring, identityRole); + IdentityUserRolestringEntityType.CreateForeignKey2(identityUserRolestring, pizzaStoreUser); + IdentityUserTokenstringEntityType.CreateForeignKey1(identityUserTokenstring, pizzaStoreUser); + + AddressEntityType.CreateAnnotations(address); + LatLongEntityType.CreateAnnotations(latLong); + NotificationSubscriptionEntityType.CreateAnnotations(notificationSubscription); + OrderEntityType.CreateAnnotations(order); + PizzaEntityType.CreateAnnotations(pizza); + PizzaSpecialEntityType.CreateAnnotations(pizzaSpecial); + PizzaToppingEntityType.CreateAnnotations(pizzaTopping); + PizzaStoreUserEntityType.CreateAnnotations(pizzaStoreUser); + ToppingEntityType.CreateAnnotations(topping); + DeviceFlowCodesEntityType.CreateAnnotations(deviceFlowCodes); + KeyEntityType.CreateAnnotations(key); + PersistedGrantEntityType.CreateAnnotations(persistedGrant); + IdentityRoleEntityType.CreateAnnotations(identityRole); + IdentityRoleClaimstringEntityType.CreateAnnotations(identityRoleClaimstring); + IdentityUserClaimstringEntityType.CreateAnnotations(identityUserClaimstring); + IdentityUserLoginstringEntityType.CreateAnnotations(identityUserLoginstring); + IdentityUserRolestringEntityType.CreateAnnotations(identityUserRolestring); + IdentityUserTokenstringEntityType.CreateAnnotations(identityUserTokenstring); + + AddAnnotation("ProductVersion", "6.0.0"); + } + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs new file mode 100644 index 00000000..18b2d96d --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs @@ -0,0 +1,156 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaStoreUserEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Server.PizzaStoreUser", + typeof(PizzaStoreUser), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var accessFailedCount = runtimeEntityType.AddProperty( + "AccessFailedCount", + typeof(int), + propertyInfo: typeof(IdentityUser).GetProperty("AccessFailedCount", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var email = runtimeEntityType.AddProperty( + "Email", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Email", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var emailConfirmed = runtimeEntityType.AddProperty( + "EmailConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("EmailConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnabled = runtimeEntityType.AddProperty( + "LockoutEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnd = runtimeEntityType.AddProperty( + "LockoutEnd", + typeof(DateTimeOffset?), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnd", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var normalizedEmail = runtimeEntityType.AddProperty( + "NormalizedEmail", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedEmail", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedUserName = runtimeEntityType.AddProperty( + "NormalizedUserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedUserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var passwordHash = runtimeEntityType.AddProperty( + "PasswordHash", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PasswordHash", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumber = runtimeEntityType.AddProperty( + "PhoneNumber", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumber", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumberConfirmed = runtimeEntityType.AddProperty( + "PhoneNumberConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumberConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var securityStamp = runtimeEntityType.AddProperty( + "SecurityStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("SecurityStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var twoFactorEnabled = runtimeEntityType.AddProperty( + "TwoFactorEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("TwoFactorEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var userName = runtimeEntityType.AddProperty( + "UserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("UserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedEmail }); + index.AddAnnotation("Relational:Name", "EmailIndex"); + + var index0 = runtimeEntityType.AddIndex( + new[] { normalizedUserName }, + unique: true); + index0.AddAnnotation("Relational:Name", "UserNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUsers"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaToppingEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaToppingEntityType.cs new file mode 100644 index 00000000..b97d2a24 --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaToppingEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaTopping", + typeof(PizzaTopping), + baseEntityType); + + var pizzaId = runtimeEntityType.AddProperty( + "PizzaId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("PizzaId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var toppingId = runtimeEntityType.AddProperty( + "ToppingId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("ToppingId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { pizzaId, toppingId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { toppingId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("PizzaId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var toppings = principalEntityType.AddNavigation("Toppings", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Pizza).GetProperty("Toppings", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("ToppingId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var topping = declaringEntityType.AddNavigation("Topping", + runtimeForeignKey, + onDependent: true, + typeof(Topping), + propertyInfo: typeof(PizzaTopping).GetProperty("Topping", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PizzaTopping"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/ToppingEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/ToppingEntityType.cs new file mode 100644 index 00000000..9295f9bf --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/ToppingEntityType.cs @@ -0,0 +1,62 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class ToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Topping", + typeof(Topping), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Topping).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Topping).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var price = runtimeEntityType.AddProperty( + "Price", + typeof(decimal), + propertyInfo: typeof(Topping).GetProperty("Price", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Toppings"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/NotificationsController.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/NotificationsController.cs deleted file mode 100644 index bb3b96ff..00000000 --- a/save-points/02-customize-a-pizza/BlazingPizza.Server/NotificationsController.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("notifications")] - [ApiController] - [Authorize] - public class NotificationsController : Controller - { - private readonly PizzaStoreContext _db; - - public NotificationsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpPut("subscribe")] - public async Task Subscribe(NotificationSubscription subscription) - { - // We're storing at most one subscription per user, so delete old ones. - // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. - var userId = GetUserId(); - var oldSubscriptions = _db.NotificationSubscriptions.Where(e => e.UserId == userId); - _db.NotificationSubscriptions.RemoveRange(oldSubscriptions); - - // Store new subscription - subscription.UserId = userId; - _db.NotificationSubscriptions.Attach(subscription); - - await _db.SaveChangesAsync(); - return subscription; - } - - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } - } -} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/OidcConfigurationController.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/OidcConfigurationController.cs index c074debf..d5822577 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Server/OidcConfigurationController.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/OidcConfigurationController.cs @@ -1,26 +1,21 @@ using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class OidcConfigurationController : Controller { - public class OidcConfigurationController : Controller - { - public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) - { - ClientRequestParametersProvider = clientRequestParametersProvider; - } + public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) + { + ClientRequestParametersProvider = clientRequestParametersProvider; + } - public IClientRequestParametersProvider ClientRequestParametersProvider { get; } + public IClientRequestParametersProvider ClientRequestParametersProvider { get; } - [HttpGet("_configuration/{clientId}")] - public IActionResult GetClientRequestParameters([FromRoute]string clientId) - { - var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); - return Ok(parameters); - } - } -} + [HttpGet("_configuration/{clientId}")] + public IActionResult GetClientRequestParameters([FromRoute]string clientId) + { + var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); + return Ok(parameters); + } +} \ No newline at end of file diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/OrdersController.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/OrdersController.cs index 2b8bc99b..54ff6114 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Server/OrdersController.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/OrdersController.cs @@ -1,114 +1,109 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; +using System.Security.Claims; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +[Route("orders")] +[ApiController] +// [Authorize] +public class OrdersController : Controller { - [Route("orders")] - [ApiController] - // [Authorize] - public class OrdersController : Controller - { - private readonly PizzaStoreContext _db; - - public OrdersController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetOrders() - { - var orders = await _db.Orders - // .Where(o => o.UserId == GetUserId()) - .Include(o => o.DeliveryLocation) - .Include(o => o.Pizzas).ThenInclude(p => p.Special) - .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) - .OrderByDescending(o => o.CreatedTime) - .ToListAsync(); - - return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); - } - - [HttpGet("{orderId}")] - public async Task> GetOrderWithStatus(int orderId) - { - var order = await _db.Orders - .Where(o => o.OrderId == orderId) - // .Where(o => o.UserId == GetUserId()) - .Include(o => o.DeliveryLocation) - .Include(o => o.Pizzas).ThenInclude(p => p.Special) - .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) - .SingleOrDefaultAsync(); - - if (order == null) - { - return NotFound(); - } - - return OrderWithStatus.FromOrder(order); - } - - [HttpPost] - public async Task> PlaceOrder(Order order) - { - order.CreatedTime = DateTime.Now; - order.DeliveryLocation = new LatLong(51.5001, -0.1239); - // order.UserId = GetUserId(); - - // Enforce existence of Pizza.SpecialId and Topping.ToppingId - // in the database - prevent the submitter from making up - // new specials and toppings - foreach (var pizza in order.Pizzas) - { - pizza.SpecialId = pizza.Special.Id; - pizza.Special = null; - - foreach (var topping in pizza.Toppings) - { - topping.ToppingId = topping.Topping.Id; - topping.Topping = null; - } - } - - _db.Orders.Attach(order); - await _db.SaveChangesAsync(); - - // In the background, send push notifications if possible - var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); - if (subscription != null) - { - _ = TrackAndSendNotificationsAsync(order, subscription); - } - - return order.OrderId; - } - - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } - - private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription subscription) - { - // In a realistic case, some other backend process would track - // order delivery progress and send us notifications when it - // changes. Since we don't have any such process here, fake it. - await Task.Delay(OrderWithStatus.PreparationDuration); - await SendNotificationAsync(order, subscription, "Your order has been dispatched!"); - - await Task.Delay(OrderWithStatus.DeliveryDuration); - await SendNotificationAsync(order, subscription, "Your order is now delivered. Enjoy!"); - } - - private static Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) - { - // This will be implemented later - return Task.CompletedTask; - } - } -} + private readonly PizzaStoreContext _db; + + public OrdersController(PizzaStoreContext db) + { + _db = db; + } + + [HttpGet] + public async Task>> GetOrders() + { + var orders = await _db.Orders + // .Where(o => o.UserId == GetUserId()) + .Include(o => o.DeliveryLocation) + .Include(o => o.Pizzas).ThenInclude(p => p.Special) + .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) + .OrderByDescending(o => o.CreatedTime) + .ToListAsync(); + + return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); + } + + [HttpGet("{orderId}")] + public async Task> GetOrderWithStatus(int orderId) + { + var order = await _db.Orders + .Where(o => o.OrderId == orderId) + // .Where(o => o.UserId == GetUserId()) + .Include(o => o.DeliveryLocation) + .Include(o => o.Pizzas).ThenInclude(p => p.Special) + .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) + .SingleOrDefaultAsync(); + + if (order == null) + { + return NotFound(); + } + + return OrderWithStatus.FromOrder(order); + } + + [HttpPost] + public async Task> PlaceOrder(Order order) + { + order.CreatedTime = DateTime.Now; + order.DeliveryLocation = new LatLong(51.5001, -0.1239); + // order.UserId = GetUserId(); + + // Enforce existence of Pizza.SpecialId and Topping.ToppingId + // in the database - prevent the submitter from making up + // new specials and toppings + foreach (var pizza in order.Pizzas) + { + pizza.SpecialId = pizza.Special.Id; + pizza.Special = null; + + foreach (var topping in pizza.Toppings) + { + topping.ToppingId = topping.Topping.Id; + topping.Topping = null; + } + } + + _db.Orders.Attach(order); + await _db.SaveChangesAsync(); + + // In the background, send push notifications if possible + var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); + if (subscription != null) + { + _ = TrackAndSendNotificationsAsync(order, subscription); + } + + return order.OrderId; + } + + private string GetUserId() + { + return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); + } + + private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription subscription) + { + // In a realistic case, some other backend process would track + // order delivery progress and send us notifications when it + // changes. Since we don't have any such process here, fake it. + await Task.Delay(OrderWithStatus.PreparationDuration); + await SendNotificationAsync(order, subscription, "Your order has been dispatched!"); + + await Task.Delay(OrderWithStatus.DeliveryDuration); + await SendNotificationAsync(order, subscription, "Your order is now delivered. Enjoy!"); + } + + private static Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) + { + // This will be implemented later + return Task.CompletedTask; + } +} \ No newline at end of file diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/PizzaApiExtensions.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/PizzaApiExtensions.cs new file mode 100644 index 00000000..bf6b7bde --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/PizzaApiExtensions.cs @@ -0,0 +1,60 @@ +using System.Security.Claims; +using Microsoft.AspNetCore.Authorization; +using Microsoft.EntityFrameworkCore; + +namespace BlazingPizza.Server; + +public static class PizzaApiExtensions +{ + + public static WebApplication MapPizzaApi(this WebApplication app) + { + + // Subscribe to notifications + app.MapPut("/notifications/subscribe", [Authorize] async ( + HttpContext context, + PizzaStoreContext db, + NotificationSubscription subscription) => + { + + // We're storing at most one subscription per user, so delete old ones. + // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. + var userId = GetUserId(context); + var oldSubscriptions = db.NotificationSubscriptions.Where(e => e.UserId == userId); + db.NotificationSubscriptions.RemoveRange(oldSubscriptions); + + // Store new subscription + subscription.UserId = userId; + db.NotificationSubscriptions.Attach(subscription); + + await db.SaveChangesAsync(); + return Results.Ok(subscription); + + }); + + // Specials + app.MapGet("/specials", async (PizzaStoreContext db) => + { + + var specials = await db.Specials.ToListAsync(); + return Results.Ok(specials); + + }); + + // Toppings + app.MapGet("/toppings", async (PizzaStoreContext db) => + { + var toppings = await db.Toppings.OrderBy(t => t.Name).ToListAsync(); + return Results.Ok(toppings); + }); + + return app; + + } + + private static string GetUserId(HttpContext context) + { + return context.User.FindFirstValue(ClaimTypes.NameIdentifier); + } + +} \ No newline at end of file diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/PizzaStoreContext.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/PizzaStoreContext.cs index 9485bd12..9a2e17ee 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Server/PizzaStoreContext.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/PizzaStoreContext.cs @@ -3,37 +3,36 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class PizzaStoreContext : ApiAuthorizationDbContext { - public class PizzaStoreContext : ApiAuthorizationDbContext - { - public PizzaStoreContext( - DbContextOptions options, - IOptions operationalStoreOptions) : base(options, operationalStoreOptions) - { - } + public PizzaStoreContext( + DbContextOptions options, + IOptions operationalStoreOptions) : base(options, operationalStoreOptions) + { + } - public DbSet Orders { get; set; } + public DbSet Orders { get; set; } - public DbSet Pizzas { get; set; } + public DbSet Pizzas { get; set; } - public DbSet Specials { get; set; } + public DbSet Specials { get; set; } - public DbSet Toppings { get; set; } + public DbSet Toppings { get; set; } - public DbSet NotificationSubscriptions { get; set; } + public DbSet NotificationSubscriptions { get; set; } - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - base.OnModelCreating(modelBuilder); + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); - // Configuring a many-to-many special -> topping relationship that is friendly for serialization - modelBuilder.Entity().HasKey(pst => new { pst.PizzaId, pst.ToppingId }); - modelBuilder.Entity().HasOne().WithMany(ps => ps.Toppings); - modelBuilder.Entity().HasOne(pst => pst.Topping).WithMany(); + // Configuring a many-to-many special -> topping relationship that is friendly for serialization + modelBuilder.Entity().HasKey(pst => new { pst.PizzaId, pst.ToppingId }); + modelBuilder.Entity().HasOne().WithMany(ps => ps.Toppings); + modelBuilder.Entity().HasOne(pst => pst.Topping).WithMany(); - // Inline the Lat-Long pairs in Order rather than having a FK to another table - modelBuilder.Entity().OwnsOne(o => o.DeliveryLocation); - } - } -} \ No newline at end of file + // Inline the Lat-Long pairs in Order rather than having a FK to another table + modelBuilder.Entity().OwnsOne(o => o.DeliveryLocation); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/PizzaStoreUser.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/PizzaStoreUser.cs index 171ce83d..d446a679 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Server/PizzaStoreUser.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/PizzaStoreUser.cs @@ -1,8 +1,6 @@ using Microsoft.AspNetCore.Identity; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; +public class PizzaStoreUser : IdentityUser { - public class PizzaStoreUser : IdentityUser - { - } } \ No newline at end of file diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/PizzasController.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/PizzasController.cs deleted file mode 100644 index c082552c..00000000 --- a/save-points/02-customize-a-pizza/BlazingPizza.Server/PizzasController.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("pizzas")] - [ApiController] - public class PizzasController : Controller - { - private readonly PizzaStoreContext _db; - - public PizzasController(PizzaStoreContext db) - { - _db = db; - } - } -} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Program.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Program.cs index 40a47641..4484d8f7 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Server/Program.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Program.cs @@ -1,33 +1,67 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; +using Microsoft.AspNetCore.Authentication; +using Microsoft.EntityFrameworkCore; +using BlazingPizza.Server; -namespace BlazingPizza.Server +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddControllersWithViews() + .AddJsonOptions(options => { + options.JsonSerializerOptions.AddContext(); + }); +builder.Services.AddRazorPages(); + +builder.Services.AddDbContext(options => + options.UseSqlite("Data Source=pizza.db") + .UseModel(BlazingPizza.Server.Models.PizzaStoreContextModel.Instance)); + +builder.Services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) + .AddEntityFrameworkStores(); + +builder.Services.AddIdentityServer() + .AddApiAuthorization(); + +builder.Services.AddAuthentication() + .AddIdentityServerJwt(); + +var app = builder.Build(); + +// Initialize the database +var scopeFactory = app.Services.GetRequiredService(); +using (var scope = scopeFactory.CreateScope()) +{ + var db = scope.ServiceProvider.GetRequiredService(); + if (db.Database.EnsureCreated()) + { + SeedData.Initialize(db); + } +} + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseWebAssemblyDebugging(); +} +else { - public class Program - { - public static void Main(string[] args) - { - var host = CreateHostBuilder(args).Build(); - - // Initialize the database - var scopeFactory = host.Services.GetRequiredService(); - using (var scope = scopeFactory.CreateScope()) - { - var db = scope.ServiceProvider.GetRequiredService(); - if (db.Database.EnsureCreated()) - { - SeedData.Initialize(db); - } - } - - host.Run(); - } - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); - } + app.UseExceptionHandler("/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); } + +app.UseHttpsRedirection(); +app.UseBlazorFrameworkFiles(); +app.UseStaticFiles(); + +app.UseRouting(); + +app.UseAuthentication(); +app.UseIdentityServer(); +app.UseAuthorization(); + +app.MapPizzaApi(); + +app.MapRazorPages(); +app.MapControllers(); +app.MapFallbackToFile("index.html"); + +app.Run(); \ No newline at end of file diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/SeedData.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/SeedData.cs index 7c86a5b2..a1e47973 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Server/SeedData.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/SeedData.cs @@ -1,193 +1,192 @@ -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public static class SeedData { - public static class SeedData - { - public static void Initialize(PizzaStoreContext db) - { - var toppings = new Topping[] - { - new Topping() - { - Name = "Extra cheese", - Price = 2.50m, - }, - new Topping() - { - Name = "American bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "British bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "Canadian bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "Tea and crumpets", - Price = 5.00m - }, - new Topping() - { - Name = "Fresh-baked scones", - Price = 4.50m, - }, - new Topping() - { - Name = "Bell peppers", - Price = 1.00m, - }, - new Topping() - { - Name = "Onions", - Price = 1.00m, - }, - new Topping() - { - Name = "Mushrooms", - Price = 1.00m, - }, - new Topping() - { - Name = "Pepperoni", - Price = 1.00m, - }, - new Topping() - { - Name = "Duck sausage", - Price = 3.20m, - }, - new Topping() - { - Name = "Venison meatballs", - Price = 2.50m, - }, - new Topping() - { - Name = "Served on a silver platter", - Price = 250.99m, - }, - new Topping() - { - Name = "Lobster on top", - Price = 64.50m, - }, - new Topping() - { - Name = "Sturgeon caviar", - Price = 101.75m, - }, - new Topping() - { - Name = "Artichoke hearts", - Price = 3.40m, - }, - new Topping() - { - Name = "Fresh tomatoes", - Price = 1.50m, - }, - new Topping() - { - Name = "Basil", - Price = 1.50m, - }, - new Topping() - { - Name = "Steak (medium-rare)", - Price = 8.50m, - }, - new Topping() - { - Name = "Blazing hot peppers", - Price = 4.20m, - }, - new Topping() - { - Name = "Buffalo chicken", - Price = 5.00m, - }, - new Topping() - { - Name = "Blue cheese", - Price = 2.50m, - }, - }; + public static void Initialize(PizzaStoreContext db) + { + var toppings = new Topping[] + { + new Topping() + { + Name = "Extra cheese", + Price = 2.50m, + }, + new Topping() + { + Name = "American bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "British bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "Canadian bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "Tea and crumpets", + Price = 5.00m + }, + new Topping() + { + Name = "Fresh-baked scones", + Price = 4.50m, + }, + new Topping() + { + Name = "Bell peppers", + Price = 1.00m, + }, + new Topping() + { + Name = "Onions", + Price = 1.00m, + }, + new Topping() + { + Name = "Mushrooms", + Price = 1.00m, + }, + new Topping() + { + Name = "Pepperoni", + Price = 1.00m, + }, + new Topping() + { + Name = "Duck sausage", + Price = 3.20m, + }, + new Topping() + { + Name = "Venison meatballs", + Price = 2.50m, + }, + new Topping() + { + Name = "Served on a silver platter", + Price = 250.99m, + }, + new Topping() + { + Name = "Lobster on top", + Price = 64.50m, + }, + new Topping() + { + Name = "Sturgeon caviar", + Price = 101.75m, + }, + new Topping() + { + Name = "Artichoke hearts", + Price = 3.40m, + }, + new Topping() + { + Name = "Fresh tomatoes", + Price = 1.50m, + }, + new Topping() + { + Name = "Basil", + Price = 1.50m, + }, + new Topping() + { + Name = "Steak (medium-rare)", + Price = 8.50m, + }, + new Topping() + { + Name = "Blazing hot peppers", + Price = 4.20m, + }, + new Topping() + { + Name = "Buffalo chicken", + Price = 5.00m, + }, + new Topping() + { + Name = "Blue cheese", + Price = 2.50m, + }, + }; - var specials = new PizzaSpecial[] - { - new PizzaSpecial() - { - Name = "Basic Cheese Pizza", - Description = "It's cheesy and delicious. Why wouldn't you want one?", - BasePrice = 9.99m, - ImageUrl = "img/pizzas/cheese.jpg", - }, - new PizzaSpecial() - { - Id = 2, - Name = "The Baconatorizor", - Description = "It has EVERY kind of bacon", - BasePrice = 11.99m, - ImageUrl = "img/pizzas/bacon.jpg", - }, - new PizzaSpecial() - { - Id = 3, - Name = "Classic pepperoni", - Description = "It's the pizza you grew up with, but Blazing hot!", - BasePrice = 10.50m, - ImageUrl = "img/pizzas/pepperoni.jpg", - }, - new PizzaSpecial() - { - Id = 4, - Name = "Buffalo chicken", - Description = "Spicy chicken, hot sauce and bleu cheese, guaranteed to warm you up", - BasePrice = 12.75m, - ImageUrl = "img/pizzas/meaty.jpg", - }, - new PizzaSpecial() - { - Id = 5, - Name = "Mushroom Lovers", - Description = "It has mushrooms. Isn't that obvious?", - BasePrice = 11.00m, - ImageUrl = "img/pizzas/mushroom.jpg", - }, - new PizzaSpecial() - { - Id = 6, - Name = "The Brit", - Description = "When in London...", - BasePrice = 10.25m, - ImageUrl = "img/pizzas/brit.jpg", - }, - new PizzaSpecial() - { - Id = 7, - Name = "Veggie Delight", - Description = "It's like salad, but on a pizza", - BasePrice = 11.50m, - ImageUrl = "img/pizzas/salad.jpg", - }, - new PizzaSpecial() - { - Id = 8, - Name = "Margherita", - Description = "Traditional Italian pizza with tomatoes and basil", - BasePrice = 9.99m, - ImageUrl = "img/pizzas/margherita.jpg", - }, - }; + var specials = new PizzaSpecial[] + { + new PizzaSpecial() + { + Name = "Basic Cheese Pizza", + Description = "It's cheesy and delicious. Why wouldn't you want one?", + BasePrice = 9.99m, + ImageUrl = "img/pizzas/cheese.jpg", + }, + new PizzaSpecial() + { + Id = 2, + Name = "The Baconatorizor", + Description = "It has EVERY kind of bacon", + BasePrice = 11.99m, + ImageUrl = "img/pizzas/bacon.jpg", + }, + new PizzaSpecial() + { + Id = 3, + Name = "Classic pepperoni", + Description = "It's the pizza you grew up with, but Blazing hot!", + BasePrice = 10.50m, + ImageUrl = "img/pizzas/pepperoni.jpg", + }, + new PizzaSpecial() + { + Id = 4, + Name = "Buffalo chicken", + Description = "Spicy chicken, hot sauce and bleu cheese, guaranteed to warm you up", + BasePrice = 12.75m, + ImageUrl = "img/pizzas/meaty.jpg", + }, + new PizzaSpecial() + { + Id = 5, + Name = "Mushroom Lovers", + Description = "It has mushrooms. Isn't that obvious?", + BasePrice = 11.00m, + ImageUrl = "img/pizzas/mushroom.jpg", + }, + new PizzaSpecial() + { + Id = 6, + Name = "The Brit", + Description = "When in London...", + BasePrice = 10.25m, + ImageUrl = "img/pizzas/brit.jpg", + }, + new PizzaSpecial() + { + Id = 7, + Name = "Veggie Delight", + Description = "It's like salad, but on a pizza", + BasePrice = 11.50m, + ImageUrl = "img/pizzas/salad.jpg", + }, + new PizzaSpecial() + { + Id = 8, + Name = "Margherita", + Description = "Traditional Italian pizza with tomatoes and basil", + BasePrice = 9.99m, + ImageUrl = "img/pizzas/margherita.jpg", + }, + }; - db.Toppings.AddRange(toppings); - db.Specials.AddRange(specials); - db.SaveChanges(); - } - } -} + db.Toppings.AddRange(toppings); + db.Specials.AddRange(specials); + db.SaveChanges(); + } +} \ No newline at end of file diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Shared/Address.cs b/save-points/02-customize-a-pizza/BlazingPizza.Shared/Address.cs index e5c0ef0d..63f1e167 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Shared/Address.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Shared/Address.cs @@ -1,21 +1,26 @@ using System.ComponentModel.DataAnnotations; -namespace BlazingPizza +namespace BlazingPizza; + +public class Address { - public class Address - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + [Required, MaxLength(100)] + public string Name { get; set; } - public string Line1 { get; set; } + [Required, MaxLength(100)] + public string Line1 { get; set; } - public string Line2 { get; set; } + [MaxLength(100)] + public string Line2 { get; set; } - public string City { get; set; } + [Required, MaxLength(50)] + public string City { get; set; } - public string Region { get; set; } + [Required, MaxLength(20)] + public string Region { get; set; } - public string PostalCode { get; set; } - } + [Required, MaxLength(20)] + public string PostalCode { get; set; } } diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/save-points/02-customize-a-pizza/BlazingPizza.Shared/BlazingPizza.Shared.csproj index f7b7dd02..075ddd60 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/save-points/02-customize-a-pizza/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -3,6 +3,7 @@ $(TargetFrameworkVersion) BlazingPizza + true diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Shared/LatLong.cs b/save-points/02-customize-a-pizza/BlazingPizza.Shared/LatLong.cs index 9b8c3811..14a94c26 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Shared/LatLong.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Shared/LatLong.cs @@ -1,27 +1,26 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class LatLong { - public class LatLong - { - public LatLong() - { - } + public LatLong() + { + } - public LatLong(double latitude, double longitude) : this() - { - Latitude = latitude; - Longitude = longitude; - } + public LatLong(double latitude, double longitude) : this() + { + Latitude = latitude; + Longitude = longitude; + } - public double Latitude { get; set; } + public double Latitude { get; set; } - public double Longitude { get; set; } + public double Longitude { get; set; } - public static LatLong Interpolate(LatLong start, LatLong end, double proportion) - { - // The Earth is flat, right? So no need for spherical interpolation. - return new LatLong( - start.Latitude + (end.Latitude - start.Latitude) * proportion, - start.Longitude + (end.Longitude - start.Longitude) * proportion); - } - } -} + public static LatLong Interpolate(LatLong start, LatLong end, double proportion) + { + // The Earth is flat, right? So no need for spherical interpolation. + return new LatLong( + start.Latitude + (end.Latitude - start.Latitude) * proportion, + start.Longitude + (end.Longitude - start.Longitude) * proportion); + } +} \ No newline at end of file diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Shared/NotificationSubscription.cs b/save-points/02-customize-a-pizza/BlazingPizza.Shared/NotificationSubscription.cs index 04259c2f..9109ff57 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Shared/NotificationSubscription.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Shared/NotificationSubscription.cs @@ -1,17 +1,14 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class NotificationSubscription { - public class NotificationSubscription - { - public int NotificationSubscriptionId { get; set; } + public int NotificationSubscriptionId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public string Url { get; set; } + public string Url { get; set; } - public string P256dh { get; set; } + public string P256dh { get; set; } - public string Auth { get; set; } - } + public string Auth { get; set; } } diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Shared/Order.cs b/save-points/02-customize-a-pizza/BlazingPizza.Shared/Order.cs index fb003bd6..aca04ca1 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Shared/Order.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Shared/Order.cs @@ -1,25 +1,32 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +public class Order { - public class Order - { - public int OrderId { get; set; } + public int OrderId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public DateTime CreatedTime { get; set; } + public DateTime CreatedTime { get; set; } - public Address DeliveryAddress { get; set; } = new Address(); + public Address DeliveryAddress { get; set; } = new Address(); - public LatLong DeliveryLocation { get; set; } + public LatLong DeliveryLocation { get; set; } - public List Pizzas { get; set; } = new List(); + public List Pizzas { get; set; } = new List(); - public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); + public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); - public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); - } + public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Default, PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] +[JsonSerializable(typeof(Order))] +[JsonSerializable(typeof(OrderWithStatus))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Pizza))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Topping))] +public partial class OrderContext : JsonSerializerContext {} \ No newline at end of file diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Shared/OrderWithStatus.cs b/save-points/02-customize-a-pizza/BlazingPizza.Shared/OrderWithStatus.cs index 021de78c..f5f153b6 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Shared/OrderWithStatus.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Shared/OrderWithStatus.cs @@ -1,79 +1,78 @@ -using BlazingPizza.ComponentsLibrary.Map; -using System; -using System.Collections.Generic; +using System.Text.Json.Serialization; +using BlazingPizza.ComponentsLibrary.Map; -namespace BlazingPizza + +namespace BlazingPizza; + +public class OrderWithStatus { - public class OrderWithStatus - { - public readonly static TimeSpan PreparationDuration = TimeSpan.FromSeconds(10); - public readonly static TimeSpan DeliveryDuration = TimeSpan.FromMinutes(1); // Unrealistic, but more interesting to watch + public readonly static TimeSpan PreparationDuration = TimeSpan.FromSeconds(10); + public readonly static TimeSpan DeliveryDuration = TimeSpan.FromMinutes(1); // Unrealistic, but more interesting to watch - public Order Order { get; set; } + public Order Order { get; set; } - public string StatusText { get; set; } + public string StatusText { get; set; } - public bool IsDelivered => StatusText == "Delivered"; + public bool IsDelivered => StatusText == "Delivered"; - public List MapMarkers { get; set; } + public List MapMarkers { get; set; } - public static OrderWithStatus FromOrder(Order order) - { - // To simulate a real backend process, we fake status updates based on the amount - // of time since the order was placed - string statusText; - List mapMarkers; - var dispatchTime = order.CreatedTime.Add(PreparationDuration); + public static OrderWithStatus FromOrder(Order order) + { + // To simulate a real backend process, we fake status updates based on the amount + // of time since the order was placed + string statusText; + List mapMarkers; + var dispatchTime = order.CreatedTime.Add(PreparationDuration); - if (DateTime.Now < dispatchTime) - { - statusText = "Preparing"; - mapMarkers = new List - { - ToMapMarker("You", order.DeliveryLocation, showPopup: true) - }; - } - else if (DateTime.Now < dispatchTime + DeliveryDuration) - { - statusText = "Out for delivery"; + if (DateTime.Now < dispatchTime) + { + statusText = "Preparing"; + mapMarkers = new List + { + ToMapMarker("You", order.DeliveryLocation, showPopup: true) + }; + } + else if (DateTime.Now < dispatchTime + DeliveryDuration) + { + statusText = "Out for delivery"; - var startPosition = ComputeStartPosition(order); - var proportionOfDeliveryCompleted = Math.Min(1, (DateTime.Now - dispatchTime).TotalMilliseconds / DeliveryDuration.TotalMilliseconds); - var driverPosition = LatLong.Interpolate(startPosition, order.DeliveryLocation, proportionOfDeliveryCompleted); - mapMarkers = new List - { - ToMapMarker("You", order.DeliveryLocation), - ToMapMarker("Driver", driverPosition, showPopup: true), - }; - } - else - { - statusText = "Delivered"; - mapMarkers = new List - { - ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), - }; - } + var startPosition = ComputeStartPosition(order); + var proportionOfDeliveryCompleted = Math.Min(1, (DateTime.Now - dispatchTime).TotalMilliseconds / DeliveryDuration.TotalMilliseconds); + var driverPosition = LatLong.Interpolate(startPosition, order.DeliveryLocation, proportionOfDeliveryCompleted); + mapMarkers = new List + { + ToMapMarker("You", order.DeliveryLocation), + ToMapMarker("Driver", driverPosition, showPopup: true), + }; + } + else + { + statusText = "Delivered"; + mapMarkers = new List + { + ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), + }; + } - return new OrderWithStatus - { - Order = order, - StatusText = statusText, - MapMarkers = mapMarkers, - }; - } + return new OrderWithStatus + { + Order = order, + StatusText = statusText, + MapMarkers = mapMarkers, + }; + } - private static LatLong ComputeStartPosition(Order order) - { - // Random but deterministic based on order ID - var rng = new Random(order.OrderId); - var distance = 0.01 + rng.NextDouble() * 0.02; - var angle = rng.NextDouble() * Math.PI * 2; - var offset = (distance * Math.Cos(angle), distance * Math.Sin(angle)); - return new LatLong(order.DeliveryLocation.Latitude + offset.Item1, order.DeliveryLocation.Longitude + offset.Item2); - } + private static LatLong ComputeStartPosition(Order order) + { + // Random but deterministic based on order ID + var rng = new Random(order.OrderId); + var distance = 0.01 + rng.NextDouble() * 0.02; + var angle = rng.NextDouble() * Math.PI * 2; + var offset = (distance * Math.Cos(angle), distance * Math.Sin(angle)); + return new LatLong(order.DeliveryLocation.Latitude + offset.Item1, order.DeliveryLocation.Longitude + offset.Item2); + } - static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) - => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; - } -} + static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) + => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; +} \ No newline at end of file diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Shared/Pizza.cs b/save-points/02-customize-a-pizza/BlazingPizza.Shared/Pizza.cs index ec1108a9..459298f4 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Shared/Pizza.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Shared/Pizza.cs @@ -1,42 +1,44 @@ -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// /// Represents a customized pizza as part of an order +/// +public class Pizza { - /// - /// Represents a customized pizza as part of an order - /// - public class Pizza - { - public const int DefaultSize = 12; - public const int MinimumSize = 9; - public const int MaximumSize = 17; + public const int DefaultSize = 12; + public const int MinimumSize = 9; + public const int MaximumSize = 17; - public int Id { get; set; } + public int Id { get; set; } - public int OrderId { get; set; } + public int OrderId { get; set; } - public PizzaSpecial Special { get; set; } + public PizzaSpecial Special { get; set; } - public int SpecialId { get; set; } + public int SpecialId { get; set; } - public int Size { get; set; } + public int Size { get; set; } - public List Toppings { get; set; } + public List Toppings { get; set; } - public decimal GetBasePrice() - { - return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; - } + public decimal GetBasePrice() + { + return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; + } - public decimal GetTotalPrice() - { - return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); - } + public decimal GetTotalPrice() + { + return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); + } - public string GetFormattedTotalPrice() - { - return GetTotalPrice().ToString("0.00"); - } - } + public string GetFormattedTotalPrice() + { + return GetTotalPrice().ToString("0.00"); + } } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Serialization)] +[JsonSerializable(typeof(Pizza))] +public partial class PizzaContext : JsonSerializerContext {} \ No newline at end of file diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Shared/PizzaSpecial.cs b/save-points/02-customize-a-pizza/BlazingPizza.Shared/PizzaSpecial.cs index 2f2b3383..9653300c 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Shared/PizzaSpecial.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Shared/PizzaSpecial.cs @@ -1,20 +1,19 @@ -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// Represents a pre-configured template for a pizza a user can order +/// +public class PizzaSpecial { - /// - /// Represents a pre-configured template for a pizza a user can order - /// - public class PizzaSpecial - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal BasePrice { get; set; } + public decimal BasePrice { get; set; } - public string Description { get; set; } + public string Description { get; set; } - public string ImageUrl { get; set; } + public string ImageUrl { get; set; } - public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); - } -} + public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); +} \ No newline at end of file diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Shared/PizzaTopping.cs b/save-points/02-customize-a-pizza/BlazingPizza.Shared/PizzaTopping.cs index f5a6c1ac..0a711647 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Shared/PizzaTopping.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Shared/PizzaTopping.cs @@ -1,11 +1,11 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class PizzaTopping { - public class PizzaTopping - { - public Topping Topping { get; set; } + public Topping Topping { get; set; } + + public int ToppingId { get; set; } - public int ToppingId { get; set; } - - public int PizzaId { get; set; } - } -} + public int PizzaId { get; set; } + +} \ No newline at end of file diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Shared/Topping.cs b/save-points/02-customize-a-pizza/BlazingPizza.Shared/Topping.cs index 61bdeb92..376c311a 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Shared/Topping.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Shared/Topping.cs @@ -1,13 +1,13 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class Topping { - public class Topping - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal Price { get; set; } + public decimal Price { get; set; } - public string GetFormattedPrice() => Price.ToString("0.00"); - } -} + public string GetFormattedPrice() => Price.ToString("0.00"); + +} \ No newline at end of file diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Shared/UserInfo.cs b/save-points/02-customize-a-pizza/BlazingPizza.Shared/UserInfo.cs index 4996ef80..362f8f8e 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Shared/UserInfo.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Shared/UserInfo.cs @@ -1,9 +1,9 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class UserInfo { - public class UserInfo - { - public bool IsAuthenticated { get; set; } + public bool IsAuthenticated { get; set; } - public string Name { get; set; } - } -} + public string Name { get; set; } + +} \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Client/BlazingPizza.Client.csproj b/save-points/03-show-order-status/BlazingPizza.Client/BlazingPizza.Client.csproj index 663677a1..f9ebe283 100644 --- a/save-points/03-show-order-status/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/save-points/03-show-order-status/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -2,6 +2,7 @@ $(TargetFrameworkVersion) + true diff --git a/save-points/03-show-order-status/BlazingPizza.Client/Program.cs b/save-points/03-show-order-status/BlazingPizza.Client/Program.cs index 48147d6f..ab7dd4d9 100644 --- a/save-points/03-show-order-status/BlazingPizza.Client/Program.cs +++ b/save-points/03-show-order-status/BlazingPizza.Client/Program.cs @@ -1,21 +1,9 @@ -using Microsoft.AspNetCore.Components.WebAssembly.Hosting; -using Microsoft.Extensions.DependencyInjection; -using System; -using System.Net.Http; -using System.Threading.Tasks; +using BlazingPizza.Client; +using Microsoft.AspNetCore.Components.WebAssembly.Hosting; -namespace BlazingPizza.Client -{ - public class Program - { - public static async Task Main(string[] args) - { - var builder = WebAssemblyHostBuilder.CreateDefault(args); - builder.RootComponents.Add("#app"); +var builder = WebAssemblyHostBuilder.CreateDefault(args); +builder.RootComponents.Add("#app"); - builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); +builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); - await builder.Build().RunAsync(); - } - } -} +await builder.Build().RunAsync(); diff --git a/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 61ebf623..cb996b1b 100644 --- a/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -2,6 +2,7 @@ $(TargetFrameworkVersion) + true diff --git a/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/LocalStorage.cs b/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/LocalStorage.cs index f36b098e..bb84f13c 100644 --- a/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/LocalStorage.cs +++ b/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/LocalStorage.cs @@ -1,17 +1,15 @@ using Microsoft.JSInterop; -using System.Threading.Tasks; -namespace BlazingPizza.ComponentsLibrary +namespace BlazingPizza.ComponentsLibrary; + +public static class LocalStorage { - public static class LocalStorage - { - public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) - => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); + public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) + => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); - public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object value) - => jsRuntime.InvokeVoidAsync("blazorLocalStorage.set", key, value); + public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object value) + => jsRuntime.InvokeVoidAsync("blazorLocalStorage.set", key, value); - public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key) - => jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key); - } -} + public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key) + => jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key); +} \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/Map/Marker.cs b/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/Map/Marker.cs index 63006067..a8e78f2a 100644 --- a/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/Map/Marker.cs +++ b/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/Map/Marker.cs @@ -1,13 +1,12 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Marker { - public class Marker - { - public string Description { get; set; } + public string Description { get; set; } - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } + public double Y { get; set; } - public bool ShowPopup { get; set; } - } + public bool ShowPopup { get; set; } } diff --git a/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/Map/Point.cs b/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/Map/Point.cs index 03841826..349046d4 100644 --- a/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/Map/Point.cs +++ b/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/Map/Point.cs @@ -1,9 +1,8 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Point { - public class Point - { - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } - } -} + public double Y { get; set; } +} \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Server/BlazingPizza.Server.csproj b/save-points/03-show-order-status/BlazingPizza.Server/BlazingPizza.Server.csproj index b9c74fc4..227890e1 100644 --- a/save-points/03-show-order-status/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/save-points/03-show-order-status/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -2,6 +2,7 @@ $(TargetFrameworkVersion) + true diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/AddressEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/AddressEntityType.cs new file mode 100644 index 00000000..82db81b6 --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/AddressEntityType.cs @@ -0,0 +1,92 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class AddressEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Address", + typeof(Address), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Address).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var city = runtimeEntityType.AddProperty( + "City", + typeof(string), + propertyInfo: typeof(Address).GetProperty("City", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var line1 = runtimeEntityType.AddProperty( + "Line1", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line1", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var line2 = runtimeEntityType.AddProperty( + "Line2", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line2", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var postalCode = runtimeEntityType.AddProperty( + "PostalCode", + typeof(string), + propertyInfo: typeof(Address).GetProperty("PostalCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var region = runtimeEntityType.AddProperty( + "Region", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Region", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Address"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs new file mode 100644 index 00000000..1dd4563b --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs @@ -0,0 +1,114 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class DeviceFlowCodesEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.DeviceFlowCodes", + typeof(DeviceFlowCodes), + baseEntityType); + + var userCode = runtimeEntityType.AddProperty( + "UserCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("UserCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var deviceCode = runtimeEntityType.AddProperty( + "DeviceCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("DeviceCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var key = runtimeEntityType.AddKey( + new[] { userCode }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deviceCode }, + unique: true); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "DeviceCodes"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs new file mode 100644 index 00000000..8946b261 --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRoleClaim", + typeof(IdentityRoleClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoleClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityRoleEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityRoleEntityType.cs new file mode 100644 index 00000000..2f1fec2b --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityRoleEntityType.cs @@ -0,0 +1,78 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRole", + typeof(IdentityRole), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedName = runtimeEntityType.AddProperty( + "NormalizedName", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("NormalizedName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedName }, + unique: true); + index.AddAnnotation("Relational:Name", "RoleNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs new file mode 100644 index 00000000..55418a1e --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserClaim", + typeof(IdentityUserClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityUserClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs new file mode 100644 index 00000000..3ca029bd --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserLoginstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserLogin", + typeof(IdentityUserLogin), + baseEntityType); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerKey = runtimeEntityType.AddProperty( + "ProviderKey", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderKey", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerDisplayName = runtimeEntityType.AddProperty( + "ProviderDisplayName", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderDisplayName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { loginProvider, providerKey }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserLogins"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs new file mode 100644 index 00000000..70078d7a --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs @@ -0,0 +1,82 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserRolestringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserRole", + typeof(IdentityUserRole), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { userId, roleId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs new file mode 100644 index 00000000..93ba6d31 --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs @@ -0,0 +1,84 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserTokenstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserToken", + typeof(IdentityUserToken), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var value = runtimeEntityType.AddProperty( + "Value", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Value", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { userId, loginProvider, name }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserTokens"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/KeyEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/KeyEntityType.cs new file mode 100644 index 00000000..f6c6b4c7 --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/KeyEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class KeyEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.Key", + typeof(Key), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var algorithm = runtimeEntityType.AddProperty( + "Algorithm", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Algorithm", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var created = runtimeEntityType.AddProperty( + "Created", + typeof(DateTime), + propertyInfo: typeof(Key).GetProperty("Created", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var dataProtected = runtimeEntityType.AddProperty( + "DataProtected", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("DataProtected", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var isX509Certificate = runtimeEntityType.AddProperty( + "IsX509Certificate", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("IsX509Certificate", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var use = runtimeEntityType.AddProperty( + "Use", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Use", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var version = runtimeEntityType.AddProperty( + "Version", + typeof(int), + propertyInfo: typeof(Key).GetProperty("Version", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { use }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Keys"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/LatLongEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/LatLongEntityType.cs new file mode 100644 index 00000000..3fd254bd --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/LatLongEntityType.cs @@ -0,0 +1,80 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class LatLongEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.LatLong", + typeof(LatLong), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var latitude = runtimeEntityType.AddProperty( + "Latitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Latitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var longitude = runtimeEntityType.AddProperty( + "Longitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Longitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + unique: true, + required: true, + ownership: true); + + var deliveryLocation = principalEntityType.AddNavigation("DeliveryLocation", + runtimeForeignKey, + onDependent: false, + typeof(LatLong), + propertyInfo: typeof(Order).GetProperty("DeliveryLocation", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + eagerLoaded: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs new file mode 100644 index 00000000..db236e4c --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs @@ -0,0 +1,77 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class NotificationSubscriptionEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.NotificationSubscription", + typeof(NotificationSubscription), + baseEntityType); + + var notificationSubscriptionId = runtimeEntityType.AddProperty( + "NotificationSubscriptionId", + typeof(int), + propertyInfo: typeof(NotificationSubscription).GetProperty("NotificationSubscriptionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var auth = runtimeEntityType.AddProperty( + "Auth", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Auth", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var p256dh = runtimeEntityType.AddProperty( + "P256dh", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("P256dh", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var url = runtimeEntityType.AddProperty( + "Url", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Url", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { notificationSubscriptionId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "NotificationSubscriptions"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/OrderEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/OrderEntityType.cs new file mode 100644 index 00000000..9d9ec6fd --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/OrderEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class OrderEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Order", + typeof(Order), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Order).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var createdTime = runtimeEntityType.AddProperty( + "CreatedTime", + typeof(DateTime), + propertyInfo: typeof(Order).GetProperty("CreatedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var deliveryAddressId = runtimeEntityType.AddProperty( + "DeliveryAddressId", + typeof(int?), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(Order).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deliveryAddressId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("DeliveryAddressId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType); + + var deliveryAddress = declaringEntityType.AddNavigation("DeliveryAddress", + runtimeForeignKey, + onDependent: true, + typeof(Address), + propertyInfo: typeof(Order).GetProperty("DeliveryAddress", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/PersistedGrantEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/PersistedGrantEntityType.cs new file mode 100644 index 00000000..842d53a5 --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/PersistedGrantEntityType.cs @@ -0,0 +1,127 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PersistedGrantEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.PersistedGrant", + typeof(PersistedGrant), + baseEntityType); + + var key = runtimeEntityType.AddProperty( + "Key", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Key", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var consumedTime = runtimeEntityType.AddProperty( + "ConsumedTime", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("ConsumedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(PersistedGrant).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var type = runtimeEntityType.AddProperty( + "Type", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Type", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var key0 = runtimeEntityType.AddKey( + new[] { key }); + runtimeEntityType.SetPrimaryKey(key0); + + var index = runtimeEntityType.AddIndex( + new[] { consumedTime }); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + var index1 = runtimeEntityType.AddIndex( + new[] { subjectId, clientId, type }); + + var index2 = runtimeEntityType.AddIndex( + new[] { subjectId, sessionId, type }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PersistedGrants"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaEntityType.cs new file mode 100644 index 00000000..3a124e63 --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaEntityType.cs @@ -0,0 +1,111 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Pizza", + typeof(Pizza), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var size = runtimeEntityType.AddProperty( + "Size", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Size", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var specialId = runtimeEntityType.AddProperty( + "SpecialId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("SpecialId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { orderId }); + + var index0 = runtimeEntityType.AddIndex( + new[] { specialId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var pizzas = principalEntityType.AddNavigation("Pizzas", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Order).GetProperty("Pizzas", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("SpecialId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var special = declaringEntityType.AddNavigation("Special", + runtimeForeignKey, + onDependent: true, + typeof(PizzaSpecial), + propertyInfo: typeof(Pizza).GetProperty("Special", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Pizzas"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs new file mode 100644 index 00000000..e86b0f50 --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs @@ -0,0 +1,76 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaSpecialEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaSpecial", + typeof(PizzaSpecial), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(PizzaSpecial).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var basePrice = runtimeEntityType.AddProperty( + "BasePrice", + typeof(decimal), + propertyInfo: typeof(PizzaSpecial).GetProperty("BasePrice", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var imageUrl = runtimeEntityType.AddProperty( + "ImageUrl", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("ImageUrl", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Specials"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaStoreContextModel.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaStoreContextModel.cs new file mode 100644 index 00000000..8b516a68 --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaStoreContextModel.cs @@ -0,0 +1,28 @@ +// +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + [DbContext(typeof(PizzaStoreContext))] + public partial class PizzaStoreContextModel : RuntimeModel + { + static PizzaStoreContextModel() + { + var model = new PizzaStoreContextModel(); + model.Initialize(); + model.Customize(); + _instance = model; + } + + private static PizzaStoreContextModel _instance; + public static IModel Instance => _instance; + + partial void Initialize(); + + partial void Customize(); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs new file mode 100644 index 00000000..d46f50f4 --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs @@ -0,0 +1,69 @@ +// +using System; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + public partial class PizzaStoreContextModel + { + partial void Initialize() + { + var address = AddressEntityType.Create(this); + var latLong = LatLongEntityType.Create(this); + var notificationSubscription = NotificationSubscriptionEntityType.Create(this); + var order = OrderEntityType.Create(this); + var pizza = PizzaEntityType.Create(this); + var pizzaSpecial = PizzaSpecialEntityType.Create(this); + var pizzaTopping = PizzaToppingEntityType.Create(this); + var pizzaStoreUser = PizzaStoreUserEntityType.Create(this); + var topping = ToppingEntityType.Create(this); + var deviceFlowCodes = DeviceFlowCodesEntityType.Create(this); + var key = KeyEntityType.Create(this); + var persistedGrant = PersistedGrantEntityType.Create(this); + var identityRole = IdentityRoleEntityType.Create(this); + var identityRoleClaimstring = IdentityRoleClaimstringEntityType.Create(this); + var identityUserClaimstring = IdentityUserClaimstringEntityType.Create(this); + var identityUserLoginstring = IdentityUserLoginstringEntityType.Create(this); + var identityUserRolestring = IdentityUserRolestringEntityType.Create(this); + var identityUserTokenstring = IdentityUserTokenstringEntityType.Create(this); + + LatLongEntityType.CreateForeignKey1(latLong, order); + OrderEntityType.CreateForeignKey1(order, address); + PizzaEntityType.CreateForeignKey1(pizza, order); + PizzaEntityType.CreateForeignKey2(pizza, pizzaSpecial); + PizzaToppingEntityType.CreateForeignKey1(pizzaTopping, pizza); + PizzaToppingEntityType.CreateForeignKey2(pizzaTopping, topping); + IdentityRoleClaimstringEntityType.CreateForeignKey1(identityRoleClaimstring, identityRole); + IdentityUserClaimstringEntityType.CreateForeignKey1(identityUserClaimstring, pizzaStoreUser); + IdentityUserLoginstringEntityType.CreateForeignKey1(identityUserLoginstring, pizzaStoreUser); + IdentityUserRolestringEntityType.CreateForeignKey1(identityUserRolestring, identityRole); + IdentityUserRolestringEntityType.CreateForeignKey2(identityUserRolestring, pizzaStoreUser); + IdentityUserTokenstringEntityType.CreateForeignKey1(identityUserTokenstring, pizzaStoreUser); + + AddressEntityType.CreateAnnotations(address); + LatLongEntityType.CreateAnnotations(latLong); + NotificationSubscriptionEntityType.CreateAnnotations(notificationSubscription); + OrderEntityType.CreateAnnotations(order); + PizzaEntityType.CreateAnnotations(pizza); + PizzaSpecialEntityType.CreateAnnotations(pizzaSpecial); + PizzaToppingEntityType.CreateAnnotations(pizzaTopping); + PizzaStoreUserEntityType.CreateAnnotations(pizzaStoreUser); + ToppingEntityType.CreateAnnotations(topping); + DeviceFlowCodesEntityType.CreateAnnotations(deviceFlowCodes); + KeyEntityType.CreateAnnotations(key); + PersistedGrantEntityType.CreateAnnotations(persistedGrant); + IdentityRoleEntityType.CreateAnnotations(identityRole); + IdentityRoleClaimstringEntityType.CreateAnnotations(identityRoleClaimstring); + IdentityUserClaimstringEntityType.CreateAnnotations(identityUserClaimstring); + IdentityUserLoginstringEntityType.CreateAnnotations(identityUserLoginstring); + IdentityUserRolestringEntityType.CreateAnnotations(identityUserRolestring); + IdentityUserTokenstringEntityType.CreateAnnotations(identityUserTokenstring); + + AddAnnotation("ProductVersion", "6.0.0"); + } + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs new file mode 100644 index 00000000..18b2d96d --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs @@ -0,0 +1,156 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaStoreUserEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Server.PizzaStoreUser", + typeof(PizzaStoreUser), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var accessFailedCount = runtimeEntityType.AddProperty( + "AccessFailedCount", + typeof(int), + propertyInfo: typeof(IdentityUser).GetProperty("AccessFailedCount", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var email = runtimeEntityType.AddProperty( + "Email", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Email", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var emailConfirmed = runtimeEntityType.AddProperty( + "EmailConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("EmailConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnabled = runtimeEntityType.AddProperty( + "LockoutEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnd = runtimeEntityType.AddProperty( + "LockoutEnd", + typeof(DateTimeOffset?), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnd", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var normalizedEmail = runtimeEntityType.AddProperty( + "NormalizedEmail", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedEmail", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedUserName = runtimeEntityType.AddProperty( + "NormalizedUserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedUserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var passwordHash = runtimeEntityType.AddProperty( + "PasswordHash", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PasswordHash", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumber = runtimeEntityType.AddProperty( + "PhoneNumber", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumber", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumberConfirmed = runtimeEntityType.AddProperty( + "PhoneNumberConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumberConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var securityStamp = runtimeEntityType.AddProperty( + "SecurityStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("SecurityStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var twoFactorEnabled = runtimeEntityType.AddProperty( + "TwoFactorEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("TwoFactorEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var userName = runtimeEntityType.AddProperty( + "UserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("UserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedEmail }); + index.AddAnnotation("Relational:Name", "EmailIndex"); + + var index0 = runtimeEntityType.AddIndex( + new[] { normalizedUserName }, + unique: true); + index0.AddAnnotation("Relational:Name", "UserNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUsers"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaToppingEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaToppingEntityType.cs new file mode 100644 index 00000000..b97d2a24 --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaToppingEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaTopping", + typeof(PizzaTopping), + baseEntityType); + + var pizzaId = runtimeEntityType.AddProperty( + "PizzaId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("PizzaId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var toppingId = runtimeEntityType.AddProperty( + "ToppingId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("ToppingId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { pizzaId, toppingId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { toppingId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("PizzaId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var toppings = principalEntityType.AddNavigation("Toppings", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Pizza).GetProperty("Toppings", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("ToppingId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var topping = declaringEntityType.AddNavigation("Topping", + runtimeForeignKey, + onDependent: true, + typeof(Topping), + propertyInfo: typeof(PizzaTopping).GetProperty("Topping", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PizzaTopping"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/ToppingEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/ToppingEntityType.cs new file mode 100644 index 00000000..9295f9bf --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/ToppingEntityType.cs @@ -0,0 +1,62 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class ToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Topping", + typeof(Topping), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Topping).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Topping).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var price = runtimeEntityType.AddProperty( + "Price", + typeof(decimal), + propertyInfo: typeof(Topping).GetProperty("Price", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Toppings"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/NotificationsController.cs b/save-points/03-show-order-status/BlazingPizza.Server/NotificationsController.cs deleted file mode 100644 index bb3b96ff..00000000 --- a/save-points/03-show-order-status/BlazingPizza.Server/NotificationsController.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("notifications")] - [ApiController] - [Authorize] - public class NotificationsController : Controller - { - private readonly PizzaStoreContext _db; - - public NotificationsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpPut("subscribe")] - public async Task Subscribe(NotificationSubscription subscription) - { - // We're storing at most one subscription per user, so delete old ones. - // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. - var userId = GetUserId(); - var oldSubscriptions = _db.NotificationSubscriptions.Where(e => e.UserId == userId); - _db.NotificationSubscriptions.RemoveRange(oldSubscriptions); - - // Store new subscription - subscription.UserId = userId; - _db.NotificationSubscriptions.Attach(subscription); - - await _db.SaveChangesAsync(); - return subscription; - } - - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } - } -} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/OidcConfigurationController.cs b/save-points/03-show-order-status/BlazingPizza.Server/OidcConfigurationController.cs index c074debf..b7654075 100644 --- a/save-points/03-show-order-status/BlazingPizza.Server/OidcConfigurationController.cs +++ b/save-points/03-show-order-status/BlazingPizza.Server/OidcConfigurationController.cs @@ -1,26 +1,21 @@ using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class OidcConfigurationController : Controller { - public class OidcConfigurationController : Controller - { - public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) - { - ClientRequestParametersProvider = clientRequestParametersProvider; - } + public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) + { + ClientRequestParametersProvider = clientRequestParametersProvider; + } - public IClientRequestParametersProvider ClientRequestParametersProvider { get; } + public IClientRequestParametersProvider ClientRequestParametersProvider { get; } - [HttpGet("_configuration/{clientId}")] - public IActionResult GetClientRequestParameters([FromRoute]string clientId) - { - var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); - return Ok(parameters); - } - } -} + [HttpGet("_configuration/{clientId}")] + public IActionResult GetClientRequestParameters([FromRoute] string clientId) + { + var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); + return Ok(parameters); + } +} \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Server/OrdersController.cs b/save-points/03-show-order-status/BlazingPizza.Server/OrdersController.cs index 2b8bc99b..54ff6114 100644 --- a/save-points/03-show-order-status/BlazingPizza.Server/OrdersController.cs +++ b/save-points/03-show-order-status/BlazingPizza.Server/OrdersController.cs @@ -1,114 +1,109 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; +using System.Security.Claims; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +[Route("orders")] +[ApiController] +// [Authorize] +public class OrdersController : Controller { - [Route("orders")] - [ApiController] - // [Authorize] - public class OrdersController : Controller - { - private readonly PizzaStoreContext _db; - - public OrdersController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetOrders() - { - var orders = await _db.Orders - // .Where(o => o.UserId == GetUserId()) - .Include(o => o.DeliveryLocation) - .Include(o => o.Pizzas).ThenInclude(p => p.Special) - .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) - .OrderByDescending(o => o.CreatedTime) - .ToListAsync(); - - return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); - } - - [HttpGet("{orderId}")] - public async Task> GetOrderWithStatus(int orderId) - { - var order = await _db.Orders - .Where(o => o.OrderId == orderId) - // .Where(o => o.UserId == GetUserId()) - .Include(o => o.DeliveryLocation) - .Include(o => o.Pizzas).ThenInclude(p => p.Special) - .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) - .SingleOrDefaultAsync(); - - if (order == null) - { - return NotFound(); - } - - return OrderWithStatus.FromOrder(order); - } - - [HttpPost] - public async Task> PlaceOrder(Order order) - { - order.CreatedTime = DateTime.Now; - order.DeliveryLocation = new LatLong(51.5001, -0.1239); - // order.UserId = GetUserId(); - - // Enforce existence of Pizza.SpecialId and Topping.ToppingId - // in the database - prevent the submitter from making up - // new specials and toppings - foreach (var pizza in order.Pizzas) - { - pizza.SpecialId = pizza.Special.Id; - pizza.Special = null; - - foreach (var topping in pizza.Toppings) - { - topping.ToppingId = topping.Topping.Id; - topping.Topping = null; - } - } - - _db.Orders.Attach(order); - await _db.SaveChangesAsync(); - - // In the background, send push notifications if possible - var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); - if (subscription != null) - { - _ = TrackAndSendNotificationsAsync(order, subscription); - } - - return order.OrderId; - } - - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } - - private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription subscription) - { - // In a realistic case, some other backend process would track - // order delivery progress and send us notifications when it - // changes. Since we don't have any such process here, fake it. - await Task.Delay(OrderWithStatus.PreparationDuration); - await SendNotificationAsync(order, subscription, "Your order has been dispatched!"); - - await Task.Delay(OrderWithStatus.DeliveryDuration); - await SendNotificationAsync(order, subscription, "Your order is now delivered. Enjoy!"); - } - - private static Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) - { - // This will be implemented later - return Task.CompletedTask; - } - } -} + private readonly PizzaStoreContext _db; + + public OrdersController(PizzaStoreContext db) + { + _db = db; + } + + [HttpGet] + public async Task>> GetOrders() + { + var orders = await _db.Orders + // .Where(o => o.UserId == GetUserId()) + .Include(o => o.DeliveryLocation) + .Include(o => o.Pizzas).ThenInclude(p => p.Special) + .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) + .OrderByDescending(o => o.CreatedTime) + .ToListAsync(); + + return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); + } + + [HttpGet("{orderId}")] + public async Task> GetOrderWithStatus(int orderId) + { + var order = await _db.Orders + .Where(o => o.OrderId == orderId) + // .Where(o => o.UserId == GetUserId()) + .Include(o => o.DeliveryLocation) + .Include(o => o.Pizzas).ThenInclude(p => p.Special) + .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) + .SingleOrDefaultAsync(); + + if (order == null) + { + return NotFound(); + } + + return OrderWithStatus.FromOrder(order); + } + + [HttpPost] + public async Task> PlaceOrder(Order order) + { + order.CreatedTime = DateTime.Now; + order.DeliveryLocation = new LatLong(51.5001, -0.1239); + // order.UserId = GetUserId(); + + // Enforce existence of Pizza.SpecialId and Topping.ToppingId + // in the database - prevent the submitter from making up + // new specials and toppings + foreach (var pizza in order.Pizzas) + { + pizza.SpecialId = pizza.Special.Id; + pizza.Special = null; + + foreach (var topping in pizza.Toppings) + { + topping.ToppingId = topping.Topping.Id; + topping.Topping = null; + } + } + + _db.Orders.Attach(order); + await _db.SaveChangesAsync(); + + // In the background, send push notifications if possible + var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); + if (subscription != null) + { + _ = TrackAndSendNotificationsAsync(order, subscription); + } + + return order.OrderId; + } + + private string GetUserId() + { + return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); + } + + private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription subscription) + { + // In a realistic case, some other backend process would track + // order delivery progress and send us notifications when it + // changes. Since we don't have any such process here, fake it. + await Task.Delay(OrderWithStatus.PreparationDuration); + await SendNotificationAsync(order, subscription, "Your order has been dispatched!"); + + await Task.Delay(OrderWithStatus.DeliveryDuration); + await SendNotificationAsync(order, subscription, "Your order is now delivered. Enjoy!"); + } + + private static Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) + { + // This will be implemented later + return Task.CompletedTask; + } +} \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Server/PizzaApiExtensions.cs b/save-points/03-show-order-status/BlazingPizza.Server/PizzaApiExtensions.cs new file mode 100644 index 00000000..bf6b7bde --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/PizzaApiExtensions.cs @@ -0,0 +1,60 @@ +using System.Security.Claims; +using Microsoft.AspNetCore.Authorization; +using Microsoft.EntityFrameworkCore; + +namespace BlazingPizza.Server; + +public static class PizzaApiExtensions +{ + + public static WebApplication MapPizzaApi(this WebApplication app) + { + + // Subscribe to notifications + app.MapPut("/notifications/subscribe", [Authorize] async ( + HttpContext context, + PizzaStoreContext db, + NotificationSubscription subscription) => + { + + // We're storing at most one subscription per user, so delete old ones. + // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. + var userId = GetUserId(context); + var oldSubscriptions = db.NotificationSubscriptions.Where(e => e.UserId == userId); + db.NotificationSubscriptions.RemoveRange(oldSubscriptions); + + // Store new subscription + subscription.UserId = userId; + db.NotificationSubscriptions.Attach(subscription); + + await db.SaveChangesAsync(); + return Results.Ok(subscription); + + }); + + // Specials + app.MapGet("/specials", async (PizzaStoreContext db) => + { + + var specials = await db.Specials.ToListAsync(); + return Results.Ok(specials); + + }); + + // Toppings + app.MapGet("/toppings", async (PizzaStoreContext db) => + { + var toppings = await db.Toppings.OrderBy(t => t.Name).ToListAsync(); + return Results.Ok(toppings); + }); + + return app; + + } + + private static string GetUserId(HttpContext context) + { + return context.User.FindFirstValue(ClaimTypes.NameIdentifier); + } + +} \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Server/PizzaStoreContext.cs b/save-points/03-show-order-status/BlazingPizza.Server/PizzaStoreContext.cs index 9485bd12..9a2e17ee 100644 --- a/save-points/03-show-order-status/BlazingPizza.Server/PizzaStoreContext.cs +++ b/save-points/03-show-order-status/BlazingPizza.Server/PizzaStoreContext.cs @@ -3,37 +3,36 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class PizzaStoreContext : ApiAuthorizationDbContext { - public class PizzaStoreContext : ApiAuthorizationDbContext - { - public PizzaStoreContext( - DbContextOptions options, - IOptions operationalStoreOptions) : base(options, operationalStoreOptions) - { - } + public PizzaStoreContext( + DbContextOptions options, + IOptions operationalStoreOptions) : base(options, operationalStoreOptions) + { + } - public DbSet Orders { get; set; } + public DbSet Orders { get; set; } - public DbSet Pizzas { get; set; } + public DbSet Pizzas { get; set; } - public DbSet Specials { get; set; } + public DbSet Specials { get; set; } - public DbSet Toppings { get; set; } + public DbSet Toppings { get; set; } - public DbSet NotificationSubscriptions { get; set; } + public DbSet NotificationSubscriptions { get; set; } - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - base.OnModelCreating(modelBuilder); + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); - // Configuring a many-to-many special -> topping relationship that is friendly for serialization - modelBuilder.Entity().HasKey(pst => new { pst.PizzaId, pst.ToppingId }); - modelBuilder.Entity().HasOne().WithMany(ps => ps.Toppings); - modelBuilder.Entity().HasOne(pst => pst.Topping).WithMany(); + // Configuring a many-to-many special -> topping relationship that is friendly for serialization + modelBuilder.Entity().HasKey(pst => new { pst.PizzaId, pst.ToppingId }); + modelBuilder.Entity().HasOne().WithMany(ps => ps.Toppings); + modelBuilder.Entity().HasOne(pst => pst.Topping).WithMany(); - // Inline the Lat-Long pairs in Order rather than having a FK to another table - modelBuilder.Entity().OwnsOne(o => o.DeliveryLocation); - } - } -} \ No newline at end of file + // Inline the Lat-Long pairs in Order rather than having a FK to another table + modelBuilder.Entity().OwnsOne(o => o.DeliveryLocation); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/PizzaStoreUser.cs b/save-points/03-show-order-status/BlazingPizza.Server/PizzaStoreUser.cs index 171ce83d..d446a679 100644 --- a/save-points/03-show-order-status/BlazingPizza.Server/PizzaStoreUser.cs +++ b/save-points/03-show-order-status/BlazingPizza.Server/PizzaStoreUser.cs @@ -1,8 +1,6 @@ using Microsoft.AspNetCore.Identity; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; +public class PizzaStoreUser : IdentityUser { - public class PizzaStoreUser : IdentityUser - { - } } \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Server/PizzasController.cs b/save-points/03-show-order-status/BlazingPizza.Server/PizzasController.cs deleted file mode 100644 index c082552c..00000000 --- a/save-points/03-show-order-status/BlazingPizza.Server/PizzasController.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("pizzas")] - [ApiController] - public class PizzasController : Controller - { - private readonly PizzaStoreContext _db; - - public PizzasController(PizzaStoreContext db) - { - _db = db; - } - } -} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Program.cs b/save-points/03-show-order-status/BlazingPizza.Server/Program.cs index 40a47641..4484d8f7 100644 --- a/save-points/03-show-order-status/BlazingPizza.Server/Program.cs +++ b/save-points/03-show-order-status/BlazingPizza.Server/Program.cs @@ -1,33 +1,67 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; +using Microsoft.AspNetCore.Authentication; +using Microsoft.EntityFrameworkCore; +using BlazingPizza.Server; -namespace BlazingPizza.Server +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddControllersWithViews() + .AddJsonOptions(options => { + options.JsonSerializerOptions.AddContext(); + }); +builder.Services.AddRazorPages(); + +builder.Services.AddDbContext(options => + options.UseSqlite("Data Source=pizza.db") + .UseModel(BlazingPizza.Server.Models.PizzaStoreContextModel.Instance)); + +builder.Services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) + .AddEntityFrameworkStores(); + +builder.Services.AddIdentityServer() + .AddApiAuthorization(); + +builder.Services.AddAuthentication() + .AddIdentityServerJwt(); + +var app = builder.Build(); + +// Initialize the database +var scopeFactory = app.Services.GetRequiredService(); +using (var scope = scopeFactory.CreateScope()) +{ + var db = scope.ServiceProvider.GetRequiredService(); + if (db.Database.EnsureCreated()) + { + SeedData.Initialize(db); + } +} + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseWebAssemblyDebugging(); +} +else { - public class Program - { - public static void Main(string[] args) - { - var host = CreateHostBuilder(args).Build(); - - // Initialize the database - var scopeFactory = host.Services.GetRequiredService(); - using (var scope = scopeFactory.CreateScope()) - { - var db = scope.ServiceProvider.GetRequiredService(); - if (db.Database.EnsureCreated()) - { - SeedData.Initialize(db); - } - } - - host.Run(); - } - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); - } + app.UseExceptionHandler("/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); } + +app.UseHttpsRedirection(); +app.UseBlazorFrameworkFiles(); +app.UseStaticFiles(); + +app.UseRouting(); + +app.UseAuthentication(); +app.UseIdentityServer(); +app.UseAuthorization(); + +app.MapPizzaApi(); + +app.MapRazorPages(); +app.MapControllers(); +app.MapFallbackToFile("index.html"); + +app.Run(); \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Server/SeedData.cs b/save-points/03-show-order-status/BlazingPizza.Server/SeedData.cs index 7c86a5b2..a1e47973 100644 --- a/save-points/03-show-order-status/BlazingPizza.Server/SeedData.cs +++ b/save-points/03-show-order-status/BlazingPizza.Server/SeedData.cs @@ -1,193 +1,192 @@ -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public static class SeedData { - public static class SeedData - { - public static void Initialize(PizzaStoreContext db) - { - var toppings = new Topping[] - { - new Topping() - { - Name = "Extra cheese", - Price = 2.50m, - }, - new Topping() - { - Name = "American bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "British bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "Canadian bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "Tea and crumpets", - Price = 5.00m - }, - new Topping() - { - Name = "Fresh-baked scones", - Price = 4.50m, - }, - new Topping() - { - Name = "Bell peppers", - Price = 1.00m, - }, - new Topping() - { - Name = "Onions", - Price = 1.00m, - }, - new Topping() - { - Name = "Mushrooms", - Price = 1.00m, - }, - new Topping() - { - Name = "Pepperoni", - Price = 1.00m, - }, - new Topping() - { - Name = "Duck sausage", - Price = 3.20m, - }, - new Topping() - { - Name = "Venison meatballs", - Price = 2.50m, - }, - new Topping() - { - Name = "Served on a silver platter", - Price = 250.99m, - }, - new Topping() - { - Name = "Lobster on top", - Price = 64.50m, - }, - new Topping() - { - Name = "Sturgeon caviar", - Price = 101.75m, - }, - new Topping() - { - Name = "Artichoke hearts", - Price = 3.40m, - }, - new Topping() - { - Name = "Fresh tomatoes", - Price = 1.50m, - }, - new Topping() - { - Name = "Basil", - Price = 1.50m, - }, - new Topping() - { - Name = "Steak (medium-rare)", - Price = 8.50m, - }, - new Topping() - { - Name = "Blazing hot peppers", - Price = 4.20m, - }, - new Topping() - { - Name = "Buffalo chicken", - Price = 5.00m, - }, - new Topping() - { - Name = "Blue cheese", - Price = 2.50m, - }, - }; + public static void Initialize(PizzaStoreContext db) + { + var toppings = new Topping[] + { + new Topping() + { + Name = "Extra cheese", + Price = 2.50m, + }, + new Topping() + { + Name = "American bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "British bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "Canadian bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "Tea and crumpets", + Price = 5.00m + }, + new Topping() + { + Name = "Fresh-baked scones", + Price = 4.50m, + }, + new Topping() + { + Name = "Bell peppers", + Price = 1.00m, + }, + new Topping() + { + Name = "Onions", + Price = 1.00m, + }, + new Topping() + { + Name = "Mushrooms", + Price = 1.00m, + }, + new Topping() + { + Name = "Pepperoni", + Price = 1.00m, + }, + new Topping() + { + Name = "Duck sausage", + Price = 3.20m, + }, + new Topping() + { + Name = "Venison meatballs", + Price = 2.50m, + }, + new Topping() + { + Name = "Served on a silver platter", + Price = 250.99m, + }, + new Topping() + { + Name = "Lobster on top", + Price = 64.50m, + }, + new Topping() + { + Name = "Sturgeon caviar", + Price = 101.75m, + }, + new Topping() + { + Name = "Artichoke hearts", + Price = 3.40m, + }, + new Topping() + { + Name = "Fresh tomatoes", + Price = 1.50m, + }, + new Topping() + { + Name = "Basil", + Price = 1.50m, + }, + new Topping() + { + Name = "Steak (medium-rare)", + Price = 8.50m, + }, + new Topping() + { + Name = "Blazing hot peppers", + Price = 4.20m, + }, + new Topping() + { + Name = "Buffalo chicken", + Price = 5.00m, + }, + new Topping() + { + Name = "Blue cheese", + Price = 2.50m, + }, + }; - var specials = new PizzaSpecial[] - { - new PizzaSpecial() - { - Name = "Basic Cheese Pizza", - Description = "It's cheesy and delicious. Why wouldn't you want one?", - BasePrice = 9.99m, - ImageUrl = "img/pizzas/cheese.jpg", - }, - new PizzaSpecial() - { - Id = 2, - Name = "The Baconatorizor", - Description = "It has EVERY kind of bacon", - BasePrice = 11.99m, - ImageUrl = "img/pizzas/bacon.jpg", - }, - new PizzaSpecial() - { - Id = 3, - Name = "Classic pepperoni", - Description = "It's the pizza you grew up with, but Blazing hot!", - BasePrice = 10.50m, - ImageUrl = "img/pizzas/pepperoni.jpg", - }, - new PizzaSpecial() - { - Id = 4, - Name = "Buffalo chicken", - Description = "Spicy chicken, hot sauce and bleu cheese, guaranteed to warm you up", - BasePrice = 12.75m, - ImageUrl = "img/pizzas/meaty.jpg", - }, - new PizzaSpecial() - { - Id = 5, - Name = "Mushroom Lovers", - Description = "It has mushrooms. Isn't that obvious?", - BasePrice = 11.00m, - ImageUrl = "img/pizzas/mushroom.jpg", - }, - new PizzaSpecial() - { - Id = 6, - Name = "The Brit", - Description = "When in London...", - BasePrice = 10.25m, - ImageUrl = "img/pizzas/brit.jpg", - }, - new PizzaSpecial() - { - Id = 7, - Name = "Veggie Delight", - Description = "It's like salad, but on a pizza", - BasePrice = 11.50m, - ImageUrl = "img/pizzas/salad.jpg", - }, - new PizzaSpecial() - { - Id = 8, - Name = "Margherita", - Description = "Traditional Italian pizza with tomatoes and basil", - BasePrice = 9.99m, - ImageUrl = "img/pizzas/margherita.jpg", - }, - }; + var specials = new PizzaSpecial[] + { + new PizzaSpecial() + { + Name = "Basic Cheese Pizza", + Description = "It's cheesy and delicious. Why wouldn't you want one?", + BasePrice = 9.99m, + ImageUrl = "img/pizzas/cheese.jpg", + }, + new PizzaSpecial() + { + Id = 2, + Name = "The Baconatorizor", + Description = "It has EVERY kind of bacon", + BasePrice = 11.99m, + ImageUrl = "img/pizzas/bacon.jpg", + }, + new PizzaSpecial() + { + Id = 3, + Name = "Classic pepperoni", + Description = "It's the pizza you grew up with, but Blazing hot!", + BasePrice = 10.50m, + ImageUrl = "img/pizzas/pepperoni.jpg", + }, + new PizzaSpecial() + { + Id = 4, + Name = "Buffalo chicken", + Description = "Spicy chicken, hot sauce and bleu cheese, guaranteed to warm you up", + BasePrice = 12.75m, + ImageUrl = "img/pizzas/meaty.jpg", + }, + new PizzaSpecial() + { + Id = 5, + Name = "Mushroom Lovers", + Description = "It has mushrooms. Isn't that obvious?", + BasePrice = 11.00m, + ImageUrl = "img/pizzas/mushroom.jpg", + }, + new PizzaSpecial() + { + Id = 6, + Name = "The Brit", + Description = "When in London...", + BasePrice = 10.25m, + ImageUrl = "img/pizzas/brit.jpg", + }, + new PizzaSpecial() + { + Id = 7, + Name = "Veggie Delight", + Description = "It's like salad, but on a pizza", + BasePrice = 11.50m, + ImageUrl = "img/pizzas/salad.jpg", + }, + new PizzaSpecial() + { + Id = 8, + Name = "Margherita", + Description = "Traditional Italian pizza with tomatoes and basil", + BasePrice = 9.99m, + ImageUrl = "img/pizzas/margherita.jpg", + }, + }; - db.Toppings.AddRange(toppings); - db.Specials.AddRange(specials); - db.SaveChanges(); - } - } -} + db.Toppings.AddRange(toppings); + db.Specials.AddRange(specials); + db.SaveChanges(); + } +} \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Server/SpecialsController.cs b/save-points/03-show-order-status/BlazingPizza.Server/SpecialsController.cs deleted file mode 100644 index a176844c..00000000 --- a/save-points/03-show-order-status/BlazingPizza.Server/SpecialsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("specials")] - [ApiController] - public class SpecialsController : Controller - { - private readonly PizzaStoreContext _db; - - public SpecialsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetSpecials() - { - return (await _db.Specials.ToListAsync()).OrderByDescending(s => s.BasePrice).ToList(); - } - } -} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Startup.cs b/save-points/03-show-order-status/BlazingPizza.Server/Startup.cs deleted file mode 100644 index ed3fca06..00000000 --- a/save-points/03-show-order-status/BlazingPizza.Server/Startup.cs +++ /dev/null @@ -1,70 +0,0 @@ -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace BlazingPizza.Server -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - public void ConfigureServices(IServiceCollection services) - { - services.AddControllersWithViews(); - services.AddRazorPages(); - - services.AddDbContext(options => - options.UseSqlite("Data Source=pizza.db")); - - services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) - .AddEntityFrameworkStores(); - - services.AddIdentityServer() - .AddApiAuthorization(); - - services.AddAuthentication() - .AddIdentityServerJwt(); - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - app.UseWebAssemblyDebugging(); - } - else - { - app.UseExceptionHandler("/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); - } - - app.UseHttpsRedirection(); - app.UseBlazorFrameworkFiles(); - app.UseStaticFiles(); - - app.UseRouting(); - - app.UseAuthentication(); - app.UseIdentityServer(); - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - endpoints.MapRazorPages(); - endpoints.MapFallbackToFile("index.html"); - }); - } - } -} \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Server/ToppingsController.cs b/save-points/03-show-order-status/BlazingPizza.Server/ToppingsController.cs deleted file mode 100644 index 6a677639..00000000 --- a/save-points/03-show-order-status/BlazingPizza.Server/ToppingsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("toppings")] - [ApiController] - public class ToppingsController : Controller - { - private readonly PizzaStoreContext _db; - - public ToppingsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetToppings() - { - return await _db.Toppings.OrderBy(t => t.Name).ToListAsync(); - } - } -} diff --git a/save-points/03-show-order-status/BlazingPizza.Shared/Address.cs b/save-points/03-show-order-status/BlazingPizza.Shared/Address.cs index e5c0ef0d..63f1e167 100644 --- a/save-points/03-show-order-status/BlazingPizza.Shared/Address.cs +++ b/save-points/03-show-order-status/BlazingPizza.Shared/Address.cs @@ -1,21 +1,26 @@ using System.ComponentModel.DataAnnotations; -namespace BlazingPizza +namespace BlazingPizza; + +public class Address { - public class Address - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + [Required, MaxLength(100)] + public string Name { get; set; } - public string Line1 { get; set; } + [Required, MaxLength(100)] + public string Line1 { get; set; } - public string Line2 { get; set; } + [MaxLength(100)] + public string Line2 { get; set; } - public string City { get; set; } + [Required, MaxLength(50)] + public string City { get; set; } - public string Region { get; set; } + [Required, MaxLength(20)] + public string Region { get; set; } - public string PostalCode { get; set; } - } + [Required, MaxLength(20)] + public string PostalCode { get; set; } } diff --git a/save-points/03-show-order-status/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/save-points/03-show-order-status/BlazingPizza.Shared/BlazingPizza.Shared.csproj index f7b7dd02..075ddd60 100644 --- a/save-points/03-show-order-status/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/save-points/03-show-order-status/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -3,6 +3,7 @@ $(TargetFrameworkVersion) BlazingPizza + true diff --git a/save-points/03-show-order-status/BlazingPizza.Shared/LatLong.cs b/save-points/03-show-order-status/BlazingPizza.Shared/LatLong.cs index 9b8c3811..14a94c26 100644 --- a/save-points/03-show-order-status/BlazingPizza.Shared/LatLong.cs +++ b/save-points/03-show-order-status/BlazingPizza.Shared/LatLong.cs @@ -1,27 +1,26 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class LatLong { - public class LatLong - { - public LatLong() - { - } + public LatLong() + { + } - public LatLong(double latitude, double longitude) : this() - { - Latitude = latitude; - Longitude = longitude; - } + public LatLong(double latitude, double longitude) : this() + { + Latitude = latitude; + Longitude = longitude; + } - public double Latitude { get; set; } + public double Latitude { get; set; } - public double Longitude { get; set; } + public double Longitude { get; set; } - public static LatLong Interpolate(LatLong start, LatLong end, double proportion) - { - // The Earth is flat, right? So no need for spherical interpolation. - return new LatLong( - start.Latitude + (end.Latitude - start.Latitude) * proportion, - start.Longitude + (end.Longitude - start.Longitude) * proportion); - } - } -} + public static LatLong Interpolate(LatLong start, LatLong end, double proportion) + { + // The Earth is flat, right? So no need for spherical interpolation. + return new LatLong( + start.Latitude + (end.Latitude - start.Latitude) * proportion, + start.Longitude + (end.Longitude - start.Longitude) * proportion); + } +} \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Shared/NotificationSubscription.cs b/save-points/03-show-order-status/BlazingPizza.Shared/NotificationSubscription.cs index 04259c2f..9109ff57 100644 --- a/save-points/03-show-order-status/BlazingPizza.Shared/NotificationSubscription.cs +++ b/save-points/03-show-order-status/BlazingPizza.Shared/NotificationSubscription.cs @@ -1,17 +1,14 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class NotificationSubscription { - public class NotificationSubscription - { - public int NotificationSubscriptionId { get; set; } + public int NotificationSubscriptionId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public string Url { get; set; } + public string Url { get; set; } - public string P256dh { get; set; } + public string P256dh { get; set; } - public string Auth { get; set; } - } + public string Auth { get; set; } } diff --git a/save-points/03-show-order-status/BlazingPizza.Shared/Order.cs b/save-points/03-show-order-status/BlazingPizza.Shared/Order.cs index fb003bd6..aca04ca1 100644 --- a/save-points/03-show-order-status/BlazingPizza.Shared/Order.cs +++ b/save-points/03-show-order-status/BlazingPizza.Shared/Order.cs @@ -1,25 +1,32 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +public class Order { - public class Order - { - public int OrderId { get; set; } + public int OrderId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public DateTime CreatedTime { get; set; } + public DateTime CreatedTime { get; set; } - public Address DeliveryAddress { get; set; } = new Address(); + public Address DeliveryAddress { get; set; } = new Address(); - public LatLong DeliveryLocation { get; set; } + public LatLong DeliveryLocation { get; set; } - public List Pizzas { get; set; } = new List(); + public List Pizzas { get; set; } = new List(); - public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); + public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); - public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); - } + public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Default, PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] +[JsonSerializable(typeof(Order))] +[JsonSerializable(typeof(OrderWithStatus))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Pizza))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Topping))] +public partial class OrderContext : JsonSerializerContext {} \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Shared/OrderWithStatus.cs b/save-points/03-show-order-status/BlazingPizza.Shared/OrderWithStatus.cs index 021de78c..f5f153b6 100644 --- a/save-points/03-show-order-status/BlazingPizza.Shared/OrderWithStatus.cs +++ b/save-points/03-show-order-status/BlazingPizza.Shared/OrderWithStatus.cs @@ -1,79 +1,78 @@ -using BlazingPizza.ComponentsLibrary.Map; -using System; -using System.Collections.Generic; +using System.Text.Json.Serialization; +using BlazingPizza.ComponentsLibrary.Map; -namespace BlazingPizza + +namespace BlazingPizza; + +public class OrderWithStatus { - public class OrderWithStatus - { - public readonly static TimeSpan PreparationDuration = TimeSpan.FromSeconds(10); - public readonly static TimeSpan DeliveryDuration = TimeSpan.FromMinutes(1); // Unrealistic, but more interesting to watch + public readonly static TimeSpan PreparationDuration = TimeSpan.FromSeconds(10); + public readonly static TimeSpan DeliveryDuration = TimeSpan.FromMinutes(1); // Unrealistic, but more interesting to watch - public Order Order { get; set; } + public Order Order { get; set; } - public string StatusText { get; set; } + public string StatusText { get; set; } - public bool IsDelivered => StatusText == "Delivered"; + public bool IsDelivered => StatusText == "Delivered"; - public List MapMarkers { get; set; } + public List MapMarkers { get; set; } - public static OrderWithStatus FromOrder(Order order) - { - // To simulate a real backend process, we fake status updates based on the amount - // of time since the order was placed - string statusText; - List mapMarkers; - var dispatchTime = order.CreatedTime.Add(PreparationDuration); + public static OrderWithStatus FromOrder(Order order) + { + // To simulate a real backend process, we fake status updates based on the amount + // of time since the order was placed + string statusText; + List mapMarkers; + var dispatchTime = order.CreatedTime.Add(PreparationDuration); - if (DateTime.Now < dispatchTime) - { - statusText = "Preparing"; - mapMarkers = new List - { - ToMapMarker("You", order.DeliveryLocation, showPopup: true) - }; - } - else if (DateTime.Now < dispatchTime + DeliveryDuration) - { - statusText = "Out for delivery"; + if (DateTime.Now < dispatchTime) + { + statusText = "Preparing"; + mapMarkers = new List + { + ToMapMarker("You", order.DeliveryLocation, showPopup: true) + }; + } + else if (DateTime.Now < dispatchTime + DeliveryDuration) + { + statusText = "Out for delivery"; - var startPosition = ComputeStartPosition(order); - var proportionOfDeliveryCompleted = Math.Min(1, (DateTime.Now - dispatchTime).TotalMilliseconds / DeliveryDuration.TotalMilliseconds); - var driverPosition = LatLong.Interpolate(startPosition, order.DeliveryLocation, proportionOfDeliveryCompleted); - mapMarkers = new List - { - ToMapMarker("You", order.DeliveryLocation), - ToMapMarker("Driver", driverPosition, showPopup: true), - }; - } - else - { - statusText = "Delivered"; - mapMarkers = new List - { - ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), - }; - } + var startPosition = ComputeStartPosition(order); + var proportionOfDeliveryCompleted = Math.Min(1, (DateTime.Now - dispatchTime).TotalMilliseconds / DeliveryDuration.TotalMilliseconds); + var driverPosition = LatLong.Interpolate(startPosition, order.DeliveryLocation, proportionOfDeliveryCompleted); + mapMarkers = new List + { + ToMapMarker("You", order.DeliveryLocation), + ToMapMarker("Driver", driverPosition, showPopup: true), + }; + } + else + { + statusText = "Delivered"; + mapMarkers = new List + { + ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), + }; + } - return new OrderWithStatus - { - Order = order, - StatusText = statusText, - MapMarkers = mapMarkers, - }; - } + return new OrderWithStatus + { + Order = order, + StatusText = statusText, + MapMarkers = mapMarkers, + }; + } - private static LatLong ComputeStartPosition(Order order) - { - // Random but deterministic based on order ID - var rng = new Random(order.OrderId); - var distance = 0.01 + rng.NextDouble() * 0.02; - var angle = rng.NextDouble() * Math.PI * 2; - var offset = (distance * Math.Cos(angle), distance * Math.Sin(angle)); - return new LatLong(order.DeliveryLocation.Latitude + offset.Item1, order.DeliveryLocation.Longitude + offset.Item2); - } + private static LatLong ComputeStartPosition(Order order) + { + // Random but deterministic based on order ID + var rng = new Random(order.OrderId); + var distance = 0.01 + rng.NextDouble() * 0.02; + var angle = rng.NextDouble() * Math.PI * 2; + var offset = (distance * Math.Cos(angle), distance * Math.Sin(angle)); + return new LatLong(order.DeliveryLocation.Latitude + offset.Item1, order.DeliveryLocation.Longitude + offset.Item2); + } - static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) - => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; - } -} + static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) + => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; +} \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Shared/Pizza.cs b/save-points/03-show-order-status/BlazingPizza.Shared/Pizza.cs index ec1108a9..459298f4 100644 --- a/save-points/03-show-order-status/BlazingPizza.Shared/Pizza.cs +++ b/save-points/03-show-order-status/BlazingPizza.Shared/Pizza.cs @@ -1,42 +1,44 @@ -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// /// Represents a customized pizza as part of an order +/// +public class Pizza { - /// - /// Represents a customized pizza as part of an order - /// - public class Pizza - { - public const int DefaultSize = 12; - public const int MinimumSize = 9; - public const int MaximumSize = 17; + public const int DefaultSize = 12; + public const int MinimumSize = 9; + public const int MaximumSize = 17; - public int Id { get; set; } + public int Id { get; set; } - public int OrderId { get; set; } + public int OrderId { get; set; } - public PizzaSpecial Special { get; set; } + public PizzaSpecial Special { get; set; } - public int SpecialId { get; set; } + public int SpecialId { get; set; } - public int Size { get; set; } + public int Size { get; set; } - public List Toppings { get; set; } + public List Toppings { get; set; } - public decimal GetBasePrice() - { - return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; - } + public decimal GetBasePrice() + { + return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; + } - public decimal GetTotalPrice() - { - return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); - } + public decimal GetTotalPrice() + { + return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); + } - public string GetFormattedTotalPrice() - { - return GetTotalPrice().ToString("0.00"); - } - } + public string GetFormattedTotalPrice() + { + return GetTotalPrice().ToString("0.00"); + } } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Serialization)] +[JsonSerializable(typeof(Pizza))] +public partial class PizzaContext : JsonSerializerContext {} \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Shared/PizzaSpecial.cs b/save-points/03-show-order-status/BlazingPizza.Shared/PizzaSpecial.cs index 2f2b3383..9653300c 100644 --- a/save-points/03-show-order-status/BlazingPizza.Shared/PizzaSpecial.cs +++ b/save-points/03-show-order-status/BlazingPizza.Shared/PizzaSpecial.cs @@ -1,20 +1,19 @@ -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// Represents a pre-configured template for a pizza a user can order +/// +public class PizzaSpecial { - /// - /// Represents a pre-configured template for a pizza a user can order - /// - public class PizzaSpecial - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal BasePrice { get; set; } + public decimal BasePrice { get; set; } - public string Description { get; set; } + public string Description { get; set; } - public string ImageUrl { get; set; } + public string ImageUrl { get; set; } - public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); - } -} + public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); +} \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Shared/PizzaTopping.cs b/save-points/03-show-order-status/BlazingPizza.Shared/PizzaTopping.cs index f5a6c1ac..0a711647 100644 --- a/save-points/03-show-order-status/BlazingPizza.Shared/PizzaTopping.cs +++ b/save-points/03-show-order-status/BlazingPizza.Shared/PizzaTopping.cs @@ -1,11 +1,11 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class PizzaTopping { - public class PizzaTopping - { - public Topping Topping { get; set; } + public Topping Topping { get; set; } + + public int ToppingId { get; set; } - public int ToppingId { get; set; } - - public int PizzaId { get; set; } - } -} + public int PizzaId { get; set; } + +} \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Shared/Topping.cs b/save-points/03-show-order-status/BlazingPizza.Shared/Topping.cs index 61bdeb92..376c311a 100644 --- a/save-points/03-show-order-status/BlazingPizza.Shared/Topping.cs +++ b/save-points/03-show-order-status/BlazingPizza.Shared/Topping.cs @@ -1,13 +1,13 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class Topping { - public class Topping - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal Price { get; set; } + public decimal Price { get; set; } - public string GetFormattedPrice() => Price.ToString("0.00"); - } -} + public string GetFormattedPrice() => Price.ToString("0.00"); + +} \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Shared/UserInfo.cs b/save-points/03-show-order-status/BlazingPizza.Shared/UserInfo.cs index 4996ef80..362f8f8e 100644 --- a/save-points/03-show-order-status/BlazingPizza.Shared/UserInfo.cs +++ b/save-points/03-show-order-status/BlazingPizza.Shared/UserInfo.cs @@ -1,9 +1,9 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class UserInfo { - public class UserInfo - { - public bool IsAuthenticated { get; set; } + public bool IsAuthenticated { get; set; } - public string Name { get; set; } - } -} + public string Name { get; set; } + +} \ No newline at end of file diff --git a/save-points/04-refactor-state-management/BlazingPizza.Client/BlazingPizza.Client.csproj b/save-points/04-refactor-state-management/BlazingPizza.Client/BlazingPizza.Client.csproj index 663677a1..f9ebe283 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/save-points/04-refactor-state-management/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -2,6 +2,7 @@ $(TargetFrameworkVersion) + true diff --git a/save-points/04-refactor-state-management/BlazingPizza.Client/OrderState.cs b/save-points/04-refactor-state-management/BlazingPizza.Client/OrderState.cs index f44ac786..064f65a7 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Client/OrderState.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Client/OrderState.cs @@ -1,50 +1,47 @@ -using System.Collections.Generic; +namespace BlazingPizza.Client; -namespace BlazingPizza.Client +public class OrderState { - public class OrderState - { - public bool ShowingConfigureDialog { get; private set; } - - public Pizza ConfiguringPizza { get; private set; } - - public Order Order { get; private set; } = new Order(); - - public void ShowConfigurePizzaDialog(PizzaSpecial special) - { - ConfiguringPizza = new Pizza() - { - Special = special, - SpecialId = special.Id, - Size = Pizza.DefaultSize, - Toppings = new List(), - }; - - ShowingConfigureDialog = true; - } - - public void CancelConfigurePizzaDialog() - { - ConfiguringPizza = null; - ShowingConfigureDialog = false; - } - - public void ConfirmConfigurePizzaDialog() - { - Order.Pizzas.Add(ConfiguringPizza); - ConfiguringPizza = null; - - ShowingConfigureDialog = false; - } - - public void RemoveConfiguredPizza(Pizza pizza) - { - Order.Pizzas.Remove(pizza); - } - - public void ResetOrder() - { - Order = new Order(); - } - } + public bool ShowingConfigureDialog { get; private set; } + + public Pizza ConfiguringPizza { get; private set; } + + public Order Order { get; private set; } = new Order(); + + public void ShowConfigurePizzaDialog(PizzaSpecial special) + { + ConfiguringPizza = new Pizza() + { + Special = special, + SpecialId = special.Id, + Size = Pizza.DefaultSize, + Toppings = new List(), + }; + + ShowingConfigureDialog = true; + } + + public void CancelConfigurePizzaDialog() + { + ConfiguringPizza = null; + ShowingConfigureDialog = false; + } + + public void ConfirmConfigurePizzaDialog() + { + Order.Pizzas.Add(ConfiguringPizza); + ConfiguringPizza = null; + + ShowingConfigureDialog = false; + } + + public void RemoveConfiguredPizza(Pizza pizza) + { + Order.Pizzas.Remove(pizza); + } + + public void ResetOrder() + { + Order = new Order(); + } } diff --git a/save-points/04-refactor-state-management/BlazingPizza.Client/Program.cs b/save-points/04-refactor-state-management/BlazingPizza.Client/Program.cs index e0c88943..3363acbb 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Client/Program.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Client/Program.cs @@ -1,22 +1,10 @@ -using Microsoft.AspNetCore.Components.WebAssembly.Hosting; -using Microsoft.Extensions.DependencyInjection; -using System; -using System.Net.Http; -using System.Threading.Tasks; +using BlazingPizza.Client; +using Microsoft.AspNetCore.Components.WebAssembly.Hosting; -namespace BlazingPizza.Client -{ - public class Program - { - public static async Task Main(string[] args) - { - var builder = WebAssemblyHostBuilder.CreateDefault(args); - builder.RootComponents.Add("#app"); +var builder = WebAssemblyHostBuilder.CreateDefault(args); +builder.RootComponents.Add("#app"); - builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); - builder.Services.AddScoped(); +builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); +builder.Services.AddScoped(); - await builder.Build().RunAsync(); - } - } -} +await builder.Build().RunAsync(); diff --git a/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 61ebf623..cb996b1b 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -2,6 +2,7 @@ $(TargetFrameworkVersion) + true diff --git a/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/LocalStorage.cs b/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/LocalStorage.cs index f36b098e..bb84f13c 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/LocalStorage.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/LocalStorage.cs @@ -1,17 +1,15 @@ using Microsoft.JSInterop; -using System.Threading.Tasks; -namespace BlazingPizza.ComponentsLibrary +namespace BlazingPizza.ComponentsLibrary; + +public static class LocalStorage { - public static class LocalStorage - { - public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) - => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); + public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) + => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); - public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object value) - => jsRuntime.InvokeVoidAsync("blazorLocalStorage.set", key, value); + public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object value) + => jsRuntime.InvokeVoidAsync("blazorLocalStorage.set", key, value); - public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key) - => jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key); - } -} + public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key) + => jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key); +} \ No newline at end of file diff --git a/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/Map/Marker.cs b/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/Map/Marker.cs index 63006067..a8e78f2a 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/Map/Marker.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/Map/Marker.cs @@ -1,13 +1,12 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Marker { - public class Marker - { - public string Description { get; set; } + public string Description { get; set; } - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } + public double Y { get; set; } - public bool ShowPopup { get; set; } - } + public bool ShowPopup { get; set; } } diff --git a/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/Map/Point.cs b/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/Map/Point.cs index 03841826..349046d4 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/Map/Point.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/Map/Point.cs @@ -1,9 +1,8 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Point { - public class Point - { - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } - } -} + public double Y { get; set; } +} \ No newline at end of file diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/BlazingPizza.Server.csproj b/save-points/04-refactor-state-management/BlazingPizza.Server/BlazingPizza.Server.csproj index b9c74fc4..ddfe5f60 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -2,6 +2,7 @@ $(TargetFrameworkVersion) + enable @@ -13,6 +14,7 @@ + diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/AddressEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/AddressEntityType.cs new file mode 100644 index 00000000..82db81b6 --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/AddressEntityType.cs @@ -0,0 +1,92 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class AddressEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Address", + typeof(Address), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Address).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var city = runtimeEntityType.AddProperty( + "City", + typeof(string), + propertyInfo: typeof(Address).GetProperty("City", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var line1 = runtimeEntityType.AddProperty( + "Line1", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line1", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var line2 = runtimeEntityType.AddProperty( + "Line2", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line2", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var postalCode = runtimeEntityType.AddProperty( + "PostalCode", + typeof(string), + propertyInfo: typeof(Address).GetProperty("PostalCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var region = runtimeEntityType.AddProperty( + "Region", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Region", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Address"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs new file mode 100644 index 00000000..1dd4563b --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs @@ -0,0 +1,114 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class DeviceFlowCodesEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.DeviceFlowCodes", + typeof(DeviceFlowCodes), + baseEntityType); + + var userCode = runtimeEntityType.AddProperty( + "UserCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("UserCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var deviceCode = runtimeEntityType.AddProperty( + "DeviceCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("DeviceCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var key = runtimeEntityType.AddKey( + new[] { userCode }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deviceCode }, + unique: true); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "DeviceCodes"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs new file mode 100644 index 00000000..8946b261 --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRoleClaim", + typeof(IdentityRoleClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoleClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityRoleEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityRoleEntityType.cs new file mode 100644 index 00000000..2f1fec2b --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityRoleEntityType.cs @@ -0,0 +1,78 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRole", + typeof(IdentityRole), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedName = runtimeEntityType.AddProperty( + "NormalizedName", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("NormalizedName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedName }, + unique: true); + index.AddAnnotation("Relational:Name", "RoleNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs new file mode 100644 index 00000000..55418a1e --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserClaim", + typeof(IdentityUserClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityUserClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs new file mode 100644 index 00000000..3ca029bd --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserLoginstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserLogin", + typeof(IdentityUserLogin), + baseEntityType); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerKey = runtimeEntityType.AddProperty( + "ProviderKey", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderKey", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerDisplayName = runtimeEntityType.AddProperty( + "ProviderDisplayName", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderDisplayName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { loginProvider, providerKey }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserLogins"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs new file mode 100644 index 00000000..70078d7a --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs @@ -0,0 +1,82 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserRolestringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserRole", + typeof(IdentityUserRole), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { userId, roleId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs new file mode 100644 index 00000000..93ba6d31 --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs @@ -0,0 +1,84 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserTokenstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserToken", + typeof(IdentityUserToken), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var value = runtimeEntityType.AddProperty( + "Value", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Value", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { userId, loginProvider, name }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserTokens"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/KeyEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/KeyEntityType.cs new file mode 100644 index 00000000..f6c6b4c7 --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/KeyEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class KeyEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.Key", + typeof(Key), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var algorithm = runtimeEntityType.AddProperty( + "Algorithm", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Algorithm", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var created = runtimeEntityType.AddProperty( + "Created", + typeof(DateTime), + propertyInfo: typeof(Key).GetProperty("Created", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var dataProtected = runtimeEntityType.AddProperty( + "DataProtected", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("DataProtected", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var isX509Certificate = runtimeEntityType.AddProperty( + "IsX509Certificate", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("IsX509Certificate", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var use = runtimeEntityType.AddProperty( + "Use", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Use", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var version = runtimeEntityType.AddProperty( + "Version", + typeof(int), + propertyInfo: typeof(Key).GetProperty("Version", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { use }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Keys"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/LatLongEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/LatLongEntityType.cs new file mode 100644 index 00000000..3fd254bd --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/LatLongEntityType.cs @@ -0,0 +1,80 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class LatLongEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.LatLong", + typeof(LatLong), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var latitude = runtimeEntityType.AddProperty( + "Latitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Latitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var longitude = runtimeEntityType.AddProperty( + "Longitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Longitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + unique: true, + required: true, + ownership: true); + + var deliveryLocation = principalEntityType.AddNavigation("DeliveryLocation", + runtimeForeignKey, + onDependent: false, + typeof(LatLong), + propertyInfo: typeof(Order).GetProperty("DeliveryLocation", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + eagerLoaded: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs new file mode 100644 index 00000000..db236e4c --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs @@ -0,0 +1,77 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class NotificationSubscriptionEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.NotificationSubscription", + typeof(NotificationSubscription), + baseEntityType); + + var notificationSubscriptionId = runtimeEntityType.AddProperty( + "NotificationSubscriptionId", + typeof(int), + propertyInfo: typeof(NotificationSubscription).GetProperty("NotificationSubscriptionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var auth = runtimeEntityType.AddProperty( + "Auth", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Auth", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var p256dh = runtimeEntityType.AddProperty( + "P256dh", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("P256dh", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var url = runtimeEntityType.AddProperty( + "Url", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Url", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { notificationSubscriptionId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "NotificationSubscriptions"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/OrderEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/OrderEntityType.cs new file mode 100644 index 00000000..9d9ec6fd --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/OrderEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class OrderEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Order", + typeof(Order), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Order).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var createdTime = runtimeEntityType.AddProperty( + "CreatedTime", + typeof(DateTime), + propertyInfo: typeof(Order).GetProperty("CreatedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var deliveryAddressId = runtimeEntityType.AddProperty( + "DeliveryAddressId", + typeof(int?), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(Order).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deliveryAddressId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("DeliveryAddressId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType); + + var deliveryAddress = declaringEntityType.AddNavigation("DeliveryAddress", + runtimeForeignKey, + onDependent: true, + typeof(Address), + propertyInfo: typeof(Order).GetProperty("DeliveryAddress", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PersistedGrantEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PersistedGrantEntityType.cs new file mode 100644 index 00000000..842d53a5 --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PersistedGrantEntityType.cs @@ -0,0 +1,127 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PersistedGrantEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.PersistedGrant", + typeof(PersistedGrant), + baseEntityType); + + var key = runtimeEntityType.AddProperty( + "Key", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Key", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var consumedTime = runtimeEntityType.AddProperty( + "ConsumedTime", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("ConsumedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(PersistedGrant).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var type = runtimeEntityType.AddProperty( + "Type", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Type", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var key0 = runtimeEntityType.AddKey( + new[] { key }); + runtimeEntityType.SetPrimaryKey(key0); + + var index = runtimeEntityType.AddIndex( + new[] { consumedTime }); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + var index1 = runtimeEntityType.AddIndex( + new[] { subjectId, clientId, type }); + + var index2 = runtimeEntityType.AddIndex( + new[] { subjectId, sessionId, type }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PersistedGrants"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaEntityType.cs new file mode 100644 index 00000000..3a124e63 --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaEntityType.cs @@ -0,0 +1,111 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Pizza", + typeof(Pizza), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var size = runtimeEntityType.AddProperty( + "Size", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Size", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var specialId = runtimeEntityType.AddProperty( + "SpecialId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("SpecialId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { orderId }); + + var index0 = runtimeEntityType.AddIndex( + new[] { specialId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var pizzas = principalEntityType.AddNavigation("Pizzas", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Order).GetProperty("Pizzas", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("SpecialId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var special = declaringEntityType.AddNavigation("Special", + runtimeForeignKey, + onDependent: true, + typeof(PizzaSpecial), + propertyInfo: typeof(Pizza).GetProperty("Special", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Pizzas"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs new file mode 100644 index 00000000..e86b0f50 --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs @@ -0,0 +1,76 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaSpecialEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaSpecial", + typeof(PizzaSpecial), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(PizzaSpecial).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var basePrice = runtimeEntityType.AddProperty( + "BasePrice", + typeof(decimal), + propertyInfo: typeof(PizzaSpecial).GetProperty("BasePrice", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var imageUrl = runtimeEntityType.AddProperty( + "ImageUrl", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("ImageUrl", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Specials"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaStoreContextModel.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaStoreContextModel.cs new file mode 100644 index 00000000..8b516a68 --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaStoreContextModel.cs @@ -0,0 +1,28 @@ +// +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + [DbContext(typeof(PizzaStoreContext))] + public partial class PizzaStoreContextModel : RuntimeModel + { + static PizzaStoreContextModel() + { + var model = new PizzaStoreContextModel(); + model.Initialize(); + model.Customize(); + _instance = model; + } + + private static PizzaStoreContextModel _instance; + public static IModel Instance => _instance; + + partial void Initialize(); + + partial void Customize(); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs new file mode 100644 index 00000000..d46f50f4 --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs @@ -0,0 +1,69 @@ +// +using System; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + public partial class PizzaStoreContextModel + { + partial void Initialize() + { + var address = AddressEntityType.Create(this); + var latLong = LatLongEntityType.Create(this); + var notificationSubscription = NotificationSubscriptionEntityType.Create(this); + var order = OrderEntityType.Create(this); + var pizza = PizzaEntityType.Create(this); + var pizzaSpecial = PizzaSpecialEntityType.Create(this); + var pizzaTopping = PizzaToppingEntityType.Create(this); + var pizzaStoreUser = PizzaStoreUserEntityType.Create(this); + var topping = ToppingEntityType.Create(this); + var deviceFlowCodes = DeviceFlowCodesEntityType.Create(this); + var key = KeyEntityType.Create(this); + var persistedGrant = PersistedGrantEntityType.Create(this); + var identityRole = IdentityRoleEntityType.Create(this); + var identityRoleClaimstring = IdentityRoleClaimstringEntityType.Create(this); + var identityUserClaimstring = IdentityUserClaimstringEntityType.Create(this); + var identityUserLoginstring = IdentityUserLoginstringEntityType.Create(this); + var identityUserRolestring = IdentityUserRolestringEntityType.Create(this); + var identityUserTokenstring = IdentityUserTokenstringEntityType.Create(this); + + LatLongEntityType.CreateForeignKey1(latLong, order); + OrderEntityType.CreateForeignKey1(order, address); + PizzaEntityType.CreateForeignKey1(pizza, order); + PizzaEntityType.CreateForeignKey2(pizza, pizzaSpecial); + PizzaToppingEntityType.CreateForeignKey1(pizzaTopping, pizza); + PizzaToppingEntityType.CreateForeignKey2(pizzaTopping, topping); + IdentityRoleClaimstringEntityType.CreateForeignKey1(identityRoleClaimstring, identityRole); + IdentityUserClaimstringEntityType.CreateForeignKey1(identityUserClaimstring, pizzaStoreUser); + IdentityUserLoginstringEntityType.CreateForeignKey1(identityUserLoginstring, pizzaStoreUser); + IdentityUserRolestringEntityType.CreateForeignKey1(identityUserRolestring, identityRole); + IdentityUserRolestringEntityType.CreateForeignKey2(identityUserRolestring, pizzaStoreUser); + IdentityUserTokenstringEntityType.CreateForeignKey1(identityUserTokenstring, pizzaStoreUser); + + AddressEntityType.CreateAnnotations(address); + LatLongEntityType.CreateAnnotations(latLong); + NotificationSubscriptionEntityType.CreateAnnotations(notificationSubscription); + OrderEntityType.CreateAnnotations(order); + PizzaEntityType.CreateAnnotations(pizza); + PizzaSpecialEntityType.CreateAnnotations(pizzaSpecial); + PizzaToppingEntityType.CreateAnnotations(pizzaTopping); + PizzaStoreUserEntityType.CreateAnnotations(pizzaStoreUser); + ToppingEntityType.CreateAnnotations(topping); + DeviceFlowCodesEntityType.CreateAnnotations(deviceFlowCodes); + KeyEntityType.CreateAnnotations(key); + PersistedGrantEntityType.CreateAnnotations(persistedGrant); + IdentityRoleEntityType.CreateAnnotations(identityRole); + IdentityRoleClaimstringEntityType.CreateAnnotations(identityRoleClaimstring); + IdentityUserClaimstringEntityType.CreateAnnotations(identityUserClaimstring); + IdentityUserLoginstringEntityType.CreateAnnotations(identityUserLoginstring); + IdentityUserRolestringEntityType.CreateAnnotations(identityUserRolestring); + IdentityUserTokenstringEntityType.CreateAnnotations(identityUserTokenstring); + + AddAnnotation("ProductVersion", "6.0.0"); + } + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs new file mode 100644 index 00000000..18b2d96d --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs @@ -0,0 +1,156 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaStoreUserEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Server.PizzaStoreUser", + typeof(PizzaStoreUser), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var accessFailedCount = runtimeEntityType.AddProperty( + "AccessFailedCount", + typeof(int), + propertyInfo: typeof(IdentityUser).GetProperty("AccessFailedCount", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var email = runtimeEntityType.AddProperty( + "Email", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Email", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var emailConfirmed = runtimeEntityType.AddProperty( + "EmailConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("EmailConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnabled = runtimeEntityType.AddProperty( + "LockoutEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnd = runtimeEntityType.AddProperty( + "LockoutEnd", + typeof(DateTimeOffset?), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnd", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var normalizedEmail = runtimeEntityType.AddProperty( + "NormalizedEmail", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedEmail", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedUserName = runtimeEntityType.AddProperty( + "NormalizedUserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedUserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var passwordHash = runtimeEntityType.AddProperty( + "PasswordHash", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PasswordHash", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumber = runtimeEntityType.AddProperty( + "PhoneNumber", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumber", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumberConfirmed = runtimeEntityType.AddProperty( + "PhoneNumberConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumberConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var securityStamp = runtimeEntityType.AddProperty( + "SecurityStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("SecurityStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var twoFactorEnabled = runtimeEntityType.AddProperty( + "TwoFactorEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("TwoFactorEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var userName = runtimeEntityType.AddProperty( + "UserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("UserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedEmail }); + index.AddAnnotation("Relational:Name", "EmailIndex"); + + var index0 = runtimeEntityType.AddIndex( + new[] { normalizedUserName }, + unique: true); + index0.AddAnnotation("Relational:Name", "UserNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUsers"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaToppingEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaToppingEntityType.cs new file mode 100644 index 00000000..b97d2a24 --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaToppingEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaTopping", + typeof(PizzaTopping), + baseEntityType); + + var pizzaId = runtimeEntityType.AddProperty( + "PizzaId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("PizzaId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var toppingId = runtimeEntityType.AddProperty( + "ToppingId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("ToppingId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { pizzaId, toppingId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { toppingId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("PizzaId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var toppings = principalEntityType.AddNavigation("Toppings", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Pizza).GetProperty("Toppings", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("ToppingId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var topping = declaringEntityType.AddNavigation("Topping", + runtimeForeignKey, + onDependent: true, + typeof(Topping), + propertyInfo: typeof(PizzaTopping).GetProperty("Topping", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PizzaTopping"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/ToppingEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/ToppingEntityType.cs new file mode 100644 index 00000000..9295f9bf --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/ToppingEntityType.cs @@ -0,0 +1,62 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class ToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Topping", + typeof(Topping), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Topping).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Topping).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var price = runtimeEntityType.AddProperty( + "Price", + typeof(decimal), + propertyInfo: typeof(Topping).GetProperty("Price", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Toppings"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/NotificationsController.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/NotificationsController.cs deleted file mode 100644 index bb3b96ff..00000000 --- a/save-points/04-refactor-state-management/BlazingPizza.Server/NotificationsController.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("notifications")] - [ApiController] - [Authorize] - public class NotificationsController : Controller - { - private readonly PizzaStoreContext _db; - - public NotificationsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpPut("subscribe")] - public async Task Subscribe(NotificationSubscription subscription) - { - // We're storing at most one subscription per user, so delete old ones. - // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. - var userId = GetUserId(); - var oldSubscriptions = _db.NotificationSubscriptions.Where(e => e.UserId == userId); - _db.NotificationSubscriptions.RemoveRange(oldSubscriptions); - - // Store new subscription - subscription.UserId = userId; - _db.NotificationSubscriptions.Attach(subscription); - - await _db.SaveChangesAsync(); - return subscription; - } - - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } - } -} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/OidcConfigurationController.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/OidcConfigurationController.cs index c074debf..dc75ecb3 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Server/OidcConfigurationController.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/OidcConfigurationController.cs @@ -1,26 +1,21 @@ using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class OidcConfigurationController : Controller { - public class OidcConfigurationController : Controller - { - public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) - { - ClientRequestParametersProvider = clientRequestParametersProvider; - } + public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) + { + ClientRequestParametersProvider = clientRequestParametersProvider; + } - public IClientRequestParametersProvider ClientRequestParametersProvider { get; } + public IClientRequestParametersProvider ClientRequestParametersProvider { get; } - [HttpGet("_configuration/{clientId}")] - public IActionResult GetClientRequestParameters([FromRoute]string clientId) - { - var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); - return Ok(parameters); - } - } + [HttpGet("_configuration/{clientId}")] + public IActionResult GetClientRequestParameters([FromRoute] string clientId) + { + var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); + return Ok(parameters); + } } diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/OrdersController.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/OrdersController.cs index 2b8bc99b..4cc7115e 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Server/OrdersController.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/OrdersController.cs @@ -1,114 +1,130 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; +using System.Security.Claims; +using System.Text.Json; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using WebPush; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +[Route("orders")] +[ApiController] +// [Authorize] +public class OrdersController : Controller { - [Route("orders")] - [ApiController] - // [Authorize] - public class OrdersController : Controller - { - private readonly PizzaStoreContext _db; - - public OrdersController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetOrders() - { - var orders = await _db.Orders - // .Where(o => o.UserId == GetUserId()) - .Include(o => o.DeliveryLocation) - .Include(o => o.Pizzas).ThenInclude(p => p.Special) - .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) - .OrderByDescending(o => o.CreatedTime) - .ToListAsync(); - - return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); - } - - [HttpGet("{orderId}")] - public async Task> GetOrderWithStatus(int orderId) - { - var order = await _db.Orders - .Where(o => o.OrderId == orderId) - // .Where(o => o.UserId == GetUserId()) - .Include(o => o.DeliveryLocation) - .Include(o => o.Pizzas).ThenInclude(p => p.Special) - .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) - .SingleOrDefaultAsync(); - - if (order == null) - { - return NotFound(); - } - - return OrderWithStatus.FromOrder(order); - } - - [HttpPost] - public async Task> PlaceOrder(Order order) - { - order.CreatedTime = DateTime.Now; - order.DeliveryLocation = new LatLong(51.5001, -0.1239); - // order.UserId = GetUserId(); - - // Enforce existence of Pizza.SpecialId and Topping.ToppingId - // in the database - prevent the submitter from making up - // new specials and toppings - foreach (var pizza in order.Pizzas) - { - pizza.SpecialId = pizza.Special.Id; - pizza.Special = null; - - foreach (var topping in pizza.Toppings) - { - topping.ToppingId = topping.Topping.Id; - topping.Topping = null; - } - } - - _db.Orders.Attach(order); - await _db.SaveChangesAsync(); - - // In the background, send push notifications if possible - var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); - if (subscription != null) - { - _ = TrackAndSendNotificationsAsync(order, subscription); - } - - return order.OrderId; - } - - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } - - private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription subscription) - { - // In a realistic case, some other backend process would track - // order delivery progress and send us notifications when it - // changes. Since we don't have any such process here, fake it. - await Task.Delay(OrderWithStatus.PreparationDuration); - await SendNotificationAsync(order, subscription, "Your order has been dispatched!"); - - await Task.Delay(OrderWithStatus.DeliveryDuration); - await SendNotificationAsync(order, subscription, "Your order is now delivered. Enjoy!"); - } - - private static Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) - { - // This will be implemented later - return Task.CompletedTask; - } - } + private readonly PizzaStoreContext _db; + + public OrdersController(PizzaStoreContext db) + { + _db = db; + } + + [HttpGet] + public async Task>> GetOrders() + { + var orders = await _db.Orders + .Where(o => o.UserId == GetUserId()) + .Include(o => o.DeliveryLocation) + .Include(o => o.Pizzas).ThenInclude(p => p.Special) + .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) + .OrderByDescending(o => o.CreatedTime) + .ToListAsync(); + + return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); + } + + [HttpGet("{orderId}")] + public async Task> GetOrderWithStatus(int orderId) + { + var order = await _db.Orders + .Where(o => o.OrderId == orderId) + .Where(o => o.UserId == GetUserId()) + .Include(o => o.DeliveryLocation) + .Include(o => o.Pizzas).ThenInclude(p => p.Special) + .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) + .SingleOrDefaultAsync(); + + if (order == null) + { + return NotFound(); + } + + return OrderWithStatus.FromOrder(order); + } + + [HttpPost] + public async Task> PlaceOrder(Order order) + { + order.CreatedTime = DateTime.Now; + order.DeliveryLocation = new LatLong(51.5001, -0.1239); + order.UserId = GetUserId(); + + // Enforce existence of Pizza.SpecialId and Topping.ToppingId + // in the database - prevent the submitter from making up + // new specials and toppings + foreach (var pizza in order.Pizzas) + { + pizza.SpecialId = pizza.Special.Id; + pizza.Special = null; + + foreach (var topping in pizza.Toppings) + { + topping.ToppingId = topping.Topping.Id; + topping.Topping = null; + } + } + + _db.Orders.Attach(order); + await _db.SaveChangesAsync(); + + // In the background, send push notifications if possible + var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); + if (subscription != null) + { + _ = TrackAndSendNotificationsAsync(order, subscription); + } + + return order.OrderId; + } + + private string GetUserId() + { + return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); + } + + private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription subscription) + { + // In a realistic case, some other backend process would track + // order delivery progress and send us notifications when it + // changes. Since we don't have any such process here, fake it. + await Task.Delay(OrderWithStatus.PreparationDuration); + await SendNotificationAsync(order, subscription, "Your order has been dispatched!"); + + await Task.Delay(OrderWithStatus.DeliveryDuration); + await SendNotificationAsync(order, subscription, "Your order is now delivered. Enjoy!"); + } + + private static async Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) + { + // For a real application, generate your own + var publicKey = "BLC8GOevpcpjQiLkO7JmVClQjycvTCYWm6Cq_a7wJZlstGTVZvwGFFHMYfXt6Njyvgx_GlXJeo5cSiZ1y4JOx1o"; + var privateKey = "OrubzSz3yWACscZXjFQrrtDwCKg-TGFuWhluQ2wLXDo"; + + var pushSubscription = new PushSubscription(subscription.Url, subscription.P256dh, subscription.Auth); + var vapidDetails = new VapidDetails("mailto:", publicKey, privateKey); + var webPushClient = new WebPushClient(); + try + { + var payload = JsonSerializer.Serialize(new + { + message, + url = $"myorders/{order.OrderId}", + }); + await webPushClient.SendNotificationAsync(pushSubscription, payload, vapidDetails); + } + catch (Exception ex) + { + Console.Error.WriteLine("Error sending push notification: " + ex.Message); + } + } } diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/PizzaApiExtensions.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/PizzaApiExtensions.cs new file mode 100644 index 00000000..bf6b7bde --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/PizzaApiExtensions.cs @@ -0,0 +1,60 @@ +using System.Security.Claims; +using Microsoft.AspNetCore.Authorization; +using Microsoft.EntityFrameworkCore; + +namespace BlazingPizza.Server; + +public static class PizzaApiExtensions +{ + + public static WebApplication MapPizzaApi(this WebApplication app) + { + + // Subscribe to notifications + app.MapPut("/notifications/subscribe", [Authorize] async ( + HttpContext context, + PizzaStoreContext db, + NotificationSubscription subscription) => + { + + // We're storing at most one subscription per user, so delete old ones. + // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. + var userId = GetUserId(context); + var oldSubscriptions = db.NotificationSubscriptions.Where(e => e.UserId == userId); + db.NotificationSubscriptions.RemoveRange(oldSubscriptions); + + // Store new subscription + subscription.UserId = userId; + db.NotificationSubscriptions.Attach(subscription); + + await db.SaveChangesAsync(); + return Results.Ok(subscription); + + }); + + // Specials + app.MapGet("/specials", async (PizzaStoreContext db) => + { + + var specials = await db.Specials.ToListAsync(); + return Results.Ok(specials); + + }); + + // Toppings + app.MapGet("/toppings", async (PizzaStoreContext db) => + { + var toppings = await db.Toppings.OrderBy(t => t.Name).ToListAsync(); + return Results.Ok(toppings); + }); + + return app; + + } + + private static string GetUserId(HttpContext context) + { + return context.User.FindFirstValue(ClaimTypes.NameIdentifier); + } + +} \ No newline at end of file diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/PizzaStoreContext.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/PizzaStoreContext.cs index 9485bd12..9a2e17ee 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Server/PizzaStoreContext.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/PizzaStoreContext.cs @@ -3,37 +3,36 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class PizzaStoreContext : ApiAuthorizationDbContext { - public class PizzaStoreContext : ApiAuthorizationDbContext - { - public PizzaStoreContext( - DbContextOptions options, - IOptions operationalStoreOptions) : base(options, operationalStoreOptions) - { - } + public PizzaStoreContext( + DbContextOptions options, + IOptions operationalStoreOptions) : base(options, operationalStoreOptions) + { + } - public DbSet Orders { get; set; } + public DbSet Orders { get; set; } - public DbSet Pizzas { get; set; } + public DbSet Pizzas { get; set; } - public DbSet Specials { get; set; } + public DbSet Specials { get; set; } - public DbSet Toppings { get; set; } + public DbSet Toppings { get; set; } - public DbSet NotificationSubscriptions { get; set; } + public DbSet NotificationSubscriptions { get; set; } - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - base.OnModelCreating(modelBuilder); + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); - // Configuring a many-to-many special -> topping relationship that is friendly for serialization - modelBuilder.Entity().HasKey(pst => new { pst.PizzaId, pst.ToppingId }); - modelBuilder.Entity().HasOne().WithMany(ps => ps.Toppings); - modelBuilder.Entity().HasOne(pst => pst.Topping).WithMany(); + // Configuring a many-to-many special -> topping relationship that is friendly for serialization + modelBuilder.Entity().HasKey(pst => new { pst.PizzaId, pst.ToppingId }); + modelBuilder.Entity().HasOne().WithMany(ps => ps.Toppings); + modelBuilder.Entity().HasOne(pst => pst.Topping).WithMany(); - // Inline the Lat-Long pairs in Order rather than having a FK to another table - modelBuilder.Entity().OwnsOne(o => o.DeliveryLocation); - } - } -} \ No newline at end of file + // Inline the Lat-Long pairs in Order rather than having a FK to another table + modelBuilder.Entity().OwnsOne(o => o.DeliveryLocation); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/PizzaStoreUser.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/PizzaStoreUser.cs index 171ce83d..7ab40235 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Server/PizzaStoreUser.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/PizzaStoreUser.cs @@ -1,8 +1,5 @@ using Microsoft.AspNetCore.Identity; -namespace BlazingPizza.Server -{ - public class PizzaStoreUser : IdentityUser - { - } -} \ No newline at end of file +namespace BlazingPizza.Server; + +public class PizzaStoreUser : IdentityUser { } \ No newline at end of file diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/PizzasController.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/PizzasController.cs deleted file mode 100644 index c082552c..00000000 --- a/save-points/04-refactor-state-management/BlazingPizza.Server/PizzasController.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("pizzas")] - [ApiController] - public class PizzasController : Controller - { - private readonly PizzaStoreContext _db; - - public PizzasController(PizzaStoreContext db) - { - _db = db; - } - } -} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Program.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Program.cs index 40a47641..4484d8f7 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Server/Program.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Program.cs @@ -1,33 +1,67 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; +using Microsoft.AspNetCore.Authentication; +using Microsoft.EntityFrameworkCore; +using BlazingPizza.Server; -namespace BlazingPizza.Server +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddControllersWithViews() + .AddJsonOptions(options => { + options.JsonSerializerOptions.AddContext(); + }); +builder.Services.AddRazorPages(); + +builder.Services.AddDbContext(options => + options.UseSqlite("Data Source=pizza.db") + .UseModel(BlazingPizza.Server.Models.PizzaStoreContextModel.Instance)); + +builder.Services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) + .AddEntityFrameworkStores(); + +builder.Services.AddIdentityServer() + .AddApiAuthorization(); + +builder.Services.AddAuthentication() + .AddIdentityServerJwt(); + +var app = builder.Build(); + +// Initialize the database +var scopeFactory = app.Services.GetRequiredService(); +using (var scope = scopeFactory.CreateScope()) +{ + var db = scope.ServiceProvider.GetRequiredService(); + if (db.Database.EnsureCreated()) + { + SeedData.Initialize(db); + } +} + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseWebAssemblyDebugging(); +} +else { - public class Program - { - public static void Main(string[] args) - { - var host = CreateHostBuilder(args).Build(); - - // Initialize the database - var scopeFactory = host.Services.GetRequiredService(); - using (var scope = scopeFactory.CreateScope()) - { - var db = scope.ServiceProvider.GetRequiredService(); - if (db.Database.EnsureCreated()) - { - SeedData.Initialize(db); - } - } - - host.Run(); - } - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); - } + app.UseExceptionHandler("/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); } + +app.UseHttpsRedirection(); +app.UseBlazorFrameworkFiles(); +app.UseStaticFiles(); + +app.UseRouting(); + +app.UseAuthentication(); +app.UseIdentityServer(); +app.UseAuthorization(); + +app.MapPizzaApi(); + +app.MapRazorPages(); +app.MapControllers(); +app.MapFallbackToFile("index.html"); + +app.Run(); \ No newline at end of file diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/SeedData.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/SeedData.cs index 7c86a5b2..a1e47973 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Server/SeedData.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/SeedData.cs @@ -1,193 +1,192 @@ -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public static class SeedData { - public static class SeedData - { - public static void Initialize(PizzaStoreContext db) - { - var toppings = new Topping[] - { - new Topping() - { - Name = "Extra cheese", - Price = 2.50m, - }, - new Topping() - { - Name = "American bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "British bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "Canadian bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "Tea and crumpets", - Price = 5.00m - }, - new Topping() - { - Name = "Fresh-baked scones", - Price = 4.50m, - }, - new Topping() - { - Name = "Bell peppers", - Price = 1.00m, - }, - new Topping() - { - Name = "Onions", - Price = 1.00m, - }, - new Topping() - { - Name = "Mushrooms", - Price = 1.00m, - }, - new Topping() - { - Name = "Pepperoni", - Price = 1.00m, - }, - new Topping() - { - Name = "Duck sausage", - Price = 3.20m, - }, - new Topping() - { - Name = "Venison meatballs", - Price = 2.50m, - }, - new Topping() - { - Name = "Served on a silver platter", - Price = 250.99m, - }, - new Topping() - { - Name = "Lobster on top", - Price = 64.50m, - }, - new Topping() - { - Name = "Sturgeon caviar", - Price = 101.75m, - }, - new Topping() - { - Name = "Artichoke hearts", - Price = 3.40m, - }, - new Topping() - { - Name = "Fresh tomatoes", - Price = 1.50m, - }, - new Topping() - { - Name = "Basil", - Price = 1.50m, - }, - new Topping() - { - Name = "Steak (medium-rare)", - Price = 8.50m, - }, - new Topping() - { - Name = "Blazing hot peppers", - Price = 4.20m, - }, - new Topping() - { - Name = "Buffalo chicken", - Price = 5.00m, - }, - new Topping() - { - Name = "Blue cheese", - Price = 2.50m, - }, - }; + public static void Initialize(PizzaStoreContext db) + { + var toppings = new Topping[] + { + new Topping() + { + Name = "Extra cheese", + Price = 2.50m, + }, + new Topping() + { + Name = "American bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "British bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "Canadian bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "Tea and crumpets", + Price = 5.00m + }, + new Topping() + { + Name = "Fresh-baked scones", + Price = 4.50m, + }, + new Topping() + { + Name = "Bell peppers", + Price = 1.00m, + }, + new Topping() + { + Name = "Onions", + Price = 1.00m, + }, + new Topping() + { + Name = "Mushrooms", + Price = 1.00m, + }, + new Topping() + { + Name = "Pepperoni", + Price = 1.00m, + }, + new Topping() + { + Name = "Duck sausage", + Price = 3.20m, + }, + new Topping() + { + Name = "Venison meatballs", + Price = 2.50m, + }, + new Topping() + { + Name = "Served on a silver platter", + Price = 250.99m, + }, + new Topping() + { + Name = "Lobster on top", + Price = 64.50m, + }, + new Topping() + { + Name = "Sturgeon caviar", + Price = 101.75m, + }, + new Topping() + { + Name = "Artichoke hearts", + Price = 3.40m, + }, + new Topping() + { + Name = "Fresh tomatoes", + Price = 1.50m, + }, + new Topping() + { + Name = "Basil", + Price = 1.50m, + }, + new Topping() + { + Name = "Steak (medium-rare)", + Price = 8.50m, + }, + new Topping() + { + Name = "Blazing hot peppers", + Price = 4.20m, + }, + new Topping() + { + Name = "Buffalo chicken", + Price = 5.00m, + }, + new Topping() + { + Name = "Blue cheese", + Price = 2.50m, + }, + }; - var specials = new PizzaSpecial[] - { - new PizzaSpecial() - { - Name = "Basic Cheese Pizza", - Description = "It's cheesy and delicious. Why wouldn't you want one?", - BasePrice = 9.99m, - ImageUrl = "img/pizzas/cheese.jpg", - }, - new PizzaSpecial() - { - Id = 2, - Name = "The Baconatorizor", - Description = "It has EVERY kind of bacon", - BasePrice = 11.99m, - ImageUrl = "img/pizzas/bacon.jpg", - }, - new PizzaSpecial() - { - Id = 3, - Name = "Classic pepperoni", - Description = "It's the pizza you grew up with, but Blazing hot!", - BasePrice = 10.50m, - ImageUrl = "img/pizzas/pepperoni.jpg", - }, - new PizzaSpecial() - { - Id = 4, - Name = "Buffalo chicken", - Description = "Spicy chicken, hot sauce and bleu cheese, guaranteed to warm you up", - BasePrice = 12.75m, - ImageUrl = "img/pizzas/meaty.jpg", - }, - new PizzaSpecial() - { - Id = 5, - Name = "Mushroom Lovers", - Description = "It has mushrooms. Isn't that obvious?", - BasePrice = 11.00m, - ImageUrl = "img/pizzas/mushroom.jpg", - }, - new PizzaSpecial() - { - Id = 6, - Name = "The Brit", - Description = "When in London...", - BasePrice = 10.25m, - ImageUrl = "img/pizzas/brit.jpg", - }, - new PizzaSpecial() - { - Id = 7, - Name = "Veggie Delight", - Description = "It's like salad, but on a pizza", - BasePrice = 11.50m, - ImageUrl = "img/pizzas/salad.jpg", - }, - new PizzaSpecial() - { - Id = 8, - Name = "Margherita", - Description = "Traditional Italian pizza with tomatoes and basil", - BasePrice = 9.99m, - ImageUrl = "img/pizzas/margherita.jpg", - }, - }; + var specials = new PizzaSpecial[] + { + new PizzaSpecial() + { + Name = "Basic Cheese Pizza", + Description = "It's cheesy and delicious. Why wouldn't you want one?", + BasePrice = 9.99m, + ImageUrl = "img/pizzas/cheese.jpg", + }, + new PizzaSpecial() + { + Id = 2, + Name = "The Baconatorizor", + Description = "It has EVERY kind of bacon", + BasePrice = 11.99m, + ImageUrl = "img/pizzas/bacon.jpg", + }, + new PizzaSpecial() + { + Id = 3, + Name = "Classic pepperoni", + Description = "It's the pizza you grew up with, but Blazing hot!", + BasePrice = 10.50m, + ImageUrl = "img/pizzas/pepperoni.jpg", + }, + new PizzaSpecial() + { + Id = 4, + Name = "Buffalo chicken", + Description = "Spicy chicken, hot sauce and bleu cheese, guaranteed to warm you up", + BasePrice = 12.75m, + ImageUrl = "img/pizzas/meaty.jpg", + }, + new PizzaSpecial() + { + Id = 5, + Name = "Mushroom Lovers", + Description = "It has mushrooms. Isn't that obvious?", + BasePrice = 11.00m, + ImageUrl = "img/pizzas/mushroom.jpg", + }, + new PizzaSpecial() + { + Id = 6, + Name = "The Brit", + Description = "When in London...", + BasePrice = 10.25m, + ImageUrl = "img/pizzas/brit.jpg", + }, + new PizzaSpecial() + { + Id = 7, + Name = "Veggie Delight", + Description = "It's like salad, but on a pizza", + BasePrice = 11.50m, + ImageUrl = "img/pizzas/salad.jpg", + }, + new PizzaSpecial() + { + Id = 8, + Name = "Margherita", + Description = "Traditional Italian pizza with tomatoes and basil", + BasePrice = 9.99m, + ImageUrl = "img/pizzas/margherita.jpg", + }, + }; - db.Toppings.AddRange(toppings); - db.Specials.AddRange(specials); - db.SaveChanges(); - } - } -} + db.Toppings.AddRange(toppings); + db.Specials.AddRange(specials); + db.SaveChanges(); + } +} \ No newline at end of file diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/SpecialsController.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/SpecialsController.cs deleted file mode 100644 index a176844c..00000000 --- a/save-points/04-refactor-state-management/BlazingPizza.Server/SpecialsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("specials")] - [ApiController] - public class SpecialsController : Controller - { - private readonly PizzaStoreContext _db; - - public SpecialsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetSpecials() - { - return (await _db.Specials.ToListAsync()).OrderByDescending(s => s.BasePrice).ToList(); - } - } -} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Startup.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Startup.cs deleted file mode 100644 index ed3fca06..00000000 --- a/save-points/04-refactor-state-management/BlazingPizza.Server/Startup.cs +++ /dev/null @@ -1,70 +0,0 @@ -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace BlazingPizza.Server -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - public void ConfigureServices(IServiceCollection services) - { - services.AddControllersWithViews(); - services.AddRazorPages(); - - services.AddDbContext(options => - options.UseSqlite("Data Source=pizza.db")); - - services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) - .AddEntityFrameworkStores(); - - services.AddIdentityServer() - .AddApiAuthorization(); - - services.AddAuthentication() - .AddIdentityServerJwt(); - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - app.UseWebAssemblyDebugging(); - } - else - { - app.UseExceptionHandler("/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); - } - - app.UseHttpsRedirection(); - app.UseBlazorFrameworkFiles(); - app.UseStaticFiles(); - - app.UseRouting(); - - app.UseAuthentication(); - app.UseIdentityServer(); - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - endpoints.MapRazorPages(); - endpoints.MapFallbackToFile("index.html"); - }); - } - } -} \ No newline at end of file diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/ToppingsController.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/ToppingsController.cs deleted file mode 100644 index 6a677639..00000000 --- a/save-points/04-refactor-state-management/BlazingPizza.Server/ToppingsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("toppings")] - [ApiController] - public class ToppingsController : Controller - { - private readonly PizzaStoreContext _db; - - public ToppingsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetToppings() - { - return await _db.Toppings.OrderBy(t => t.Name).ToListAsync(); - } - } -} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/pizza.db-shm b/save-points/04-refactor-state-management/BlazingPizza.Server/pizza.db-shm new file mode 100644 index 0000000000000000000000000000000000000000..0ba16f0cb838a14216aa22cdaa5553f246a133be GIT binary patch literal 32768 zcmeI*xiW)c7{&3A*tf(Ud#te&6e^w4j7I4q+=t6hxdV+-L$6RUN;kndMMla;VR+y9 zpP4fg=9@@?y2#5ef4Y}=&E~_i*s=B7u)pd14-Bh>KZPjYK>Ylo<+RUH5`FZq`Abkkh}zZwShzgd^3aOCE$A{BqHEzF(fYmU+N(d0pCd?c?tMN6^RIx zi^IrcJd==sud|VeK&9~IJ(81v?-G)TfUiQ5yaaralSBl350&I4;9ImLBH&BFBrgG9 YVI~m)-@qn$3Hbgvi3s@mJBbK<0sk;F>Hq)$ literal 0 HcmV?d00001 diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/pizza.db-wal b/save-points/04-refactor-state-management/BlazingPizza.Server/pizza.db-wal new file mode 100644 index 0000000000000000000000000000000000000000..435bedc6a6aeb137805dda08f553d088e56512e6 GIT binary patch literal 214272 zcmeI54R9Q1dB^Xh^PMD1Iwy*JksZbBlO5|KOSbGN!QsO>pHB86`6QoCj@^)4R(G$Z zjqh&HyL+}Jnt&|FkisOCQrbd+6hi5cCX_H~389pRmhw^P2M}gRTbS?-878G6G_+;< zzPtP0erQjUJCn}j=6^HR?fdyW&+mEOci(-q8sGG$;052{vse3kn|$o^?YE!#^6NhT z%*=x)9{BmA*9?AxR{8DqU+cQ|j;FtyxMBL(grpJSl&q9QP1sLIH#PZg5d_+|iT)dA zW6Vz<{SNQ~{nqERmAx*Td_$9WZ=fwr;TKu^b>aUCzu5L<$Mvm&wu_;6v^*0W4-|v# z%}Ueb{`SuEUQ_)4)h%DQDHQ4H@n71diL*sAsT7E!8b7Z{WRmf0Qpm;+O(cb=Q5hBb zJK6;LG0LezR7j<>$-~Kvke6wWMAu*Yr&Sv7YUWiVO=lH;>OzLPnb5a;jp4@HD zkx+=JkwR7~k*JVOo}d$$lkgrhDp8maqmj^+JDiWrrA5dn}nr zrW46&A!-h!w4+pkSVvoI>E>`K(%b95a9DR#R<2Z}@|?=QH#wcft1Wjq?5N`@Yn07b zLVPAWnM%|7k0#Sujx;S=F0-garxYpgb|q8(T&J%5a$Hw_x(q03R$tA(=~G8NNXt4-R-}q z>JVvktL$H!6Ai1fC|K^VvjU9nHmi8(#fx*YB5Cs_Zj3wbjeAm^*41K~hWnHvYcv3f z$8C|zPpKzH_8v$O#S9f1l-tVijx-xj4Axk$_?)h`2HQL49Gc9fcHAGWbd{2c+KfDZ_O00@8p2!H?xfB*=900@8p2sAQ*ATy4?FYs{e z{%7~y`oKH!zCa_p9JYY~2!H?xfB*=900@8p2!H?xfIy8vh+Xl#z=j)s@cwr_{IO5s zeSsPuTz~)wfB*=900@8p2!H?xfB*=9KqC{-|6d567r6A^;}1UH^R79(FVM&?hixDL z0w4eaAOHd&00JNY0w4eaAW$RF%C2}`;7dOyZ@Bcf9U|TrsPVxC2!H?xfB*=900@8p z2!H?xfB*8 z2yA3mJTLJ2Ti*Gp&i8&XiuVO-d~g8*AOHd&00JNY0w4eaAOHd&00NCnpq&}V^8#D< z{mW}^_}ttA-WOE zK#dPBKmY_l00ck)1V8`;KmY_l00cmwkqLA%<9J@+jZb}lOYCH15r0R}$S#L%AOHd& z00JNY0w4eaAOHd&00JOTBM@d+JTLH4^zYuV?YXg!<9&e|A6$R{2!H?xfB*=900@8p z2!H?xfIuS?*u;$Ed4c=h_tN#{dc~*@*f{UUZBPY7a#xvAOHd&00JNY0w4eaAOHd&(8vU?WXAElz%{>k zWY+hlzI%`tXk?eeHV^;-5C8!X009sH0T2KI5C8!Xs1fL5S3EE9&ZV)>KC$7$109{` zeVxsUuk)Wf-`pW~#@n9kxV|;eb}{shmS=+FfrkUdW~J$Ie>?5g@So1}O{XF~J^o9( zG;y{_CY1tFRO9CriA*w{O$yogp^2mrH7cV*e@B}@KSnuKhzhB6HhDOi5z>=cAw4rO zAtWZ#)7ea%)(g?8@f;sGl}R0qXHE*^$&j(dBZ3vN@t0(Fd^qfO_IyG3Hqf~3v?o?_JpoU{l0Q}ZmrJoLO~&_>afs~Z?|!b z+n6)Q*ac(vs&haGi1WsS1=N{G*7CsS!U|IuVR%aNu<%Vido=#(Pm z-L7QHpX=0>Uykd_Pgh7@5{oMT4m*|S)t9HdHEK=e4~Z)A(v%xFO4Pg}RajVgL|&>S z&XF0V=+We&LM?x7M=)}1!0(gF1#(_JQ*FyO!Uj1JD#>?(FRF}hkUn&V`F>s}`iRt&Wv<&Y9ZiIg>KZMqh2LN2S-l5=g_ z0!3f>lJCbtuSkl%De&Po!P9h2Q@NJj_O|NmT_kU_$<~%#sCWeS zg+m)dk%I^Q7rS)-q-9MyB^evibal2CMQYuKcBjwk_OrZKugiKCc)hV|RIqv2d&S4A z+PnwPseL0i7Q7m~SICO}oUV}zM_NOX?r#4@RfkB!Q)U0!oM>2;MZxl4oe(y<+pOZT z6EDumiloh#xH0a)HSS4uT2~878n07|tkDP}9=AmzHWt>X^ISP!qPwVN=fyiD7LrJBnI?uM27i7R9-cTb^?8fgheQhoIt zWvN8{Wh=B^EN;-12scRIi?nKP4&jUQ%BKJq4bYt6H+m4zcU$ z=XIn^%SuTsN{ggWPaUfVWA3`!b91LeRXrywg(ITswJ%Q1%VmnsnP{P zT*YPwBv)g9nI6J-(~+?Y1O8BC>sJ58K?At)=wd!ZG&$z5JzAI#Ve2_K)SgFdjJ=Nu z2^x+(u3g*Ygj6QOtF-OoZMKcU4&OE1luXYHMUQ(AUx*npr{5y0` z?qs7c|3jyr-QMS4YSj<_`W};Fj|H}+v%~aNDm|J!Aw;b{QDHJo9}BJho-UH86{E(6 z6prTE&gW#bUK~dayiif54_m1j}-+n>`Zyqo#(tg{V^Ap1 zj$7?~bT?~V&+9dG?2M{EvonW{CMS|KgOZ3(C*q??8hSK%;?slmZu={=vF)mc*;|)0 z-TDLJrQ2K{*0&gI0=;;3J^$*h>vS*cThI4)nhqzK0_yq5oO4a5=+l@!F|N&#g3~8_ zK4%U^_lZ8NzE9Q)3qz{K^<{~Q*KS@dNni;#l(7YcUeU9>w@Y93myCx{tG~V!Y^&ZV zZ>|>=Mza+b&XweypX2MEK2+3M`n<=eq*jXJf_*2jRy$w6o|O})9-if1Bs$2m25sY%H8#RZZumyU)N!v zw%PH~b_aN-3-yln6pGFDdRv{lz`EnYv6mZaz1%)r_Fb{k1#Cqc;*Di!m9O-2fz|wf zae;mG%jW_nWj!~5nhPwoUe>K!Kgl)!=-_~VsaHQyrB2vf&XiDdhVIsmsMq$Ho-hwt zb%(jnT>4;kD=}t`#+LlsLXr5Oe`)(l`R2+sP79U-Ms;)*4IBgADwxBm4*VFhtIxGUquJUK(`J?BjdnzDE5XTyXe7otB!%uVY|HTY^#$KOo21$)UlZ)&0gt8 zTt{!aD18i*Vx4l0liZU38c&Pa08?>xnJTzf;I=vzuNdf7!?M_zI7%NOn!gd*xzm4X zQr~{3q{T(i{OyVTy4RFw{tC_BWUY6-)@$G82W)fVRl2zDkWM-FouNO3{CmFZ}$%N7`7W{y!M93w%HT1V8`;KmY_l00ck)1V8`;KmY_9 zl)%-@E}j?I|2u#DC!6os`$4=f(4gLiSs(xcAOHd&00JNY0w4eaAOHd&;3Uw)iaamy z{3m|;_Tv3puEzTUPDm($00@8p2!H?xfB*=900@8p2!KF?64=7*;(39GIs)%L>$@j{ z_XQf%+b|0RKmY_l00ck)1V8`;KmY_l00f)_wz4A63mo~5_Nlk-dtSu*0!~OMfdB}A z00@8p2!H?xfB*=900@9UgA%xg*~Rk$7r%4$_dfcnhez?gK!bW4W`O_*fB*=900@8p z2!H?xfB*=9fRjKkEAqU+5C699(OX_~uZp~Y6B0@w00JNY0w4eaAOHd&00JNY0wBRv@w~tbZ(X?ZN5}r>5&RuNgL)fgfdB}A00@8p2!H?xfB*=900@A9lfX7sW0<(+f1$zJcTb~;G;7bRP z7ids#!z>U00T2KI5C8!X009sH0T2KI5O5OM&Wb!QaR0@>xo5WNo8!m}I3b|~0w4ea zAOHd&00JNY0w4eaAOHdlN+8PY;(38vDhHqa;xE7cedGli)Y~u%1V8`;KmY_l00ck) z1V8`;KmY`s1o~K!=LNp|%hv0Db+GLt$O||jp#%aT00JNY0w4eaAOHd&00JNY0u4%F z2eXUk1quh-e(UJc$3Bj{K!bW4W`O_*fB*=900@8p2!H?xfB*=9fRn&ZR^)ks_9yO4 z-_i8shmaR=LP7}yKmY_l00ck)1V8`;KmY_l00bJ8z;(1zVcXm+mX9FXx--K zHedL!I-YCq+xU}>r`rCrO>2F=^-OEH<$Wz%LLUen4}L3nWW%R7GzShh|D^d6?Tily zG#r7&!BFJjPXAJ`R4$P7sS~*=X>n1^%9V;#p39lvse-+BIFU)lvq>S99!;JQqIJha zg~_xKwU3Mn{n6T#(b(+nP-K6Pe`$k5wwjx+kh~-oO{wZ$Z+W(UHc2XzQJWwdyKNvC z+0)~{+a+RBDG-GV*i%n{*~>jWuZ}GpxIPrg5BQhP)TSqjDybSN99G1#MpdlN-bM0S zs*sx|sw&B4dX-(MkSS-sp_LjqJJg-X)XmvjXTT*#cMH*)a8_XQqp_tMW1)yhbuX>0 zd!i_jGBd(M^})+f-7(MlH0MKXinsQMB8REsgY^_op07xXs8QN3%)8gr)f!q?JzJO9 zQg~M=GEQ|Fsi#XqF00iNDP*OR+vx*qYGWTGpDN1LF zvJfv66dH-Cf>D3{3LWb8H{=_wEWTDu7>ym?8I1IG`w164P8QVMj7r#dY=t1+YD~;Z zY+Bkq8e7;wH>Ez?rZh^SXb&UQ}#?cb!^7IE!z6nMtZ7Xb&bX<(NJU;wZ2c+fC5p{Vu_^K{v1~;X`-(U6 zP^xsD)NV7DRvEcSy~=*33a;8dr%-yQadj|Er}cpfjKyz3rm(G0xCpvoedX@wAu?FcoK)oVr!Lt&YW34-dy% zjdsu9v^5wR-|6@12CHX^l16f3Rg?9y^RP2)KdM~2Jhmki*}2nyX;Kqsi^Se$zwR|v z&BhN+Bv+hvI@$#KG0s3V2I!F~n>?J%2C*ll*O4n_64Bqr0-*-V^HK&Kmb zC>|B2GO45S%t>K9d6EX4t{#=fZuQ1Fj)k8o%0ADSa~@+-)%arCj!kBgsl#d4v@s!* z97|@B=|pncG)>>RnGkm38%<6m>FF>LpH9R_lj{&`DydqhO}A*984lrmBy+g8_>Q*N z@>EYK($nL=^hV2(s?JEg#>08c7Sk(?f!kw(9UylE9b@-`_#3w4}akqOcSlKmY_l00ck)1V8`;KmY_lpy3D% zFpGFz;DOFYuSI`_~7) z{odc4>7aE@;qUpvKc_$N0Ra#I0T2KI5C8!X009sH0T2KI5O~EBXm4un^=IWuMJms! zo7?@gG+iNiNi3=@)Tl5sjOPXJKXS6=w`cG9GRq6Jbd31IzaO6H{6VMExwYfjj^Cvf z_<#TifB*=900@8p2!H?xfB*>ie0Q`2eckfG?FWVq9LOqSLDD3-EEa{7CKe^JEL5b$ zMNv2>Y4d_6mqbk_svwpN!mOxDMX5BmNAIBSDT&J5JW(V~9J;GAceGX-57GI@M`FXn zLnA3|mnsyc(?n3kqFC51%vLo)E(@X|#WtJX&L%oe=H?_KjFO@>H?Q3k4EiE__V*6& z9ojc?>pUq7QdyXg%LTbSG&E!zKT8#1!?W{5I7F{!Hc%~Yef0pV# zmP_i8kW$OLG(npesW!7`CAq2|w9Umk>UNofsL-=SQI$Z*7g_2W85rI-bkoRmManM- z`FSaSnv{17^RhY70!} zq3WqqVo~N37n+&FUb}}fFo0^*M#D>NjyZ*#qZ8>KGXNhdii`9qn(4FMHh+awDnyaX z5|fcAimEE*g<9q7n<(k{$Q}ypzyXt3@^~_HQaCM9@5`rX0OaXlD**IzjX7(i!JnR1RIqTxa8&M*k-SZDy| zg@jI2m|{^%m-8n2ul9EYAKi8IJHvnf#1zX5Z0`8AFZ|Q+*TSC;KNNmjxDviCJQ2P* z+#l}he5vzmolkZ?*!h;uO6P3nSm*VfSJKY-fB*=900@8p2!H?xfB*=900_Lo2wb^2 z;Opx;RIC#7@q6FU$mZ^VZ=lQdU_COlcgs})-+tP+_P}gD5UV!~?c37D+NL!ko)-E` zq##vGgNmq-*sF#{+OG`wB3*}AN`$64x~~ZMVqIejQLUT_t&VI8_y)V;iYDdfWtsz- zC!(UM`-g7m2~%x)rnRavM`$)AFP@b|Wq9u}O(|^dq*HZI$g`?O6qYK{9YX(?mH-QwVwng^H#b387LHHQIIG$X@!eeRX@lx2NkkDN8EtQ=$olS+Q7DDS)nx z0pHH9(Q5uQOHrue9N9m#Z&O>qx2BN{d|~ zHqRkaEOJt`vL_hu4IB0k&Wfk0hAPbl5DIZ5vVk$k5>bEn&nwkZg=i`zzd67RO^9Wh wfudO_J(;kNn$X=G@a^hmDIAH?tW|GrV%_5 $(TargetFrameworkVersion) BlazingPizza + true diff --git a/save-points/04-refactor-state-management/BlazingPizza.Shared/LatLong.cs b/save-points/04-refactor-state-management/BlazingPizza.Shared/LatLong.cs index 9b8c3811..14a94c26 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Shared/LatLong.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Shared/LatLong.cs @@ -1,27 +1,26 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class LatLong { - public class LatLong - { - public LatLong() - { - } + public LatLong() + { + } - public LatLong(double latitude, double longitude) : this() - { - Latitude = latitude; - Longitude = longitude; - } + public LatLong(double latitude, double longitude) : this() + { + Latitude = latitude; + Longitude = longitude; + } - public double Latitude { get; set; } + public double Latitude { get; set; } - public double Longitude { get; set; } + public double Longitude { get; set; } - public static LatLong Interpolate(LatLong start, LatLong end, double proportion) - { - // The Earth is flat, right? So no need for spherical interpolation. - return new LatLong( - start.Latitude + (end.Latitude - start.Latitude) * proportion, - start.Longitude + (end.Longitude - start.Longitude) * proportion); - } - } -} + public static LatLong Interpolate(LatLong start, LatLong end, double proportion) + { + // The Earth is flat, right? So no need for spherical interpolation. + return new LatLong( + start.Latitude + (end.Latitude - start.Latitude) * proportion, + start.Longitude + (end.Longitude - start.Longitude) * proportion); + } +} \ No newline at end of file diff --git a/save-points/04-refactor-state-management/BlazingPizza.Shared/NotificationSubscription.cs b/save-points/04-refactor-state-management/BlazingPizza.Shared/NotificationSubscription.cs index 04259c2f..9109ff57 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Shared/NotificationSubscription.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Shared/NotificationSubscription.cs @@ -1,17 +1,14 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class NotificationSubscription { - public class NotificationSubscription - { - public int NotificationSubscriptionId { get; set; } + public int NotificationSubscriptionId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public string Url { get; set; } + public string Url { get; set; } - public string P256dh { get; set; } + public string P256dh { get; set; } - public string Auth { get; set; } - } + public string Auth { get; set; } } diff --git a/save-points/04-refactor-state-management/BlazingPizza.Shared/Order.cs b/save-points/04-refactor-state-management/BlazingPizza.Shared/Order.cs index fb003bd6..aca04ca1 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Shared/Order.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Shared/Order.cs @@ -1,25 +1,32 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +public class Order { - public class Order - { - public int OrderId { get; set; } + public int OrderId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public DateTime CreatedTime { get; set; } + public DateTime CreatedTime { get; set; } - public Address DeliveryAddress { get; set; } = new Address(); + public Address DeliveryAddress { get; set; } = new Address(); - public LatLong DeliveryLocation { get; set; } + public LatLong DeliveryLocation { get; set; } - public List Pizzas { get; set; } = new List(); + public List Pizzas { get; set; } = new List(); - public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); + public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); - public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); - } + public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Default, PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] +[JsonSerializable(typeof(Order))] +[JsonSerializable(typeof(OrderWithStatus))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Pizza))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Topping))] +public partial class OrderContext : JsonSerializerContext {} \ No newline at end of file diff --git a/save-points/04-refactor-state-management/BlazingPizza.Shared/OrderWithStatus.cs b/save-points/04-refactor-state-management/BlazingPizza.Shared/OrderWithStatus.cs index 021de78c..f5f153b6 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Shared/OrderWithStatus.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Shared/OrderWithStatus.cs @@ -1,79 +1,78 @@ -using BlazingPizza.ComponentsLibrary.Map; -using System; -using System.Collections.Generic; +using System.Text.Json.Serialization; +using BlazingPizza.ComponentsLibrary.Map; -namespace BlazingPizza + +namespace BlazingPizza; + +public class OrderWithStatus { - public class OrderWithStatus - { - public readonly static TimeSpan PreparationDuration = TimeSpan.FromSeconds(10); - public readonly static TimeSpan DeliveryDuration = TimeSpan.FromMinutes(1); // Unrealistic, but more interesting to watch + public readonly static TimeSpan PreparationDuration = TimeSpan.FromSeconds(10); + public readonly static TimeSpan DeliveryDuration = TimeSpan.FromMinutes(1); // Unrealistic, but more interesting to watch - public Order Order { get; set; } + public Order Order { get; set; } - public string StatusText { get; set; } + public string StatusText { get; set; } - public bool IsDelivered => StatusText == "Delivered"; + public bool IsDelivered => StatusText == "Delivered"; - public List MapMarkers { get; set; } + public List MapMarkers { get; set; } - public static OrderWithStatus FromOrder(Order order) - { - // To simulate a real backend process, we fake status updates based on the amount - // of time since the order was placed - string statusText; - List mapMarkers; - var dispatchTime = order.CreatedTime.Add(PreparationDuration); + public static OrderWithStatus FromOrder(Order order) + { + // To simulate a real backend process, we fake status updates based on the amount + // of time since the order was placed + string statusText; + List mapMarkers; + var dispatchTime = order.CreatedTime.Add(PreparationDuration); - if (DateTime.Now < dispatchTime) - { - statusText = "Preparing"; - mapMarkers = new List - { - ToMapMarker("You", order.DeliveryLocation, showPopup: true) - }; - } - else if (DateTime.Now < dispatchTime + DeliveryDuration) - { - statusText = "Out for delivery"; + if (DateTime.Now < dispatchTime) + { + statusText = "Preparing"; + mapMarkers = new List + { + ToMapMarker("You", order.DeliveryLocation, showPopup: true) + }; + } + else if (DateTime.Now < dispatchTime + DeliveryDuration) + { + statusText = "Out for delivery"; - var startPosition = ComputeStartPosition(order); - var proportionOfDeliveryCompleted = Math.Min(1, (DateTime.Now - dispatchTime).TotalMilliseconds / DeliveryDuration.TotalMilliseconds); - var driverPosition = LatLong.Interpolate(startPosition, order.DeliveryLocation, proportionOfDeliveryCompleted); - mapMarkers = new List - { - ToMapMarker("You", order.DeliveryLocation), - ToMapMarker("Driver", driverPosition, showPopup: true), - }; - } - else - { - statusText = "Delivered"; - mapMarkers = new List - { - ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), - }; - } + var startPosition = ComputeStartPosition(order); + var proportionOfDeliveryCompleted = Math.Min(1, (DateTime.Now - dispatchTime).TotalMilliseconds / DeliveryDuration.TotalMilliseconds); + var driverPosition = LatLong.Interpolate(startPosition, order.DeliveryLocation, proportionOfDeliveryCompleted); + mapMarkers = new List + { + ToMapMarker("You", order.DeliveryLocation), + ToMapMarker("Driver", driverPosition, showPopup: true), + }; + } + else + { + statusText = "Delivered"; + mapMarkers = new List + { + ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), + }; + } - return new OrderWithStatus - { - Order = order, - StatusText = statusText, - MapMarkers = mapMarkers, - }; - } + return new OrderWithStatus + { + Order = order, + StatusText = statusText, + MapMarkers = mapMarkers, + }; + } - private static LatLong ComputeStartPosition(Order order) - { - // Random but deterministic based on order ID - var rng = new Random(order.OrderId); - var distance = 0.01 + rng.NextDouble() * 0.02; - var angle = rng.NextDouble() * Math.PI * 2; - var offset = (distance * Math.Cos(angle), distance * Math.Sin(angle)); - return new LatLong(order.DeliveryLocation.Latitude + offset.Item1, order.DeliveryLocation.Longitude + offset.Item2); - } + private static LatLong ComputeStartPosition(Order order) + { + // Random but deterministic based on order ID + var rng = new Random(order.OrderId); + var distance = 0.01 + rng.NextDouble() * 0.02; + var angle = rng.NextDouble() * Math.PI * 2; + var offset = (distance * Math.Cos(angle), distance * Math.Sin(angle)); + return new LatLong(order.DeliveryLocation.Latitude + offset.Item1, order.DeliveryLocation.Longitude + offset.Item2); + } - static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) - => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; - } -} + static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) + => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; +} \ No newline at end of file diff --git a/save-points/04-refactor-state-management/BlazingPizza.Shared/Pizza.cs b/save-points/04-refactor-state-management/BlazingPizza.Shared/Pizza.cs index ec1108a9..459298f4 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Shared/Pizza.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Shared/Pizza.cs @@ -1,42 +1,44 @@ -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// /// Represents a customized pizza as part of an order +/// +public class Pizza { - /// - /// Represents a customized pizza as part of an order - /// - public class Pizza - { - public const int DefaultSize = 12; - public const int MinimumSize = 9; - public const int MaximumSize = 17; + public const int DefaultSize = 12; + public const int MinimumSize = 9; + public const int MaximumSize = 17; - public int Id { get; set; } + public int Id { get; set; } - public int OrderId { get; set; } + public int OrderId { get; set; } - public PizzaSpecial Special { get; set; } + public PizzaSpecial Special { get; set; } - public int SpecialId { get; set; } + public int SpecialId { get; set; } - public int Size { get; set; } + public int Size { get; set; } - public List Toppings { get; set; } + public List Toppings { get; set; } - public decimal GetBasePrice() - { - return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; - } + public decimal GetBasePrice() + { + return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; + } - public decimal GetTotalPrice() - { - return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); - } + public decimal GetTotalPrice() + { + return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); + } - public string GetFormattedTotalPrice() - { - return GetTotalPrice().ToString("0.00"); - } - } + public string GetFormattedTotalPrice() + { + return GetTotalPrice().ToString("0.00"); + } } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Serialization)] +[JsonSerializable(typeof(Pizza))] +public partial class PizzaContext : JsonSerializerContext {} \ No newline at end of file diff --git a/save-points/04-refactor-state-management/BlazingPizza.Shared/PizzaSpecial.cs b/save-points/04-refactor-state-management/BlazingPizza.Shared/PizzaSpecial.cs index 2f2b3383..9653300c 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Shared/PizzaSpecial.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Shared/PizzaSpecial.cs @@ -1,20 +1,19 @@ -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// Represents a pre-configured template for a pizza a user can order +/// +public class PizzaSpecial { - /// - /// Represents a pre-configured template for a pizza a user can order - /// - public class PizzaSpecial - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal BasePrice { get; set; } + public decimal BasePrice { get; set; } - public string Description { get; set; } + public string Description { get; set; } - public string ImageUrl { get; set; } + public string ImageUrl { get; set; } - public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); - } -} + public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); +} \ No newline at end of file diff --git a/save-points/04-refactor-state-management/BlazingPizza.Shared/PizzaTopping.cs b/save-points/04-refactor-state-management/BlazingPizza.Shared/PizzaTopping.cs index f5a6c1ac..0a711647 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Shared/PizzaTopping.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Shared/PizzaTopping.cs @@ -1,11 +1,11 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class PizzaTopping { - public class PizzaTopping - { - public Topping Topping { get; set; } + public Topping Topping { get; set; } + + public int ToppingId { get; set; } - public int ToppingId { get; set; } - - public int PizzaId { get; set; } - } -} + public int PizzaId { get; set; } + +} \ No newline at end of file diff --git a/save-points/04-refactor-state-management/BlazingPizza.Shared/Topping.cs b/save-points/04-refactor-state-management/BlazingPizza.Shared/Topping.cs index 61bdeb92..376c311a 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Shared/Topping.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Shared/Topping.cs @@ -1,13 +1,13 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class Topping { - public class Topping - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal Price { get; set; } + public decimal Price { get; set; } - public string GetFormattedPrice() => Price.ToString("0.00"); - } -} + public string GetFormattedPrice() => Price.ToString("0.00"); + +} \ No newline at end of file diff --git a/save-points/04-refactor-state-management/BlazingPizza.Shared/UserInfo.cs b/save-points/04-refactor-state-management/BlazingPizza.Shared/UserInfo.cs index 4996ef80..362f8f8e 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Shared/UserInfo.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Shared/UserInfo.cs @@ -1,9 +1,9 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class UserInfo { - public class UserInfo - { - public bool IsAuthenticated { get; set; } + public bool IsAuthenticated { get; set; } - public string Name { get; set; } - } -} + public string Name { get; set; } + +} \ No newline at end of file diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Client/BlazingPizza.Client.csproj b/save-points/05-checkout-with-validation/BlazingPizza.Client/BlazingPizza.Client.csproj index 663677a1..44802d79 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/save-points/05-checkout-with-validation/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -2,16 +2,19 @@ $(TargetFrameworkVersion) + true + - + + diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Client/OrderState.cs b/save-points/05-checkout-with-validation/BlazingPizza.Client/OrderState.cs index f44ac786..4f47979d 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Client/OrderState.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Client/OrderState.cs @@ -1,50 +1,52 @@ -using System.Collections.Generic; +namespace BlazingPizza.Client; -namespace BlazingPizza.Client +public class OrderState { - public class OrderState - { - public bool ShowingConfigureDialog { get; private set; } - - public Pizza ConfiguringPizza { get; private set; } - - public Order Order { get; private set; } = new Order(); - - public void ShowConfigurePizzaDialog(PizzaSpecial special) - { - ConfiguringPizza = new Pizza() - { - Special = special, - SpecialId = special.Id, - Size = Pizza.DefaultSize, - Toppings = new List(), - }; - - ShowingConfigureDialog = true; - } - - public void CancelConfigurePizzaDialog() - { - ConfiguringPizza = null; - ShowingConfigureDialog = false; - } - - public void ConfirmConfigurePizzaDialog() - { - Order.Pizzas.Add(ConfiguringPizza); - ConfiguringPizza = null; - - ShowingConfigureDialog = false; - } - - public void RemoveConfiguredPizza(Pizza pizza) - { - Order.Pizzas.Remove(pizza); - } - - public void ResetOrder() - { - Order = new Order(); - } - } + public bool ShowingConfigureDialog { get; private set; } + + public Pizza ConfiguringPizza { get; private set; } + + public Order Order { get; private set; } = new Order(); + + public void ShowConfigurePizzaDialog(PizzaSpecial special) + { + ConfiguringPizza = new Pizza() + { + Special = special, + SpecialId = special.Id, + Size = Pizza.DefaultSize, + Toppings = new List(), + }; + + ShowingConfigureDialog = true; + } + + public void CancelConfigurePizzaDialog() + { + ConfiguringPizza = null; + ShowingConfigureDialog = false; + } + + public void ConfirmConfigurePizzaDialog() + { + Order.Pizzas.Add(ConfiguringPizza); + ConfiguringPizza = null; + + ShowingConfigureDialog = false; + } + + public void RemoveConfiguredPizza(Pizza pizza) + { + Order.Pizzas.Remove(pizza); + } + + public void ResetOrder() + { + Order = new Order(); + } + + public void ReplaceOrder(Order order) + { + Order = order; + } } diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Client/Program.cs b/save-points/05-checkout-with-validation/BlazingPizza.Client/Program.cs index e0c88943..8c6740d5 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Client/Program.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Client/Program.cs @@ -1,22 +1,10 @@ using Microsoft.AspNetCore.Components.WebAssembly.Hosting; -using Microsoft.Extensions.DependencyInjection; -using System; -using System.Net.Http; -using System.Threading.Tasks; +using BlazingPizza.Client; -namespace BlazingPizza.Client -{ - public class Program - { - public static async Task Main(string[] args) - { - var builder = WebAssemblyHostBuilder.CreateDefault(args); - builder.RootComponents.Add("#app"); +var builder = WebAssemblyHostBuilder.CreateDefault(args); +builder.RootComponents.Add("#app"); - builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); - builder.Services.AddScoped(); +builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); +builder.Services.AddScoped(); - await builder.Build().RunAsync(); - } - } -} +await builder.Build().RunAsync(); diff --git a/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 61ebf623..cb996b1b 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -2,6 +2,7 @@ $(TargetFrameworkVersion) + true diff --git a/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/LocalStorage.cs b/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/LocalStorage.cs index f36b098e..bb84f13c 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/LocalStorage.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/LocalStorage.cs @@ -1,17 +1,15 @@ using Microsoft.JSInterop; -using System.Threading.Tasks; -namespace BlazingPizza.ComponentsLibrary +namespace BlazingPizza.ComponentsLibrary; + +public static class LocalStorage { - public static class LocalStorage - { - public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) - => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); + public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) + => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); - public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object value) - => jsRuntime.InvokeVoidAsync("blazorLocalStorage.set", key, value); + public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object value) + => jsRuntime.InvokeVoidAsync("blazorLocalStorage.set", key, value); - public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key) - => jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key); - } -} + public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key) + => jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key); +} \ No newline at end of file diff --git a/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/Map/Marker.cs b/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/Map/Marker.cs index 63006067..a8e78f2a 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/Map/Marker.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/Map/Marker.cs @@ -1,13 +1,12 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Marker { - public class Marker - { - public string Description { get; set; } + public string Description { get; set; } - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } + public double Y { get; set; } - public bool ShowPopup { get; set; } - } + public bool ShowPopup { get; set; } } diff --git a/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/Map/Point.cs b/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/Map/Point.cs index 03841826..349046d4 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/Map/Point.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/Map/Point.cs @@ -1,9 +1,8 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Point { - public class Point - { - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } - } -} + public double Y { get; set; } +} \ No newline at end of file diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/BlazingPizza.Server.csproj b/save-points/05-checkout-with-validation/BlazingPizza.Server/BlazingPizza.Server.csproj index b9c74fc4..abd2317b 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -2,6 +2,7 @@ $(TargetFrameworkVersion) + true @@ -13,6 +14,7 @@ + diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/NotificationsController.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/NotificationsController.cs deleted file mode 100644 index bb3b96ff..00000000 --- a/save-points/05-checkout-with-validation/BlazingPizza.Server/NotificationsController.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("notifications")] - [ApiController] - [Authorize] - public class NotificationsController : Controller - { - private readonly PizzaStoreContext _db; - - public NotificationsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpPut("subscribe")] - public async Task Subscribe(NotificationSubscription subscription) - { - // We're storing at most one subscription per user, so delete old ones. - // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. - var userId = GetUserId(); - var oldSubscriptions = _db.NotificationSubscriptions.Where(e => e.UserId == userId); - _db.NotificationSubscriptions.RemoveRange(oldSubscriptions); - - // Store new subscription - subscription.UserId = userId; - _db.NotificationSubscriptions.Attach(subscription); - - await _db.SaveChangesAsync(); - return subscription; - } - - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } - } -} diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/OidcConfigurationController.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/OidcConfigurationController.cs index c074debf..dc75ecb3 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Server/OidcConfigurationController.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/OidcConfigurationController.cs @@ -1,26 +1,21 @@ using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class OidcConfigurationController : Controller { - public class OidcConfigurationController : Controller - { - public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) - { - ClientRequestParametersProvider = clientRequestParametersProvider; - } + public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) + { + ClientRequestParametersProvider = clientRequestParametersProvider; + } - public IClientRequestParametersProvider ClientRequestParametersProvider { get; } + public IClientRequestParametersProvider ClientRequestParametersProvider { get; } - [HttpGet("_configuration/{clientId}")] - public IActionResult GetClientRequestParameters([FromRoute]string clientId) - { - var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); - return Ok(parameters); - } - } + [HttpGet("_configuration/{clientId}")] + public IActionResult GetClientRequestParameters([FromRoute] string clientId) + { + var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); + return Ok(parameters); + } } diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/OrdersController.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/OrdersController.cs index 2b8bc99b..4cc7115e 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Server/OrdersController.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/OrdersController.cs @@ -1,114 +1,130 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; +using System.Security.Claims; +using System.Text.Json; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using WebPush; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +[Route("orders")] +[ApiController] +// [Authorize] +public class OrdersController : Controller { - [Route("orders")] - [ApiController] - // [Authorize] - public class OrdersController : Controller - { - private readonly PizzaStoreContext _db; - - public OrdersController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetOrders() - { - var orders = await _db.Orders - // .Where(o => o.UserId == GetUserId()) - .Include(o => o.DeliveryLocation) - .Include(o => o.Pizzas).ThenInclude(p => p.Special) - .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) - .OrderByDescending(o => o.CreatedTime) - .ToListAsync(); - - return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); - } - - [HttpGet("{orderId}")] - public async Task> GetOrderWithStatus(int orderId) - { - var order = await _db.Orders - .Where(o => o.OrderId == orderId) - // .Where(o => o.UserId == GetUserId()) - .Include(o => o.DeliveryLocation) - .Include(o => o.Pizzas).ThenInclude(p => p.Special) - .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) - .SingleOrDefaultAsync(); - - if (order == null) - { - return NotFound(); - } - - return OrderWithStatus.FromOrder(order); - } - - [HttpPost] - public async Task> PlaceOrder(Order order) - { - order.CreatedTime = DateTime.Now; - order.DeliveryLocation = new LatLong(51.5001, -0.1239); - // order.UserId = GetUserId(); - - // Enforce existence of Pizza.SpecialId and Topping.ToppingId - // in the database - prevent the submitter from making up - // new specials and toppings - foreach (var pizza in order.Pizzas) - { - pizza.SpecialId = pizza.Special.Id; - pizza.Special = null; - - foreach (var topping in pizza.Toppings) - { - topping.ToppingId = topping.Topping.Id; - topping.Topping = null; - } - } - - _db.Orders.Attach(order); - await _db.SaveChangesAsync(); - - // In the background, send push notifications if possible - var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); - if (subscription != null) - { - _ = TrackAndSendNotificationsAsync(order, subscription); - } - - return order.OrderId; - } - - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } - - private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription subscription) - { - // In a realistic case, some other backend process would track - // order delivery progress and send us notifications when it - // changes. Since we don't have any such process here, fake it. - await Task.Delay(OrderWithStatus.PreparationDuration); - await SendNotificationAsync(order, subscription, "Your order has been dispatched!"); - - await Task.Delay(OrderWithStatus.DeliveryDuration); - await SendNotificationAsync(order, subscription, "Your order is now delivered. Enjoy!"); - } - - private static Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) - { - // This will be implemented later - return Task.CompletedTask; - } - } + private readonly PizzaStoreContext _db; + + public OrdersController(PizzaStoreContext db) + { + _db = db; + } + + [HttpGet] + public async Task>> GetOrders() + { + var orders = await _db.Orders + .Where(o => o.UserId == GetUserId()) + .Include(o => o.DeliveryLocation) + .Include(o => o.Pizzas).ThenInclude(p => p.Special) + .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) + .OrderByDescending(o => o.CreatedTime) + .ToListAsync(); + + return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); + } + + [HttpGet("{orderId}")] + public async Task> GetOrderWithStatus(int orderId) + { + var order = await _db.Orders + .Where(o => o.OrderId == orderId) + .Where(o => o.UserId == GetUserId()) + .Include(o => o.DeliveryLocation) + .Include(o => o.Pizzas).ThenInclude(p => p.Special) + .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) + .SingleOrDefaultAsync(); + + if (order == null) + { + return NotFound(); + } + + return OrderWithStatus.FromOrder(order); + } + + [HttpPost] + public async Task> PlaceOrder(Order order) + { + order.CreatedTime = DateTime.Now; + order.DeliveryLocation = new LatLong(51.5001, -0.1239); + order.UserId = GetUserId(); + + // Enforce existence of Pizza.SpecialId and Topping.ToppingId + // in the database - prevent the submitter from making up + // new specials and toppings + foreach (var pizza in order.Pizzas) + { + pizza.SpecialId = pizza.Special.Id; + pizza.Special = null; + + foreach (var topping in pizza.Toppings) + { + topping.ToppingId = topping.Topping.Id; + topping.Topping = null; + } + } + + _db.Orders.Attach(order); + await _db.SaveChangesAsync(); + + // In the background, send push notifications if possible + var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); + if (subscription != null) + { + _ = TrackAndSendNotificationsAsync(order, subscription); + } + + return order.OrderId; + } + + private string GetUserId() + { + return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); + } + + private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription subscription) + { + // In a realistic case, some other backend process would track + // order delivery progress and send us notifications when it + // changes. Since we don't have any such process here, fake it. + await Task.Delay(OrderWithStatus.PreparationDuration); + await SendNotificationAsync(order, subscription, "Your order has been dispatched!"); + + await Task.Delay(OrderWithStatus.DeliveryDuration); + await SendNotificationAsync(order, subscription, "Your order is now delivered. Enjoy!"); + } + + private static async Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) + { + // For a real application, generate your own + var publicKey = "BLC8GOevpcpjQiLkO7JmVClQjycvTCYWm6Cq_a7wJZlstGTVZvwGFFHMYfXt6Njyvgx_GlXJeo5cSiZ1y4JOx1o"; + var privateKey = "OrubzSz3yWACscZXjFQrrtDwCKg-TGFuWhluQ2wLXDo"; + + var pushSubscription = new PushSubscription(subscription.Url, subscription.P256dh, subscription.Auth); + var vapidDetails = new VapidDetails("mailto:", publicKey, privateKey); + var webPushClient = new WebPushClient(); + try + { + var payload = JsonSerializer.Serialize(new + { + message, + url = $"myorders/{order.OrderId}", + }); + await webPushClient.SendNotificationAsync(pushSubscription, payload, vapidDetails); + } + catch (Exception ex) + { + Console.Error.WriteLine("Error sending push notification: " + ex.Message); + } + } } diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/PizzaApiExtensions.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/PizzaApiExtensions.cs new file mode 100644 index 00000000..bf6b7bde --- /dev/null +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/PizzaApiExtensions.cs @@ -0,0 +1,60 @@ +using System.Security.Claims; +using Microsoft.AspNetCore.Authorization; +using Microsoft.EntityFrameworkCore; + +namespace BlazingPizza.Server; + +public static class PizzaApiExtensions +{ + + public static WebApplication MapPizzaApi(this WebApplication app) + { + + // Subscribe to notifications + app.MapPut("/notifications/subscribe", [Authorize] async ( + HttpContext context, + PizzaStoreContext db, + NotificationSubscription subscription) => + { + + // We're storing at most one subscription per user, so delete old ones. + // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. + var userId = GetUserId(context); + var oldSubscriptions = db.NotificationSubscriptions.Where(e => e.UserId == userId); + db.NotificationSubscriptions.RemoveRange(oldSubscriptions); + + // Store new subscription + subscription.UserId = userId; + db.NotificationSubscriptions.Attach(subscription); + + await db.SaveChangesAsync(); + return Results.Ok(subscription); + + }); + + // Specials + app.MapGet("/specials", async (PizzaStoreContext db) => + { + + var specials = await db.Specials.ToListAsync(); + return Results.Ok(specials); + + }); + + // Toppings + app.MapGet("/toppings", async (PizzaStoreContext db) => + { + var toppings = await db.Toppings.OrderBy(t => t.Name).ToListAsync(); + return Results.Ok(toppings); + }); + + return app; + + } + + private static string GetUserId(HttpContext context) + { + return context.User.FindFirstValue(ClaimTypes.NameIdentifier); + } + +} \ No newline at end of file diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/PizzaStoreContext.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/PizzaStoreContext.cs index 9485bd12..9a2e17ee 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Server/PizzaStoreContext.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/PizzaStoreContext.cs @@ -3,37 +3,36 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class PizzaStoreContext : ApiAuthorizationDbContext { - public class PizzaStoreContext : ApiAuthorizationDbContext - { - public PizzaStoreContext( - DbContextOptions options, - IOptions operationalStoreOptions) : base(options, operationalStoreOptions) - { - } + public PizzaStoreContext( + DbContextOptions options, + IOptions operationalStoreOptions) : base(options, operationalStoreOptions) + { + } - public DbSet Orders { get; set; } + public DbSet Orders { get; set; } - public DbSet Pizzas { get; set; } + public DbSet Pizzas { get; set; } - public DbSet Specials { get; set; } + public DbSet Specials { get; set; } - public DbSet Toppings { get; set; } + public DbSet Toppings { get; set; } - public DbSet NotificationSubscriptions { get; set; } + public DbSet NotificationSubscriptions { get; set; } - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - base.OnModelCreating(modelBuilder); + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); - // Configuring a many-to-many special -> topping relationship that is friendly for serialization - modelBuilder.Entity().HasKey(pst => new { pst.PizzaId, pst.ToppingId }); - modelBuilder.Entity().HasOne().WithMany(ps => ps.Toppings); - modelBuilder.Entity().HasOne(pst => pst.Topping).WithMany(); + // Configuring a many-to-many special -> topping relationship that is friendly for serialization + modelBuilder.Entity().HasKey(pst => new { pst.PizzaId, pst.ToppingId }); + modelBuilder.Entity().HasOne().WithMany(ps => ps.Toppings); + modelBuilder.Entity().HasOne(pst => pst.Topping).WithMany(); - // Inline the Lat-Long pairs in Order rather than having a FK to another table - modelBuilder.Entity().OwnsOne(o => o.DeliveryLocation); - } - } -} \ No newline at end of file + // Inline the Lat-Long pairs in Order rather than having a FK to another table + modelBuilder.Entity().OwnsOne(o => o.DeliveryLocation); + } +} diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/PizzaStoreUser.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/PizzaStoreUser.cs index 171ce83d..7ab40235 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Server/PizzaStoreUser.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/PizzaStoreUser.cs @@ -1,8 +1,5 @@ using Microsoft.AspNetCore.Identity; -namespace BlazingPizza.Server -{ - public class PizzaStoreUser : IdentityUser - { - } -} \ No newline at end of file +namespace BlazingPizza.Server; + +public class PizzaStoreUser : IdentityUser { } \ No newline at end of file diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/PizzasController.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/PizzasController.cs deleted file mode 100644 index c082552c..00000000 --- a/save-points/05-checkout-with-validation/BlazingPizza.Server/PizzasController.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("pizzas")] - [ApiController] - public class PizzasController : Controller - { - private readonly PizzaStoreContext _db; - - public PizzasController(PizzaStoreContext db) - { - _db = db; - } - } -} diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/Program.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/Program.cs index 40a47641..4484d8f7 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Server/Program.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/Program.cs @@ -1,33 +1,67 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; +using Microsoft.AspNetCore.Authentication; +using Microsoft.EntityFrameworkCore; +using BlazingPizza.Server; -namespace BlazingPizza.Server +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddControllersWithViews() + .AddJsonOptions(options => { + options.JsonSerializerOptions.AddContext(); + }); +builder.Services.AddRazorPages(); + +builder.Services.AddDbContext(options => + options.UseSqlite("Data Source=pizza.db") + .UseModel(BlazingPizza.Server.Models.PizzaStoreContextModel.Instance)); + +builder.Services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) + .AddEntityFrameworkStores(); + +builder.Services.AddIdentityServer() + .AddApiAuthorization(); + +builder.Services.AddAuthentication() + .AddIdentityServerJwt(); + +var app = builder.Build(); + +// Initialize the database +var scopeFactory = app.Services.GetRequiredService(); +using (var scope = scopeFactory.CreateScope()) +{ + var db = scope.ServiceProvider.GetRequiredService(); + if (db.Database.EnsureCreated()) + { + SeedData.Initialize(db); + } +} + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseWebAssemblyDebugging(); +} +else { - public class Program - { - public static void Main(string[] args) - { - var host = CreateHostBuilder(args).Build(); - - // Initialize the database - var scopeFactory = host.Services.GetRequiredService(); - using (var scope = scopeFactory.CreateScope()) - { - var db = scope.ServiceProvider.GetRequiredService(); - if (db.Database.EnsureCreated()) - { - SeedData.Initialize(db); - } - } - - host.Run(); - } - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); - } + app.UseExceptionHandler("/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); } + +app.UseHttpsRedirection(); +app.UseBlazorFrameworkFiles(); +app.UseStaticFiles(); + +app.UseRouting(); + +app.UseAuthentication(); +app.UseIdentityServer(); +app.UseAuthorization(); + +app.MapPizzaApi(); + +app.MapRazorPages(); +app.MapControllers(); +app.MapFallbackToFile("index.html"); + +app.Run(); \ No newline at end of file diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/SeedData.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/SeedData.cs index 7c86a5b2..a1e47973 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Server/SeedData.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/SeedData.cs @@ -1,193 +1,192 @@ -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public static class SeedData { - public static class SeedData - { - public static void Initialize(PizzaStoreContext db) - { - var toppings = new Topping[] - { - new Topping() - { - Name = "Extra cheese", - Price = 2.50m, - }, - new Topping() - { - Name = "American bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "British bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "Canadian bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "Tea and crumpets", - Price = 5.00m - }, - new Topping() - { - Name = "Fresh-baked scones", - Price = 4.50m, - }, - new Topping() - { - Name = "Bell peppers", - Price = 1.00m, - }, - new Topping() - { - Name = "Onions", - Price = 1.00m, - }, - new Topping() - { - Name = "Mushrooms", - Price = 1.00m, - }, - new Topping() - { - Name = "Pepperoni", - Price = 1.00m, - }, - new Topping() - { - Name = "Duck sausage", - Price = 3.20m, - }, - new Topping() - { - Name = "Venison meatballs", - Price = 2.50m, - }, - new Topping() - { - Name = "Served on a silver platter", - Price = 250.99m, - }, - new Topping() - { - Name = "Lobster on top", - Price = 64.50m, - }, - new Topping() - { - Name = "Sturgeon caviar", - Price = 101.75m, - }, - new Topping() - { - Name = "Artichoke hearts", - Price = 3.40m, - }, - new Topping() - { - Name = "Fresh tomatoes", - Price = 1.50m, - }, - new Topping() - { - Name = "Basil", - Price = 1.50m, - }, - new Topping() - { - Name = "Steak (medium-rare)", - Price = 8.50m, - }, - new Topping() - { - Name = "Blazing hot peppers", - Price = 4.20m, - }, - new Topping() - { - Name = "Buffalo chicken", - Price = 5.00m, - }, - new Topping() - { - Name = "Blue cheese", - Price = 2.50m, - }, - }; + public static void Initialize(PizzaStoreContext db) + { + var toppings = new Topping[] + { + new Topping() + { + Name = "Extra cheese", + Price = 2.50m, + }, + new Topping() + { + Name = "American bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "British bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "Canadian bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "Tea and crumpets", + Price = 5.00m + }, + new Topping() + { + Name = "Fresh-baked scones", + Price = 4.50m, + }, + new Topping() + { + Name = "Bell peppers", + Price = 1.00m, + }, + new Topping() + { + Name = "Onions", + Price = 1.00m, + }, + new Topping() + { + Name = "Mushrooms", + Price = 1.00m, + }, + new Topping() + { + Name = "Pepperoni", + Price = 1.00m, + }, + new Topping() + { + Name = "Duck sausage", + Price = 3.20m, + }, + new Topping() + { + Name = "Venison meatballs", + Price = 2.50m, + }, + new Topping() + { + Name = "Served on a silver platter", + Price = 250.99m, + }, + new Topping() + { + Name = "Lobster on top", + Price = 64.50m, + }, + new Topping() + { + Name = "Sturgeon caviar", + Price = 101.75m, + }, + new Topping() + { + Name = "Artichoke hearts", + Price = 3.40m, + }, + new Topping() + { + Name = "Fresh tomatoes", + Price = 1.50m, + }, + new Topping() + { + Name = "Basil", + Price = 1.50m, + }, + new Topping() + { + Name = "Steak (medium-rare)", + Price = 8.50m, + }, + new Topping() + { + Name = "Blazing hot peppers", + Price = 4.20m, + }, + new Topping() + { + Name = "Buffalo chicken", + Price = 5.00m, + }, + new Topping() + { + Name = "Blue cheese", + Price = 2.50m, + }, + }; - var specials = new PizzaSpecial[] - { - new PizzaSpecial() - { - Name = "Basic Cheese Pizza", - Description = "It's cheesy and delicious. Why wouldn't you want one?", - BasePrice = 9.99m, - ImageUrl = "img/pizzas/cheese.jpg", - }, - new PizzaSpecial() - { - Id = 2, - Name = "The Baconatorizor", - Description = "It has EVERY kind of bacon", - BasePrice = 11.99m, - ImageUrl = "img/pizzas/bacon.jpg", - }, - new PizzaSpecial() - { - Id = 3, - Name = "Classic pepperoni", - Description = "It's the pizza you grew up with, but Blazing hot!", - BasePrice = 10.50m, - ImageUrl = "img/pizzas/pepperoni.jpg", - }, - new PizzaSpecial() - { - Id = 4, - Name = "Buffalo chicken", - Description = "Spicy chicken, hot sauce and bleu cheese, guaranteed to warm you up", - BasePrice = 12.75m, - ImageUrl = "img/pizzas/meaty.jpg", - }, - new PizzaSpecial() - { - Id = 5, - Name = "Mushroom Lovers", - Description = "It has mushrooms. Isn't that obvious?", - BasePrice = 11.00m, - ImageUrl = "img/pizzas/mushroom.jpg", - }, - new PizzaSpecial() - { - Id = 6, - Name = "The Brit", - Description = "When in London...", - BasePrice = 10.25m, - ImageUrl = "img/pizzas/brit.jpg", - }, - new PizzaSpecial() - { - Id = 7, - Name = "Veggie Delight", - Description = "It's like salad, but on a pizza", - BasePrice = 11.50m, - ImageUrl = "img/pizzas/salad.jpg", - }, - new PizzaSpecial() - { - Id = 8, - Name = "Margherita", - Description = "Traditional Italian pizza with tomatoes and basil", - BasePrice = 9.99m, - ImageUrl = "img/pizzas/margherita.jpg", - }, - }; + var specials = new PizzaSpecial[] + { + new PizzaSpecial() + { + Name = "Basic Cheese Pizza", + Description = "It's cheesy and delicious. Why wouldn't you want one?", + BasePrice = 9.99m, + ImageUrl = "img/pizzas/cheese.jpg", + }, + new PizzaSpecial() + { + Id = 2, + Name = "The Baconatorizor", + Description = "It has EVERY kind of bacon", + BasePrice = 11.99m, + ImageUrl = "img/pizzas/bacon.jpg", + }, + new PizzaSpecial() + { + Id = 3, + Name = "Classic pepperoni", + Description = "It's the pizza you grew up with, but Blazing hot!", + BasePrice = 10.50m, + ImageUrl = "img/pizzas/pepperoni.jpg", + }, + new PizzaSpecial() + { + Id = 4, + Name = "Buffalo chicken", + Description = "Spicy chicken, hot sauce and bleu cheese, guaranteed to warm you up", + BasePrice = 12.75m, + ImageUrl = "img/pizzas/meaty.jpg", + }, + new PizzaSpecial() + { + Id = 5, + Name = "Mushroom Lovers", + Description = "It has mushrooms. Isn't that obvious?", + BasePrice = 11.00m, + ImageUrl = "img/pizzas/mushroom.jpg", + }, + new PizzaSpecial() + { + Id = 6, + Name = "The Brit", + Description = "When in London...", + BasePrice = 10.25m, + ImageUrl = "img/pizzas/brit.jpg", + }, + new PizzaSpecial() + { + Id = 7, + Name = "Veggie Delight", + Description = "It's like salad, but on a pizza", + BasePrice = 11.50m, + ImageUrl = "img/pizzas/salad.jpg", + }, + new PizzaSpecial() + { + Id = 8, + Name = "Margherita", + Description = "Traditional Italian pizza with tomatoes and basil", + BasePrice = 9.99m, + ImageUrl = "img/pizzas/margherita.jpg", + }, + }; - db.Toppings.AddRange(toppings); - db.Specials.AddRange(specials); - db.SaveChanges(); - } - } -} + db.Toppings.AddRange(toppings); + db.Specials.AddRange(specials); + db.SaveChanges(); + } +} \ No newline at end of file diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/SpecialsController.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/SpecialsController.cs deleted file mode 100644 index a176844c..00000000 --- a/save-points/05-checkout-with-validation/BlazingPizza.Server/SpecialsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("specials")] - [ApiController] - public class SpecialsController : Controller - { - private readonly PizzaStoreContext _db; - - public SpecialsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetSpecials() - { - return (await _db.Specials.ToListAsync()).OrderByDescending(s => s.BasePrice).ToList(); - } - } -} diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/Startup.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/Startup.cs deleted file mode 100644 index ed3fca06..00000000 --- a/save-points/05-checkout-with-validation/BlazingPizza.Server/Startup.cs +++ /dev/null @@ -1,70 +0,0 @@ -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace BlazingPizza.Server -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - public void ConfigureServices(IServiceCollection services) - { - services.AddControllersWithViews(); - services.AddRazorPages(); - - services.AddDbContext(options => - options.UseSqlite("Data Source=pizza.db")); - - services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) - .AddEntityFrameworkStores(); - - services.AddIdentityServer() - .AddApiAuthorization(); - - services.AddAuthentication() - .AddIdentityServerJwt(); - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - app.UseWebAssemblyDebugging(); - } - else - { - app.UseExceptionHandler("/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); - } - - app.UseHttpsRedirection(); - app.UseBlazorFrameworkFiles(); - app.UseStaticFiles(); - - app.UseRouting(); - - app.UseAuthentication(); - app.UseIdentityServer(); - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - endpoints.MapRazorPages(); - endpoints.MapFallbackToFile("index.html"); - }); - } - } -} \ No newline at end of file diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/ToppingsController.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/ToppingsController.cs deleted file mode 100644 index 6a677639..00000000 --- a/save-points/05-checkout-with-validation/BlazingPizza.Server/ToppingsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("toppings")] - [ApiController] - public class ToppingsController : Controller - { - private readonly PizzaStoreContext _db; - - public ToppingsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetToppings() - { - return await _db.Toppings.OrderBy(t => t.Name).ToListAsync(); - } - } -} diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Shared/Address.cs b/save-points/05-checkout-with-validation/BlazingPizza.Shared/Address.cs index d76bc52a..79be9c5b 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Shared/Address.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Shared/Address.cs @@ -1,27 +1,24 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class Address { - public class Address - { - public int Id { get; set; } + public int Id { get; set; } - [Required, MaxLength(100)] - public string Name { get; set; } + [Required, MaxLength(100)] + public string Name { get; set; } - [Required, MaxLength(100)] - public string Line1 { get; set; } + [Required, MaxLength(100)] + public string Line1 { get; set; } - [MaxLength(100)] - public string Line2 { get; set; } + [MaxLength(100)] + public string Line2 { get; set; } - [Required, MaxLength(50)] - public string City { get; set; } + [Required, MaxLength(50)] + public string City { get; set; } - [Required, MaxLength(20)] - public string Region { get; set; } + [Required, MaxLength(20)] + public string Region { get; set; } - [Required, MaxLength(20)] - public string PostalCode { get; set; } - } + [Required, MaxLength(20)] + public string PostalCode { get; set; } } diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/save-points/05-checkout-with-validation/BlazingPizza.Shared/BlazingPizza.Shared.csproj index f7b7dd02..fb17e53b 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/save-points/05-checkout-with-validation/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -3,8 +3,13 @@ $(TargetFrameworkVersion) BlazingPizza + true + + + + diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Shared/LatLong.cs b/save-points/05-checkout-with-validation/BlazingPizza.Shared/LatLong.cs index 9b8c3811..14a94c26 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Shared/LatLong.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Shared/LatLong.cs @@ -1,27 +1,26 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class LatLong { - public class LatLong - { - public LatLong() - { - } + public LatLong() + { + } - public LatLong(double latitude, double longitude) : this() - { - Latitude = latitude; - Longitude = longitude; - } + public LatLong(double latitude, double longitude) : this() + { + Latitude = latitude; + Longitude = longitude; + } - public double Latitude { get; set; } + public double Latitude { get; set; } - public double Longitude { get; set; } + public double Longitude { get; set; } - public static LatLong Interpolate(LatLong start, LatLong end, double proportion) - { - // The Earth is flat, right? So no need for spherical interpolation. - return new LatLong( - start.Latitude + (end.Latitude - start.Latitude) * proportion, - start.Longitude + (end.Longitude - start.Longitude) * proportion); - } - } -} + public static LatLong Interpolate(LatLong start, LatLong end, double proportion) + { + // The Earth is flat, right? So no need for spherical interpolation. + return new LatLong( + start.Latitude + (end.Latitude - start.Latitude) * proportion, + start.Longitude + (end.Longitude - start.Longitude) * proportion); + } +} \ No newline at end of file diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Shared/NotificationSubscription.cs b/save-points/05-checkout-with-validation/BlazingPizza.Shared/NotificationSubscription.cs index 04259c2f..9109ff57 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Shared/NotificationSubscription.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Shared/NotificationSubscription.cs @@ -1,17 +1,14 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class NotificationSubscription { - public class NotificationSubscription - { - public int NotificationSubscriptionId { get; set; } + public int NotificationSubscriptionId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public string Url { get; set; } + public string Url { get; set; } - public string P256dh { get; set; } + public string P256dh { get; set; } - public string Auth { get; set; } - } + public string Auth { get; set; } } diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Shared/Order.cs b/save-points/05-checkout-with-validation/BlazingPizza.Shared/Order.cs index fb003bd6..aca04ca1 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Shared/Order.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Shared/Order.cs @@ -1,25 +1,32 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +public class Order { - public class Order - { - public int OrderId { get; set; } + public int OrderId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public DateTime CreatedTime { get; set; } + public DateTime CreatedTime { get; set; } - public Address DeliveryAddress { get; set; } = new Address(); + public Address DeliveryAddress { get; set; } = new Address(); - public LatLong DeliveryLocation { get; set; } + public LatLong DeliveryLocation { get; set; } - public List Pizzas { get; set; } = new List(); + public List Pizzas { get; set; } = new List(); - public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); + public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); - public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); - } + public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Default, PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] +[JsonSerializable(typeof(Order))] +[JsonSerializable(typeof(OrderWithStatus))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Pizza))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Topping))] +public partial class OrderContext : JsonSerializerContext {} \ No newline at end of file diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Shared/OrderWithStatus.cs b/save-points/05-checkout-with-validation/BlazingPizza.Shared/OrderWithStatus.cs index 021de78c..f5f153b6 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Shared/OrderWithStatus.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Shared/OrderWithStatus.cs @@ -1,79 +1,78 @@ -using BlazingPizza.ComponentsLibrary.Map; -using System; -using System.Collections.Generic; +using System.Text.Json.Serialization; +using BlazingPizza.ComponentsLibrary.Map; -namespace BlazingPizza + +namespace BlazingPizza; + +public class OrderWithStatus { - public class OrderWithStatus - { - public readonly static TimeSpan PreparationDuration = TimeSpan.FromSeconds(10); - public readonly static TimeSpan DeliveryDuration = TimeSpan.FromMinutes(1); // Unrealistic, but more interesting to watch + public readonly static TimeSpan PreparationDuration = TimeSpan.FromSeconds(10); + public readonly static TimeSpan DeliveryDuration = TimeSpan.FromMinutes(1); // Unrealistic, but more interesting to watch - public Order Order { get; set; } + public Order Order { get; set; } - public string StatusText { get; set; } + public string StatusText { get; set; } - public bool IsDelivered => StatusText == "Delivered"; + public bool IsDelivered => StatusText == "Delivered"; - public List MapMarkers { get; set; } + public List MapMarkers { get; set; } - public static OrderWithStatus FromOrder(Order order) - { - // To simulate a real backend process, we fake status updates based on the amount - // of time since the order was placed - string statusText; - List mapMarkers; - var dispatchTime = order.CreatedTime.Add(PreparationDuration); + public static OrderWithStatus FromOrder(Order order) + { + // To simulate a real backend process, we fake status updates based on the amount + // of time since the order was placed + string statusText; + List mapMarkers; + var dispatchTime = order.CreatedTime.Add(PreparationDuration); - if (DateTime.Now < dispatchTime) - { - statusText = "Preparing"; - mapMarkers = new List - { - ToMapMarker("You", order.DeliveryLocation, showPopup: true) - }; - } - else if (DateTime.Now < dispatchTime + DeliveryDuration) - { - statusText = "Out for delivery"; + if (DateTime.Now < dispatchTime) + { + statusText = "Preparing"; + mapMarkers = new List + { + ToMapMarker("You", order.DeliveryLocation, showPopup: true) + }; + } + else if (DateTime.Now < dispatchTime + DeliveryDuration) + { + statusText = "Out for delivery"; - var startPosition = ComputeStartPosition(order); - var proportionOfDeliveryCompleted = Math.Min(1, (DateTime.Now - dispatchTime).TotalMilliseconds / DeliveryDuration.TotalMilliseconds); - var driverPosition = LatLong.Interpolate(startPosition, order.DeliveryLocation, proportionOfDeliveryCompleted); - mapMarkers = new List - { - ToMapMarker("You", order.DeliveryLocation), - ToMapMarker("Driver", driverPosition, showPopup: true), - }; - } - else - { - statusText = "Delivered"; - mapMarkers = new List - { - ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), - }; - } + var startPosition = ComputeStartPosition(order); + var proportionOfDeliveryCompleted = Math.Min(1, (DateTime.Now - dispatchTime).TotalMilliseconds / DeliveryDuration.TotalMilliseconds); + var driverPosition = LatLong.Interpolate(startPosition, order.DeliveryLocation, proportionOfDeliveryCompleted); + mapMarkers = new List + { + ToMapMarker("You", order.DeliveryLocation), + ToMapMarker("Driver", driverPosition, showPopup: true), + }; + } + else + { + statusText = "Delivered"; + mapMarkers = new List + { + ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), + }; + } - return new OrderWithStatus - { - Order = order, - StatusText = statusText, - MapMarkers = mapMarkers, - }; - } + return new OrderWithStatus + { + Order = order, + StatusText = statusText, + MapMarkers = mapMarkers, + }; + } - private static LatLong ComputeStartPosition(Order order) - { - // Random but deterministic based on order ID - var rng = new Random(order.OrderId); - var distance = 0.01 + rng.NextDouble() * 0.02; - var angle = rng.NextDouble() * Math.PI * 2; - var offset = (distance * Math.Cos(angle), distance * Math.Sin(angle)); - return new LatLong(order.DeliveryLocation.Latitude + offset.Item1, order.DeliveryLocation.Longitude + offset.Item2); - } + private static LatLong ComputeStartPosition(Order order) + { + // Random but deterministic based on order ID + var rng = new Random(order.OrderId); + var distance = 0.01 + rng.NextDouble() * 0.02; + var angle = rng.NextDouble() * Math.PI * 2; + var offset = (distance * Math.Cos(angle), distance * Math.Sin(angle)); + return new LatLong(order.DeliveryLocation.Latitude + offset.Item1, order.DeliveryLocation.Longitude + offset.Item2); + } - static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) - => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; - } -} + static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) + => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; +} \ No newline at end of file diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Shared/Pizza.cs b/save-points/05-checkout-with-validation/BlazingPizza.Shared/Pizza.cs index ec1108a9..459298f4 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Shared/Pizza.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Shared/Pizza.cs @@ -1,42 +1,44 @@ -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// /// Represents a customized pizza as part of an order +/// +public class Pizza { - /// - /// Represents a customized pizza as part of an order - /// - public class Pizza - { - public const int DefaultSize = 12; - public const int MinimumSize = 9; - public const int MaximumSize = 17; + public const int DefaultSize = 12; + public const int MinimumSize = 9; + public const int MaximumSize = 17; - public int Id { get; set; } + public int Id { get; set; } - public int OrderId { get; set; } + public int OrderId { get; set; } - public PizzaSpecial Special { get; set; } + public PizzaSpecial Special { get; set; } - public int SpecialId { get; set; } + public int SpecialId { get; set; } - public int Size { get; set; } + public int Size { get; set; } - public List Toppings { get; set; } + public List Toppings { get; set; } - public decimal GetBasePrice() - { - return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; - } + public decimal GetBasePrice() + { + return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; + } - public decimal GetTotalPrice() - { - return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); - } + public decimal GetTotalPrice() + { + return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); + } - public string GetFormattedTotalPrice() - { - return GetTotalPrice().ToString("0.00"); - } - } + public string GetFormattedTotalPrice() + { + return GetTotalPrice().ToString("0.00"); + } } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Serialization)] +[JsonSerializable(typeof(Pizza))] +public partial class PizzaContext : JsonSerializerContext {} \ No newline at end of file diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Shared/PizzaSpecial.cs b/save-points/05-checkout-with-validation/BlazingPizza.Shared/PizzaSpecial.cs index 2f2b3383..9653300c 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Shared/PizzaSpecial.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Shared/PizzaSpecial.cs @@ -1,20 +1,19 @@ -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// Represents a pre-configured template for a pizza a user can order +/// +public class PizzaSpecial { - /// - /// Represents a pre-configured template for a pizza a user can order - /// - public class PizzaSpecial - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal BasePrice { get; set; } + public decimal BasePrice { get; set; } - public string Description { get; set; } + public string Description { get; set; } - public string ImageUrl { get; set; } + public string ImageUrl { get; set; } - public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); - } -} + public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); +} \ No newline at end of file diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Shared/PizzaTopping.cs b/save-points/05-checkout-with-validation/BlazingPizza.Shared/PizzaTopping.cs index f5a6c1ac..0a711647 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Shared/PizzaTopping.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Shared/PizzaTopping.cs @@ -1,11 +1,11 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class PizzaTopping { - public class PizzaTopping - { - public Topping Topping { get; set; } + public Topping Topping { get; set; } + + public int ToppingId { get; set; } - public int ToppingId { get; set; } - - public int PizzaId { get; set; } - } -} + public int PizzaId { get; set; } + +} \ No newline at end of file diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Shared/Topping.cs b/save-points/05-checkout-with-validation/BlazingPizza.Shared/Topping.cs index 61bdeb92..376c311a 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Shared/Topping.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Shared/Topping.cs @@ -1,13 +1,13 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class Topping { - public class Topping - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal Price { get; set; } + public decimal Price { get; set; } - public string GetFormattedPrice() => Price.ToString("0.00"); - } -} + public string GetFormattedPrice() => Price.ToString("0.00"); + +} \ No newline at end of file diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Shared/UserInfo.cs b/save-points/05-checkout-with-validation/BlazingPizza.Shared/UserInfo.cs index 4996ef80..362f8f8e 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Shared/UserInfo.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Shared/UserInfo.cs @@ -1,9 +1,9 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class UserInfo { - public class UserInfo - { - public bool IsAuthenticated { get; set; } + public bool IsAuthenticated { get; set; } - public string Name { get; set; } - } -} + public string Name { get; set; } + +} \ No newline at end of file diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Client/BlazingPizza.Client.csproj b/save-points/06-authentication-and-authorization/BlazingPizza.Client/BlazingPizza.Client.csproj index 663677a1..44802d79 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -2,16 +2,19 @@ $(TargetFrameworkVersion) + true + - + + diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Client/OrderState.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Client/OrderState.cs index 5265ae39..7309fbad 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Client/OrderState.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Client/OrderState.cs @@ -1,55 +1,52 @@ -using System.Collections.Generic; +namespace BlazingPizza.Client; -namespace BlazingPizza.Client +public class OrderState { - public class OrderState - { - public bool ShowingConfigureDialog { get; private set; } - - public Pizza ConfiguringPizza { get; private set; } - - public Order Order { get; private set; } = new Order(); - - public void ShowConfigurePizzaDialog(PizzaSpecial special) - { - ConfiguringPizza = new Pizza() - { - Special = special, - SpecialId = special.Id, - Size = Pizza.DefaultSize, - Toppings = new List(), - }; - - ShowingConfigureDialog = true; - } - - public void CancelConfigurePizzaDialog() - { - ConfiguringPizza = null; - ShowingConfigureDialog = false; - } - - public void ConfirmConfigurePizzaDialog() - { - Order.Pizzas.Add(ConfiguringPizza); - ConfiguringPizza = null; - - ShowingConfigureDialog = false; - } - - public void RemoveConfiguredPizza(Pizza pizza) - { - Order.Pizzas.Remove(pizza); - } - - public void ResetOrder() - { - Order = new Order(); - } - - public void ReplaceOrder(Order order) - { - Order = order; - } - } + public bool ShowingConfigureDialog { get; private set; } + + public Pizza ConfiguringPizza { get; private set; } + + public Order Order { get; private set; } = new Order(); + + public void ShowConfigurePizzaDialog(PizzaSpecial special) + { + ConfiguringPizza = new Pizza() + { + Special = special, + SpecialId = special.Id, + Size = Pizza.DefaultSize, + Toppings = new List(), + }; + + ShowingConfigureDialog = true; + } + + public void CancelConfigurePizzaDialog() + { + ConfiguringPizza = null; + ShowingConfigureDialog = false; + } + + public void ConfirmConfigurePizzaDialog() + { + Order.Pizzas.Add(ConfiguringPizza); + ConfiguringPizza = null; + + ShowingConfigureDialog = false; + } + + public void RemoveConfiguredPizza(Pizza pizza) + { + Order.Pizzas.Remove(pizza); + } + + public void ResetOrder() + { + Order = new Order(); + } + + public void ReplaceOrder(Order order) + { + Order = order; + } } diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Client/OrdersClient.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Client/OrdersClient.cs index 0f800e6f..d90979ae 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Client/OrdersClient.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Client/OrdersClient.cs @@ -1,35 +1,30 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Net.Http.Json; -using System.Threading.Tasks; - -namespace BlazingPizza.Client +using System.Net.Http.Json; + +namespace BlazingPizza.Client; + +public class OrdersClient { - public class OrdersClient - { - private readonly HttpClient httpClient; + private readonly HttpClient httpClient; + + public OrdersClient(HttpClient httpClient) + { + this.httpClient = httpClient; + } - public OrdersClient(HttpClient httpClient) - { - this.httpClient = httpClient; - } + public async Task> GetOrders() => + await httpClient.GetFromJsonAsync("orders", OrderContext.Default.ListOrderWithStatus); - public async Task> GetOrders() => - await httpClient.GetFromJsonAsync>("orders"); + public async Task GetOrder(int orderId) => + await httpClient.GetFromJsonAsync($"orders/{orderId}", OrderContext.Default.OrderWithStatus); - public async Task GetOrder(int orderId) => - await httpClient.GetFromJsonAsync($"orders/{orderId}"); + public async Task PlaceOrder(Order order) + { + var response = await httpClient.PostAsJsonAsync("orders", order, OrderContext.Default.Order); + response.EnsureSuccessStatusCode(); + var orderId = await response.Content.ReadFromJsonAsync(); + return orderId; + } - public async Task PlaceOrder(Order order) - { - var response = await httpClient.PostAsJsonAsync("orders", order); - response.EnsureSuccessStatusCode(); - var orderId = await response.Content.ReadFromJsonAsync(); - return orderId; - } - } -} \ No newline at end of file +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Client/PizzaAuthenticationState.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Client/PizzaAuthenticationState.cs index 3f295928..f5bfef65 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Client/PizzaAuthenticationState.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Client/PizzaAuthenticationState.cs @@ -1,9 +1,8 @@ using Microsoft.AspNetCore.Components.WebAssembly.Authentication; -namespace BlazingPizza.Client +namespace BlazingPizza.Client; + +public class PizzaAuthenticationState : RemoteAuthenticationState { - public class PizzaAuthenticationState : RemoteAuthenticationState - { - public Order Order { get; set; } - } + public Order Order { get; set; } } diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Client/Program.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Client/Program.cs index afeee128..41eedccb 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Client/Program.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Client/Program.cs @@ -1,31 +1,20 @@ using Microsoft.AspNetCore.Components.WebAssembly.Authentication; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; using Microsoft.Extensions.DependencyInjection; -using System; -using System.Net.Http; -using System.Threading.Tasks; +using BlazingPizza.Client; -namespace BlazingPizza.Client -{ - public class Program - { - public static async Task Main(string[] args) - { - var builder = WebAssemblyHostBuilder.CreateDefault(args); - builder.RootComponents.Add("#app"); +var builder = WebAssemblyHostBuilder.CreateDefault(args); +builder.RootComponents.Add("#app"); - builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); - builder.Services.AddHttpClient(client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)) - .AddHttpMessageHandler(); - builder.Services.AddScoped(); +builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); +builder.Services.AddHttpClient(client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)) + .AddHttpMessageHandler(); +builder.Services.AddScoped(); - // Add auth services - builder.Services.AddApiAuthorization(options => - { - options.AuthenticationPaths.LogOutSucceededPath = ""; - }); +// Add auth services +builder.Services.AddApiAuthorization(options => +{ + options.AuthenticationPaths.LogOutSucceededPath = ""; +}); - await builder.Build().RunAsync(); - } - } -} +await builder.Build().RunAsync(); diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 61ebf623..cb996b1b 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -2,6 +2,7 @@ $(TargetFrameworkVersion) + true diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/LocalStorage.cs b/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/LocalStorage.cs index f36b098e..bb84f13c 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/LocalStorage.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/LocalStorage.cs @@ -1,17 +1,15 @@ using Microsoft.JSInterop; -using System.Threading.Tasks; -namespace BlazingPizza.ComponentsLibrary +namespace BlazingPizza.ComponentsLibrary; + +public static class LocalStorage { - public static class LocalStorage - { - public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) - => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); + public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) + => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); - public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object value) - => jsRuntime.InvokeVoidAsync("blazorLocalStorage.set", key, value); + public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object value) + => jsRuntime.InvokeVoidAsync("blazorLocalStorage.set", key, value); - public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key) - => jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key); - } -} + public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key) + => jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key); +} \ No newline at end of file diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/Map/Marker.cs b/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/Map/Marker.cs index 63006067..a8e78f2a 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/Map/Marker.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/Map/Marker.cs @@ -1,13 +1,12 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Marker { - public class Marker - { - public string Description { get; set; } + public string Description { get; set; } - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } + public double Y { get; set; } - public bool ShowPopup { get; set; } - } + public bool ShowPopup { get; set; } } diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/Map/Point.cs b/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/Map/Point.cs index 03841826..349046d4 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/Map/Point.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/Map/Point.cs @@ -1,9 +1,8 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Point { - public class Point - { - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } - } -} + public double Y { get; set; } +} \ No newline at end of file diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/AddressEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/AddressEntityType.cs new file mode 100644 index 00000000..82db81b6 --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/AddressEntityType.cs @@ -0,0 +1,92 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class AddressEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Address", + typeof(Address), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Address).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var city = runtimeEntityType.AddProperty( + "City", + typeof(string), + propertyInfo: typeof(Address).GetProperty("City", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var line1 = runtimeEntityType.AddProperty( + "Line1", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line1", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var line2 = runtimeEntityType.AddProperty( + "Line2", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line2", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var postalCode = runtimeEntityType.AddProperty( + "PostalCode", + typeof(string), + propertyInfo: typeof(Address).GetProperty("PostalCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var region = runtimeEntityType.AddProperty( + "Region", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Region", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Address"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs new file mode 100644 index 00000000..1dd4563b --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs @@ -0,0 +1,114 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class DeviceFlowCodesEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.DeviceFlowCodes", + typeof(DeviceFlowCodes), + baseEntityType); + + var userCode = runtimeEntityType.AddProperty( + "UserCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("UserCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var deviceCode = runtimeEntityType.AddProperty( + "DeviceCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("DeviceCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var key = runtimeEntityType.AddKey( + new[] { userCode }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deviceCode }, + unique: true); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "DeviceCodes"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs new file mode 100644 index 00000000..8946b261 --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRoleClaim", + typeof(IdentityRoleClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoleClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityRoleEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityRoleEntityType.cs new file mode 100644 index 00000000..2f1fec2b --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityRoleEntityType.cs @@ -0,0 +1,78 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRole", + typeof(IdentityRole), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedName = runtimeEntityType.AddProperty( + "NormalizedName", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("NormalizedName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedName }, + unique: true); + index.AddAnnotation("Relational:Name", "RoleNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs new file mode 100644 index 00000000..55418a1e --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserClaim", + typeof(IdentityUserClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityUserClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs new file mode 100644 index 00000000..3ca029bd --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserLoginstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserLogin", + typeof(IdentityUserLogin), + baseEntityType); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerKey = runtimeEntityType.AddProperty( + "ProviderKey", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderKey", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerDisplayName = runtimeEntityType.AddProperty( + "ProviderDisplayName", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderDisplayName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { loginProvider, providerKey }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserLogins"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs new file mode 100644 index 00000000..70078d7a --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs @@ -0,0 +1,82 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserRolestringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserRole", + typeof(IdentityUserRole), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { userId, roleId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs new file mode 100644 index 00000000..93ba6d31 --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs @@ -0,0 +1,84 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserTokenstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserToken", + typeof(IdentityUserToken), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var value = runtimeEntityType.AddProperty( + "Value", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Value", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { userId, loginProvider, name }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserTokens"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/KeyEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/KeyEntityType.cs new file mode 100644 index 00000000..f6c6b4c7 --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/KeyEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class KeyEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.Key", + typeof(Key), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var algorithm = runtimeEntityType.AddProperty( + "Algorithm", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Algorithm", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var created = runtimeEntityType.AddProperty( + "Created", + typeof(DateTime), + propertyInfo: typeof(Key).GetProperty("Created", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var dataProtected = runtimeEntityType.AddProperty( + "DataProtected", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("DataProtected", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var isX509Certificate = runtimeEntityType.AddProperty( + "IsX509Certificate", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("IsX509Certificate", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var use = runtimeEntityType.AddProperty( + "Use", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Use", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var version = runtimeEntityType.AddProperty( + "Version", + typeof(int), + propertyInfo: typeof(Key).GetProperty("Version", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { use }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Keys"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/LatLongEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/LatLongEntityType.cs new file mode 100644 index 00000000..3fd254bd --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/LatLongEntityType.cs @@ -0,0 +1,80 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class LatLongEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.LatLong", + typeof(LatLong), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var latitude = runtimeEntityType.AddProperty( + "Latitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Latitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var longitude = runtimeEntityType.AddProperty( + "Longitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Longitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + unique: true, + required: true, + ownership: true); + + var deliveryLocation = principalEntityType.AddNavigation("DeliveryLocation", + runtimeForeignKey, + onDependent: false, + typeof(LatLong), + propertyInfo: typeof(Order).GetProperty("DeliveryLocation", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + eagerLoaded: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs new file mode 100644 index 00000000..db236e4c --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs @@ -0,0 +1,77 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class NotificationSubscriptionEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.NotificationSubscription", + typeof(NotificationSubscription), + baseEntityType); + + var notificationSubscriptionId = runtimeEntityType.AddProperty( + "NotificationSubscriptionId", + typeof(int), + propertyInfo: typeof(NotificationSubscription).GetProperty("NotificationSubscriptionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var auth = runtimeEntityType.AddProperty( + "Auth", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Auth", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var p256dh = runtimeEntityType.AddProperty( + "P256dh", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("P256dh", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var url = runtimeEntityType.AddProperty( + "Url", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Url", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { notificationSubscriptionId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "NotificationSubscriptions"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/OrderEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/OrderEntityType.cs new file mode 100644 index 00000000..9d9ec6fd --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/OrderEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class OrderEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Order", + typeof(Order), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Order).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var createdTime = runtimeEntityType.AddProperty( + "CreatedTime", + typeof(DateTime), + propertyInfo: typeof(Order).GetProperty("CreatedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var deliveryAddressId = runtimeEntityType.AddProperty( + "DeliveryAddressId", + typeof(int?), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(Order).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deliveryAddressId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("DeliveryAddressId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType); + + var deliveryAddress = declaringEntityType.AddNavigation("DeliveryAddress", + runtimeForeignKey, + onDependent: true, + typeof(Address), + propertyInfo: typeof(Order).GetProperty("DeliveryAddress", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PersistedGrantEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PersistedGrantEntityType.cs new file mode 100644 index 00000000..842d53a5 --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PersistedGrantEntityType.cs @@ -0,0 +1,127 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PersistedGrantEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.PersistedGrant", + typeof(PersistedGrant), + baseEntityType); + + var key = runtimeEntityType.AddProperty( + "Key", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Key", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var consumedTime = runtimeEntityType.AddProperty( + "ConsumedTime", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("ConsumedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(PersistedGrant).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var type = runtimeEntityType.AddProperty( + "Type", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Type", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var key0 = runtimeEntityType.AddKey( + new[] { key }); + runtimeEntityType.SetPrimaryKey(key0); + + var index = runtimeEntityType.AddIndex( + new[] { consumedTime }); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + var index1 = runtimeEntityType.AddIndex( + new[] { subjectId, clientId, type }); + + var index2 = runtimeEntityType.AddIndex( + new[] { subjectId, sessionId, type }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PersistedGrants"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaEntityType.cs new file mode 100644 index 00000000..3a124e63 --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaEntityType.cs @@ -0,0 +1,111 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Pizza", + typeof(Pizza), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var size = runtimeEntityType.AddProperty( + "Size", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Size", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var specialId = runtimeEntityType.AddProperty( + "SpecialId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("SpecialId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { orderId }); + + var index0 = runtimeEntityType.AddIndex( + new[] { specialId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var pizzas = principalEntityType.AddNavigation("Pizzas", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Order).GetProperty("Pizzas", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("SpecialId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var special = declaringEntityType.AddNavigation("Special", + runtimeForeignKey, + onDependent: true, + typeof(PizzaSpecial), + propertyInfo: typeof(Pizza).GetProperty("Special", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Pizzas"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs new file mode 100644 index 00000000..e86b0f50 --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs @@ -0,0 +1,76 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaSpecialEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaSpecial", + typeof(PizzaSpecial), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(PizzaSpecial).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var basePrice = runtimeEntityType.AddProperty( + "BasePrice", + typeof(decimal), + propertyInfo: typeof(PizzaSpecial).GetProperty("BasePrice", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var imageUrl = runtimeEntityType.AddProperty( + "ImageUrl", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("ImageUrl", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Specials"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaStoreContextModel.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaStoreContextModel.cs new file mode 100644 index 00000000..8b516a68 --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaStoreContextModel.cs @@ -0,0 +1,28 @@ +// +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + [DbContext(typeof(PizzaStoreContext))] + public partial class PizzaStoreContextModel : RuntimeModel + { + static PizzaStoreContextModel() + { + var model = new PizzaStoreContextModel(); + model.Initialize(); + model.Customize(); + _instance = model; + } + + private static PizzaStoreContextModel _instance; + public static IModel Instance => _instance; + + partial void Initialize(); + + partial void Customize(); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs new file mode 100644 index 00000000..d46f50f4 --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs @@ -0,0 +1,69 @@ +// +using System; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + public partial class PizzaStoreContextModel + { + partial void Initialize() + { + var address = AddressEntityType.Create(this); + var latLong = LatLongEntityType.Create(this); + var notificationSubscription = NotificationSubscriptionEntityType.Create(this); + var order = OrderEntityType.Create(this); + var pizza = PizzaEntityType.Create(this); + var pizzaSpecial = PizzaSpecialEntityType.Create(this); + var pizzaTopping = PizzaToppingEntityType.Create(this); + var pizzaStoreUser = PizzaStoreUserEntityType.Create(this); + var topping = ToppingEntityType.Create(this); + var deviceFlowCodes = DeviceFlowCodesEntityType.Create(this); + var key = KeyEntityType.Create(this); + var persistedGrant = PersistedGrantEntityType.Create(this); + var identityRole = IdentityRoleEntityType.Create(this); + var identityRoleClaimstring = IdentityRoleClaimstringEntityType.Create(this); + var identityUserClaimstring = IdentityUserClaimstringEntityType.Create(this); + var identityUserLoginstring = IdentityUserLoginstringEntityType.Create(this); + var identityUserRolestring = IdentityUserRolestringEntityType.Create(this); + var identityUserTokenstring = IdentityUserTokenstringEntityType.Create(this); + + LatLongEntityType.CreateForeignKey1(latLong, order); + OrderEntityType.CreateForeignKey1(order, address); + PizzaEntityType.CreateForeignKey1(pizza, order); + PizzaEntityType.CreateForeignKey2(pizza, pizzaSpecial); + PizzaToppingEntityType.CreateForeignKey1(pizzaTopping, pizza); + PizzaToppingEntityType.CreateForeignKey2(pizzaTopping, topping); + IdentityRoleClaimstringEntityType.CreateForeignKey1(identityRoleClaimstring, identityRole); + IdentityUserClaimstringEntityType.CreateForeignKey1(identityUserClaimstring, pizzaStoreUser); + IdentityUserLoginstringEntityType.CreateForeignKey1(identityUserLoginstring, pizzaStoreUser); + IdentityUserRolestringEntityType.CreateForeignKey1(identityUserRolestring, identityRole); + IdentityUserRolestringEntityType.CreateForeignKey2(identityUserRolestring, pizzaStoreUser); + IdentityUserTokenstringEntityType.CreateForeignKey1(identityUserTokenstring, pizzaStoreUser); + + AddressEntityType.CreateAnnotations(address); + LatLongEntityType.CreateAnnotations(latLong); + NotificationSubscriptionEntityType.CreateAnnotations(notificationSubscription); + OrderEntityType.CreateAnnotations(order); + PizzaEntityType.CreateAnnotations(pizza); + PizzaSpecialEntityType.CreateAnnotations(pizzaSpecial); + PizzaToppingEntityType.CreateAnnotations(pizzaTopping); + PizzaStoreUserEntityType.CreateAnnotations(pizzaStoreUser); + ToppingEntityType.CreateAnnotations(topping); + DeviceFlowCodesEntityType.CreateAnnotations(deviceFlowCodes); + KeyEntityType.CreateAnnotations(key); + PersistedGrantEntityType.CreateAnnotations(persistedGrant); + IdentityRoleEntityType.CreateAnnotations(identityRole); + IdentityRoleClaimstringEntityType.CreateAnnotations(identityRoleClaimstring); + IdentityUserClaimstringEntityType.CreateAnnotations(identityUserClaimstring); + IdentityUserLoginstringEntityType.CreateAnnotations(identityUserLoginstring); + IdentityUserRolestringEntityType.CreateAnnotations(identityUserRolestring); + IdentityUserTokenstringEntityType.CreateAnnotations(identityUserTokenstring); + + AddAnnotation("ProductVersion", "6.0.0"); + } + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs new file mode 100644 index 00000000..18b2d96d --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs @@ -0,0 +1,156 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaStoreUserEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Server.PizzaStoreUser", + typeof(PizzaStoreUser), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var accessFailedCount = runtimeEntityType.AddProperty( + "AccessFailedCount", + typeof(int), + propertyInfo: typeof(IdentityUser).GetProperty("AccessFailedCount", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var email = runtimeEntityType.AddProperty( + "Email", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Email", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var emailConfirmed = runtimeEntityType.AddProperty( + "EmailConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("EmailConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnabled = runtimeEntityType.AddProperty( + "LockoutEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnd = runtimeEntityType.AddProperty( + "LockoutEnd", + typeof(DateTimeOffset?), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnd", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var normalizedEmail = runtimeEntityType.AddProperty( + "NormalizedEmail", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedEmail", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedUserName = runtimeEntityType.AddProperty( + "NormalizedUserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedUserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var passwordHash = runtimeEntityType.AddProperty( + "PasswordHash", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PasswordHash", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumber = runtimeEntityType.AddProperty( + "PhoneNumber", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumber", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumberConfirmed = runtimeEntityType.AddProperty( + "PhoneNumberConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumberConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var securityStamp = runtimeEntityType.AddProperty( + "SecurityStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("SecurityStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var twoFactorEnabled = runtimeEntityType.AddProperty( + "TwoFactorEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("TwoFactorEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var userName = runtimeEntityType.AddProperty( + "UserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("UserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedEmail }); + index.AddAnnotation("Relational:Name", "EmailIndex"); + + var index0 = runtimeEntityType.AddIndex( + new[] { normalizedUserName }, + unique: true); + index0.AddAnnotation("Relational:Name", "UserNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUsers"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaToppingEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaToppingEntityType.cs new file mode 100644 index 00000000..b97d2a24 --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaToppingEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaTopping", + typeof(PizzaTopping), + baseEntityType); + + var pizzaId = runtimeEntityType.AddProperty( + "PizzaId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("PizzaId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var toppingId = runtimeEntityType.AddProperty( + "ToppingId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("ToppingId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { pizzaId, toppingId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { toppingId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("PizzaId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var toppings = principalEntityType.AddNavigation("Toppings", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Pizza).GetProperty("Toppings", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("ToppingId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var topping = declaringEntityType.AddNavigation("Topping", + runtimeForeignKey, + onDependent: true, + typeof(Topping), + propertyInfo: typeof(PizzaTopping).GetProperty("Topping", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PizzaTopping"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/ToppingEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/ToppingEntityType.cs new file mode 100644 index 00000000..9295f9bf --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/ToppingEntityType.cs @@ -0,0 +1,62 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class ToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Topping", + typeof(Topping), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Topping).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Topping).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var price = runtimeEntityType.AddProperty( + "Price", + typeof(decimal), + propertyInfo: typeof(Topping).GetProperty("Price", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Toppings"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/SeedData.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/SeedData.cs index 7c86a5b2..a1e47973 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Server/SeedData.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/SeedData.cs @@ -1,193 +1,192 @@ -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public static class SeedData { - public static class SeedData - { - public static void Initialize(PizzaStoreContext db) - { - var toppings = new Topping[] - { - new Topping() - { - Name = "Extra cheese", - Price = 2.50m, - }, - new Topping() - { - Name = "American bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "British bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "Canadian bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "Tea and crumpets", - Price = 5.00m - }, - new Topping() - { - Name = "Fresh-baked scones", - Price = 4.50m, - }, - new Topping() - { - Name = "Bell peppers", - Price = 1.00m, - }, - new Topping() - { - Name = "Onions", - Price = 1.00m, - }, - new Topping() - { - Name = "Mushrooms", - Price = 1.00m, - }, - new Topping() - { - Name = "Pepperoni", - Price = 1.00m, - }, - new Topping() - { - Name = "Duck sausage", - Price = 3.20m, - }, - new Topping() - { - Name = "Venison meatballs", - Price = 2.50m, - }, - new Topping() - { - Name = "Served on a silver platter", - Price = 250.99m, - }, - new Topping() - { - Name = "Lobster on top", - Price = 64.50m, - }, - new Topping() - { - Name = "Sturgeon caviar", - Price = 101.75m, - }, - new Topping() - { - Name = "Artichoke hearts", - Price = 3.40m, - }, - new Topping() - { - Name = "Fresh tomatoes", - Price = 1.50m, - }, - new Topping() - { - Name = "Basil", - Price = 1.50m, - }, - new Topping() - { - Name = "Steak (medium-rare)", - Price = 8.50m, - }, - new Topping() - { - Name = "Blazing hot peppers", - Price = 4.20m, - }, - new Topping() - { - Name = "Buffalo chicken", - Price = 5.00m, - }, - new Topping() - { - Name = "Blue cheese", - Price = 2.50m, - }, - }; + public static void Initialize(PizzaStoreContext db) + { + var toppings = new Topping[] + { + new Topping() + { + Name = "Extra cheese", + Price = 2.50m, + }, + new Topping() + { + Name = "American bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "British bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "Canadian bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "Tea and crumpets", + Price = 5.00m + }, + new Topping() + { + Name = "Fresh-baked scones", + Price = 4.50m, + }, + new Topping() + { + Name = "Bell peppers", + Price = 1.00m, + }, + new Topping() + { + Name = "Onions", + Price = 1.00m, + }, + new Topping() + { + Name = "Mushrooms", + Price = 1.00m, + }, + new Topping() + { + Name = "Pepperoni", + Price = 1.00m, + }, + new Topping() + { + Name = "Duck sausage", + Price = 3.20m, + }, + new Topping() + { + Name = "Venison meatballs", + Price = 2.50m, + }, + new Topping() + { + Name = "Served on a silver platter", + Price = 250.99m, + }, + new Topping() + { + Name = "Lobster on top", + Price = 64.50m, + }, + new Topping() + { + Name = "Sturgeon caviar", + Price = 101.75m, + }, + new Topping() + { + Name = "Artichoke hearts", + Price = 3.40m, + }, + new Topping() + { + Name = "Fresh tomatoes", + Price = 1.50m, + }, + new Topping() + { + Name = "Basil", + Price = 1.50m, + }, + new Topping() + { + Name = "Steak (medium-rare)", + Price = 8.50m, + }, + new Topping() + { + Name = "Blazing hot peppers", + Price = 4.20m, + }, + new Topping() + { + Name = "Buffalo chicken", + Price = 5.00m, + }, + new Topping() + { + Name = "Blue cheese", + Price = 2.50m, + }, + }; - var specials = new PizzaSpecial[] - { - new PizzaSpecial() - { - Name = "Basic Cheese Pizza", - Description = "It's cheesy and delicious. Why wouldn't you want one?", - BasePrice = 9.99m, - ImageUrl = "img/pizzas/cheese.jpg", - }, - new PizzaSpecial() - { - Id = 2, - Name = "The Baconatorizor", - Description = "It has EVERY kind of bacon", - BasePrice = 11.99m, - ImageUrl = "img/pizzas/bacon.jpg", - }, - new PizzaSpecial() - { - Id = 3, - Name = "Classic pepperoni", - Description = "It's the pizza you grew up with, but Blazing hot!", - BasePrice = 10.50m, - ImageUrl = "img/pizzas/pepperoni.jpg", - }, - new PizzaSpecial() - { - Id = 4, - Name = "Buffalo chicken", - Description = "Spicy chicken, hot sauce and bleu cheese, guaranteed to warm you up", - BasePrice = 12.75m, - ImageUrl = "img/pizzas/meaty.jpg", - }, - new PizzaSpecial() - { - Id = 5, - Name = "Mushroom Lovers", - Description = "It has mushrooms. Isn't that obvious?", - BasePrice = 11.00m, - ImageUrl = "img/pizzas/mushroom.jpg", - }, - new PizzaSpecial() - { - Id = 6, - Name = "The Brit", - Description = "When in London...", - BasePrice = 10.25m, - ImageUrl = "img/pizzas/brit.jpg", - }, - new PizzaSpecial() - { - Id = 7, - Name = "Veggie Delight", - Description = "It's like salad, but on a pizza", - BasePrice = 11.50m, - ImageUrl = "img/pizzas/salad.jpg", - }, - new PizzaSpecial() - { - Id = 8, - Name = "Margherita", - Description = "Traditional Italian pizza with tomatoes and basil", - BasePrice = 9.99m, - ImageUrl = "img/pizzas/margherita.jpg", - }, - }; + var specials = new PizzaSpecial[] + { + new PizzaSpecial() + { + Name = "Basic Cheese Pizza", + Description = "It's cheesy and delicious. Why wouldn't you want one?", + BasePrice = 9.99m, + ImageUrl = "img/pizzas/cheese.jpg", + }, + new PizzaSpecial() + { + Id = 2, + Name = "The Baconatorizor", + Description = "It has EVERY kind of bacon", + BasePrice = 11.99m, + ImageUrl = "img/pizzas/bacon.jpg", + }, + new PizzaSpecial() + { + Id = 3, + Name = "Classic pepperoni", + Description = "It's the pizza you grew up with, but Blazing hot!", + BasePrice = 10.50m, + ImageUrl = "img/pizzas/pepperoni.jpg", + }, + new PizzaSpecial() + { + Id = 4, + Name = "Buffalo chicken", + Description = "Spicy chicken, hot sauce and bleu cheese, guaranteed to warm you up", + BasePrice = 12.75m, + ImageUrl = "img/pizzas/meaty.jpg", + }, + new PizzaSpecial() + { + Id = 5, + Name = "Mushroom Lovers", + Description = "It has mushrooms. Isn't that obvious?", + BasePrice = 11.00m, + ImageUrl = "img/pizzas/mushroom.jpg", + }, + new PizzaSpecial() + { + Id = 6, + Name = "The Brit", + Description = "When in London...", + BasePrice = 10.25m, + ImageUrl = "img/pizzas/brit.jpg", + }, + new PizzaSpecial() + { + Id = 7, + Name = "Veggie Delight", + Description = "It's like salad, but on a pizza", + BasePrice = 11.50m, + ImageUrl = "img/pizzas/salad.jpg", + }, + new PizzaSpecial() + { + Id = 8, + Name = "Margherita", + Description = "Traditional Italian pizza with tomatoes and basil", + BasePrice = 9.99m, + ImageUrl = "img/pizzas/margherita.jpg", + }, + }; - db.Toppings.AddRange(toppings); - db.Specials.AddRange(specials); - db.SaveChanges(); - } - } -} + db.Toppings.AddRange(toppings); + db.Specials.AddRange(specials); + db.SaveChanges(); + } +} \ No newline at end of file diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/SpecialsController.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/SpecialsController.cs deleted file mode 100644 index a176844c..00000000 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Server/SpecialsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("specials")] - [ApiController] - public class SpecialsController : Controller - { - private readonly PizzaStoreContext _db; - - public SpecialsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetSpecials() - { - return (await _db.Specials.ToListAsync()).OrderByDescending(s => s.BasePrice).ToList(); - } - } -} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Startup.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Startup.cs deleted file mode 100644 index ed3fca06..00000000 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Startup.cs +++ /dev/null @@ -1,70 +0,0 @@ -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace BlazingPizza.Server -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - public void ConfigureServices(IServiceCollection services) - { - services.AddControllersWithViews(); - services.AddRazorPages(); - - services.AddDbContext(options => - options.UseSqlite("Data Source=pizza.db")); - - services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) - .AddEntityFrameworkStores(); - - services.AddIdentityServer() - .AddApiAuthorization(); - - services.AddAuthentication() - .AddIdentityServerJwt(); - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - app.UseWebAssemblyDebugging(); - } - else - { - app.UseExceptionHandler("/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); - } - - app.UseHttpsRedirection(); - app.UseBlazorFrameworkFiles(); - app.UseStaticFiles(); - - app.UseRouting(); - - app.UseAuthentication(); - app.UseIdentityServer(); - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - endpoints.MapRazorPages(); - endpoints.MapFallbackToFile("index.html"); - }); - } - } -} \ No newline at end of file diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/ToppingsController.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/ToppingsController.cs deleted file mode 100644 index 6a677639..00000000 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Server/ToppingsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("toppings")] - [ApiController] - public class ToppingsController : Controller - { - private readonly PizzaStoreContext _db; - - public ToppingsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetToppings() - { - return await _db.Toppings.OrderBy(t => t.Name).ToListAsync(); - } - } -} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/pizza.db-shm b/save-points/06-authentication-and-authorization/BlazingPizza.Server/pizza.db-shm new file mode 100644 index 0000000000000000000000000000000000000000..d52f63d35bfa01e9d93f7f13ebc85edc02a39305 GIT binary patch literal 32768 zcmeI*xk{u#6vgp!Us~;U8EyA{9d{jlfr-S-(9EYW@tI7`O^wCaWbhFLLC?`q%;pM0 zPZj?IhYylGCC#rBplAb4R_oxO<#`+`7GbIH|1nAN@Z6b9{RFbaq|; z;(7hlYy7*XbUI&Zx8MoI0;AsEg{7x~#6KtLmEiQ(afBwyAEZ+p5ic_xJm} z-__qE2q1s}0tg_000IagfB*srAb5{SpJja+s1UyBW zlqKK^-XtQ>oqk1*aV8^ynT+n**sE63L1Qn#+rM4FTN_A3z&kTYSpwcyLLvg*7DLJs z@TMLT5%8WQQkH;sRFQ~4HSI-?aV8@HZ)YPBfm+&+9OFzz0^UnVA_CqDNy-xNMotnD r@IF*hmVkHBl8Ase0h6)>R+INglYa|%2R127!28EZM8MnMNkrfU7x*+) literal 0 HcmV?d00001 diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/pizza.db-wal b/save-points/06-authentication-and-authorization/BlazingPizza.Server/pizza.db-wal new file mode 100644 index 0000000000000000000000000000000000000000..ea6103d0290efd8b8d8a6a324c31bf3485cb3e72 GIT binary patch literal 226632 zcmeI54UijYdFLg2JY$bNGrQ}xwO+5WJYKIoYs=QhNHb!y7=5&6H2VG?4F^g~YDq1% z)KYg#8cniCyf&L~)K%avNhJ^pvg|>nNFA4}qsSFWLGe*s71SjcLXIR9Q;oe!rggd4A9HzWw$i&F_mED0{oXec z$FDuS<^9Xoe(SSe;=b^kq)M-?|7SgM#`ogC`*9)`WF^K};)Oab8Es_rp+maY8;zvz zA@XC9#|&N<$@`32An%GiO?lGgA>H-Jb4N(ap{4K3?N2TJpQZ25e{|vLV>9!2=H7nv zFJ=QX-0X?N!l4iAPb}_E67m18?)Fm;%^A*|(Z6t6qVpUR5sHi;_J2R@iBqm5WlXx< zLCUz?uUs}>S(rDHSHJ8pE*t&fB(*`sjp0br7)}L)Mo%Q1NXA{H-nbkM_Wdu<>iB{G66B1vuc$Epn;fuSX)m}KjW+B%S~_V6+s+hK&Bt5_5mQ5;c(C^6nG z$QNjdSeR1}`xmv5A(bk^GFQ*F!*l*vs{&KHSO{*AC~z46NO-5pkl zK0Yc=g*{ZlxI7R| zcxpIG<13>pm5lhqM1F`0CskHqdgvJq?x?^P#yuu0-(6IczwJ_#Pc)eVOLL<7zBH=5 zTK&qDACCG-m3Px3GsyteW-lWa1hy%Mks6d5)BSb2%%lWP(?l%4eeT4Z;p$cWTUv_c zQL?&Nkwo@}KsO|Dthg}BVXSqCBf#|3S*CdMuAv$xsyWGCbKF&GQ=*-(G6iYk(oB%m zMhHx7^KdNF&Y1$PAcvV^AcNP`#TL` zxNogEwc*65%cu4mI)7T12U+0L#)`{EO@K^Z@l*He(U@05C~CDkiWL>O#t*Kxq^%}C zcz*NPoZ-|d{T)$(NTOSmf96Ng$W=oM!|QJ|PNM=Zk@d$+xVx%aP7deG^RtF$ zPE8AEnMuwf|33cwb8~Zsix>58>F>y1rb9Mv4_{;$h2+s6c{_P%t9MCon4CQ9Qx#|)xWxty64rAo^yj?%%X2~m3A2%Xa59?qAs z%-kP~qLYe6Daen6N98BG=%HEpNSIaN49*-P(`u7YW5$YyM<9(gUTKg+_%$+e<@u}n zIm6kr`a7mR@cuK=;34ABhz!l6#o!_AK@JZ4&m$VflaC2npkq5>kZmv)b)igXv#M>{ zRY+E-T0J%-&XhGL@v+7zPYx5D_QpiOKWZSqPA-yP@^k)vz994)J74?3yZ>IdAXoNN z3Gx+QAOHd&00JNY0w4eaAOHd&00JNY0tb`8Vc9J8djyZh{`!~x==(ohLSEotIvZAj z00@8p2!H?xfB*=900@8p2!OyC0p)K1)V#nGkN^4nmtXX~6M2C#N+^N=2!H?xfB*=9 z00@8p2!H?xfWW~dApcFr{`Uo*{h8#~VxRRI=jBTL9f3>%FAx9$5C8!X009sH0T2KI z5C8!XILHKMW#iQE3;e7mA~h!!0w4eaAOHd&00JNY0w4eaAOHgU1eWA0H81e~|R9JYY~2!H?xfB*=900@8p2!H?x zfWSV1lk%0C7x=uX`rY%t__dXV#a-RvVL`X}$BVzPKrg!HKf3Vrv6=Zhb8kQT7qfwx z56*Chg+m|KpCH{1{A+RdP|0xSjQ)ko5}oImh)`q%vH$yFPn>ckDPz**4pPSDe&w?9 z%EG*ny!vH-aoOk(C#el8ZVX3~#&9YaGxRrL)#XpK4=npiFLpa=u8M@^6G?>y1~I@9wZd^zl(~D(s;W z#^r$^LVKB5wz4q4a_hBAbB1&0^v`c7j!N>)Cfg{B>ia{Z&Qhy~?iv9!#Z$vk8ebV* zsbs_-Ch|j6IH|G<(?ic_a7P8UFzzu~`R<~k{B4(_e4@z|Seg^n_oY$g)#_KK{BYDy zs=S*PnMnqyHhUSdAh1n2jMSjinC`FBWhNzXnkHiTvkS9^*j2rbZ4{YZvBj|xlcU=b zuat99ve;OW1p0leeT4Z;p$cWTUrXZvF5Sj!YIbE)*;OR(^Hk45(sw< z)gV=ABzw(qPpeIdcD~9Kq=_p#K^7|kII+#cu}niV?5-t$FaFAwK_uT}&!Bdjte|WI zs{I=OdH9Cdu8;0Hnr1I8(dwvyUc|l6yN}NqZr;@2IjQ(3%u8&E?e8=M!oIrV)P@tI zKAYNa=)GxO9%O+}8!IjwH6EV4;-~J_qcN|>K-6k?6e}t*4MI3PMy-< z5fz9eJVp6ueiV&dHKZ_%pD7{S@2;^*RV*#9Ie7(--?!8bgL{vv`dAPW3~GzkD6Y&4 ztW>G1ZDXVS;BGJYJrkH9T`_+IAx|$ywyz z$De<0Zq9J=qW&%Y9ofrt$j0sAi;SqbJUZ$DP0P>`a#+aY#ta`n1dNQG;FV$fm>|{O zSI?d@=K9HwvLBr__%BX#)Q|@8m!@#+4tGRx+gr~oOT{HN!;B=mK-65$j=D|LGIZO0 z*U!kP2@aDdopJ~W^Fp2G*gd9rk4{vbX0`W9)z8Dh(|RcNWVbG{0@<#oFQh0fid|kP zZqlN5!%-(nFoiZ*vb}^v*PCk4X_hpZfpid<8t z;QeQ!!9&EM5gD3Ci@`(KgB%?8pGP!|Cm$2EK*x5%AlqOp>Oz^&W>wp?tB|ZvwR&tw zoGEKg;$w|bo*X8)2{$IB^_j|HPmdE$XmD{f|%o$83{abj=!jm`QBwu41ntMdQ z{P`U)A57(hA;;uV}x{(I?GTR_0mJUmD2UC1?kElq~TzmiYF!a3k0h=TdhL)?k zX(RE<@<79D#^q6UNQE-@%0OGKSn}LHE>=?^=2WXkAKeGFW6$gR=;Sl1^2{zf%u59+ zl0osf5+0YABB4iu$CWTmyY1hljb>Nvn|=0n{FL%Q_`(~;JgjUnLjg+hv1$HQS|8B8 za^Gpb*U}tu(qMvVJ{ripuTvB;1E2J-2P2K6K2hb3=1>%$D8r`vF?S9b<4D>ga0r`-vLt6g2c6DOG(WvarXVK%BZ*#J}xWF7Ata($UU?S0_pqqBww z*#`#NXk6Z}G2GTY(%2_Ck#~8`*;XNE988!B`(r7JQj@}<8xz5>rrvG}fm<7x~o?h9Tfj}V8yV7PQi z|3XCBexvN(9zFQ5pth1UIc=G+GbF-Ew+Q!3m00ck)1V8`;KmY_l z00cnbl@lU00T2KI5C8!X009sH0T2KI5EvzJMlPy( zfu{}cde{0NG9SnH1x6vE1Ogxc0w4eaAOHd&00JNY0w4ea2b93$vR!Ik;9bA|kH;kL z#2mgaa6r8cvp@g@KmY_l00ck)1V8`;KmY_lV3fdFxv1s^wtnrmT;`wo%x~cP0;7;n z0s#;J0T2KI5C8!X009sH0T2Lz14`ft*)BCN@U8fN=704Wn-|{~IH2B!Ss(xcAOHd& z00JNY0w4eaAOHd&FiPN@TvYP{e|O=j`pYL?_YCp^qmWPn0T2KI5C8!X009sH0T2KI z5CDM#O5ioJU20z7JFj=PPf>6F1N8+LtbDM z5=tNd0w4eaAOHd&00JNY0w4eaAaFnlEX#JOd4Vr}$Yg)YeD)Ob0teLFFbf1g00ck) z1V8`;KmY_l00ck)1V#y5l#6O!;2UQ@w2=94tLKpy7=?rq2!H?xfB*=900@8p2!H?x zfB*;_Py$cNcBy#*$D9A^dk>dC@Ezm@4ydxw(zYJ7mt7QcxnEJ^U|@uJ=Qw5boAXvAD?^ATzdA;XE%@h{*l8o z8;8Gn_yy7#FAz9z1oljGhMSl4x6ZMRBD3q?&PCb1JvzxZn{1<;8@&6A+FFYzPPvkl z(I56w+s5UoW0sAPuyI*Ca@lxgd0*u6O8(lM!FEP}>&VF5VlL5S3M|bHW);no=hO7l z%p}Tl>AQ58*1tc0zg3Q}y96$;Y+RZ(Ts);` z)TskZPt2u6Mt)zpYa+F^FIXmj`pF!v0uFyDe(^Xhu#{Vc2zfrMWz3 zxJ<0SsAxcd2w}R;_~rfCB{sv1Bv*--CeAw2yFZg=jBIR}7wR;}?lDER@AAseUYIjn zATu6QW~Ayg%Z*R>zjgCbHkwl9@5ftRhY(t4tazhx(?^iG1LxYil<0=e>_amAJ zmUVc|R2@7V&DQVMpz!u-nZ=$SdgnKSwqes1VUQDG!LF~NDVEd!s( z495Ls)B;o;LB?oZ;7TPU{xFdpqQXhl!OER;l0>z`@X&hKr2AdSwtcrs_dqP>2DkJ5 z*++eT8}b5^P@xV4KmY_l00ck) z1V8`;KmY_l00a&k0h4TzniqKgFZ}r1@A#eH{xR|b2hPth2n0X?1V8`;KmY_l00ck) z1V8`;CK0$USE_k|UpsW^D?j%pw*h&9NvKc<0w4eaAOHd&00JNY0w4eaAOHdfj=&As zA~i4Y%WE(GWA77JddLeLI6uQ65C8!X009sH0T2KI5C8!X009t~M8GUps(FD=ztoL< z@#~8oMXa9FNX^8)XV{mXAfqJRIf1yXlt>3`^!{x|uB z7YKj=2!H?xfB*=900@8p2!H?xfWWJkz==bL&*_tVv&lBf;^`B5Qc5(L0!wq^QDW4R zY?zuCc=o^C`OH6@mp&rr1&%J*bxXg#6kPn;qOf>&;j0V3N-FRI0T2KI5C8!X009sH z0T2KI5YXw~baYmC;S_%}L<{8#Bd`+fyzX=+1-i&eEZ?9xqhF#qmTnlE?A{)2?6OkD zDDib#;u+CMH;TqQEwUV2FW*o)h&Sr{lCD>q<-pvmZsk0-JeM#QE8Wjt12Cc0Y8*RA$Ug=rYs zhB3%DihSex_3N6EdD2N9m^w16yLu|~OsFkZ1fH*x&K*V&i5h0VWUSDlu|8-KuN(bh zCX6AHP4Yy9(-R)9|=6GYF!WL>w!(zR@W=}NPLQk!^ zW~}fMF|=J^`p`J0P1+bnWUd*@ZCaok62lY;S!0(L>c$@5HnyAEX&GAT$#WJD&+2ZR z;-B?!v?#I#W0Pq%8G&!G1V*2!MCkOLB}*v_OqYmK9M@;;=IA~0SS@RGK{La?AbFOp zLu3|%%dU{73nUOEUSRilfgp1_2h6B670()LEC~X>MB;#S)5ufGvaFJRR%bcYU2~H_ zDHuJ9(Z;A8O>(FyVW5!cDP)QyLJBhU>&8r_XYBHAt|Z^Ik@Etl7yd!F^w&$DU;6!}mzLhP)LeSQQgG?DOIMaoF220@ z`NfYezIX8#7n_UuMc?Ani;s}bc!2;2fB*=900@8p2!H?xfB*=*$_PAidPaBgq?>Cq zgXeAQb^Ga4GrFrM#~#}4*UgVVI-|3ZzWdL|gQsh8^}6-(lX6=^V(6OjN}VaP?Yc>z z1!iUay8Xl>Gdjab`T3S3iH%ba&*)Z8`UFNCW=cr4;h`Cw>7+}L*g}OTS&s@s3zBHN zzItYfXmchZwS_W6@*f4d!_tDqY#}*>(~CsZsUV*hB}R~wBNE?qtX{W2xiF)1ok=i4 zhvW>DoC%qlWHgLTj+RJQtKCcrF-y3Hj4AvY{TjLGn%{*QDeQ zti*&YDX7_!Yf=K6K1;)^POL`|B3F!)9}>+stmC&9c5~ zUpG^0)>R)xIh-!?+iW#kttPY0WOf>@=GWRRuU%cc?l9Y}wpFXhmK!9O9#2^94o}Iu zwH|5u*E;QTs9D*lmE7TtSjfYKv(;+e(@sg%z-l4AR*dl37`<)|ZPE3DZ&UEt1M8)7 zD89aG?Id_{$LV%%Vz#)ykl%E7-EJ8(CYjYtPgZ!AwhVBqEhu z#+340XU(u6i;tz7S4r?+Q+~>hk7%j-=EGt!6#Jwk^d8J!`ew&h6xF z*&x5?+X@M->XzTSwr#KPxLA)fV(B(&dC_hcy5*cL*0V;EY;m=`owjDpxh*$ONvj@v zr@OOT=*EgYsnDwNy`q_I=Xa#gdN7~f^*gBUE}i0YrkE?fM@LHSmOm6>oZV!(P*}@K zt?k}w#Gh}j*)1ifwQk!IsIGfAo?0#OOxn@Ph!xtDu?E6b&-%8_Un|5Kg>6$$q{8dI z-Rf4YTS(ID)ve85u(KKRZLY5SvZiu-Bc0Ei?adfn=~~OBRcw3clLc8VTvwjAGc zREvSNRiC}O$97%eb!nrtm!#dbMj==7Ih*UQ?R-14V-2*bVRvzzORw#$_11*dWI5(o z^M-}&ddpj`t=HC^>CjfmTyAw@?QS3!_Q#}5x)E`+)nKRONvC%M!B{rUTB8mt?VxI% z_HMNvGX*WFW^LEIvsQ{1w^IUFvuu>JQ7@O;_L$4fL^sz8x|`KnVncK|_Oi6S5^`AL zVcy|0hm)1=rd{MaLdMdft=&>PD|tgEI@NZR;u}mPvKO*&!9XNP)0NE)+HLW2`Cv7i zsjORfsGX`WmGrw(I~8|v*U|2!)@*)@n_Jr}G+W_a8?{^S<%1$)&UW?+F?XRF2#Ie0 z-mb@zt9M+kbkyq4mNtB;il<6;yv%O5$8vkNkiFDuyLnsC>(7}TYcAhLbu&XbVwqGu zmuq(Y)k53P`W$)2ZQ`~!H$z>UKkRHc(xD6;UiW9+&6bIcM%$%OVmF*Jb34@tv=^Hu zUndt$JCjAS=ec5ZU^TGbrSnlIpVwK7VGT|CLOaCQ>L`Fy>2pPx3*fn zmL=k{g#(?9T(DQ>f=Dw$$t0j?25gzL)gI;sFN}+VbS2J#Ke5kaBFh+ulkw8(lA0wu@Xg==SV5 zcl`-_M=BM9fmD=yzMu2iHnzlc&{^wrI8%4aVXMU~jc#t!5sd}u64@e{PO`)0y$x|s z+LSuQY;Y}^-rT8HQ&OkRw4GF>&epc}%3`3DOgWmCnytFsZ8d8pinkYbB94u8an)7v zc8f7fcs(CWWw|T6ECFcE+CFw6?wORg2puG7Pb@!g%oNJeA-W@7Xt+>LO&3vZV z^L8EXZY)}Bml7S9lr5}UJ(W&+yIIe-d9k;XBF3>amD%0fUayz8>t;sik%eDlYdL<4 z_jWkCVzTqGuD@8{Dkr6?Yo{4cu5CH9EsMpoM+-tR6iAVy?s56JtL6nB`R~8`z8By4 z=x@u(0{zmLbmSjiAOHd&00JNY0w4eaAOHd&00JNY07Y~Py-S6WbV%7@z+5bC& zm%sSj=l=A@%NP53f$!;-zV|9L94dnV2!H?xfB*=900@8p2!H?xfB*nXJW literal 0 HcmV?d00001 diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Address.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Address.cs index d76bc52a..79be9c5b 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Address.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Address.cs @@ -1,27 +1,24 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class Address { - public class Address - { - public int Id { get; set; } + public int Id { get; set; } - [Required, MaxLength(100)] - public string Name { get; set; } + [Required, MaxLength(100)] + public string Name { get; set; } - [Required, MaxLength(100)] - public string Line1 { get; set; } + [Required, MaxLength(100)] + public string Line1 { get; set; } - [MaxLength(100)] - public string Line2 { get; set; } + [MaxLength(100)] + public string Line2 { get; set; } - [Required, MaxLength(50)] - public string City { get; set; } + [Required, MaxLength(50)] + public string City { get; set; } - [Required, MaxLength(20)] - public string Region { get; set; } + [Required, MaxLength(20)] + public string Region { get; set; } - [Required, MaxLength(20)] - public string PostalCode { get; set; } - } + [Required, MaxLength(20)] + public string PostalCode { get; set; } } diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/BlazingPizza.Shared.csproj index f7b7dd02..fb17e53b 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -3,8 +3,13 @@ $(TargetFrameworkVersion) BlazingPizza + true + + + + diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/LatLong.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/LatLong.cs index 9b8c3811..14a94c26 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/LatLong.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/LatLong.cs @@ -1,27 +1,26 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class LatLong { - public class LatLong - { - public LatLong() - { - } + public LatLong() + { + } - public LatLong(double latitude, double longitude) : this() - { - Latitude = latitude; - Longitude = longitude; - } + public LatLong(double latitude, double longitude) : this() + { + Latitude = latitude; + Longitude = longitude; + } - public double Latitude { get; set; } + public double Latitude { get; set; } - public double Longitude { get; set; } + public double Longitude { get; set; } - public static LatLong Interpolate(LatLong start, LatLong end, double proportion) - { - // The Earth is flat, right? So no need for spherical interpolation. - return new LatLong( - start.Latitude + (end.Latitude - start.Latitude) * proportion, - start.Longitude + (end.Longitude - start.Longitude) * proportion); - } - } -} + public static LatLong Interpolate(LatLong start, LatLong end, double proportion) + { + // The Earth is flat, right? So no need for spherical interpolation. + return new LatLong( + start.Latitude + (end.Latitude - start.Latitude) * proportion, + start.Longitude + (end.Longitude - start.Longitude) * proportion); + } +} \ No newline at end of file diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/NotificationSubscription.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/NotificationSubscription.cs index 04259c2f..9109ff57 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/NotificationSubscription.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/NotificationSubscription.cs @@ -1,17 +1,14 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class NotificationSubscription { - public class NotificationSubscription - { - public int NotificationSubscriptionId { get; set; } + public int NotificationSubscriptionId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public string Url { get; set; } + public string Url { get; set; } - public string P256dh { get; set; } + public string P256dh { get; set; } - public string Auth { get; set; } - } + public string Auth { get; set; } } diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Order.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Order.cs index fb003bd6..aca04ca1 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Order.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Order.cs @@ -1,25 +1,32 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +public class Order { - public class Order - { - public int OrderId { get; set; } + public int OrderId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public DateTime CreatedTime { get; set; } + public DateTime CreatedTime { get; set; } - public Address DeliveryAddress { get; set; } = new Address(); + public Address DeliveryAddress { get; set; } = new Address(); - public LatLong DeliveryLocation { get; set; } + public LatLong DeliveryLocation { get; set; } - public List Pizzas { get; set; } = new List(); + public List Pizzas { get; set; } = new List(); - public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); + public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); - public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); - } + public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Default, PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] +[JsonSerializable(typeof(Order))] +[JsonSerializable(typeof(OrderWithStatus))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Pizza))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Topping))] +public partial class OrderContext : JsonSerializerContext {} \ No newline at end of file diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/OrderWithStatus.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/OrderWithStatus.cs index 021de78c..f5f153b6 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/OrderWithStatus.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/OrderWithStatus.cs @@ -1,79 +1,78 @@ -using BlazingPizza.ComponentsLibrary.Map; -using System; -using System.Collections.Generic; +using System.Text.Json.Serialization; +using BlazingPizza.ComponentsLibrary.Map; -namespace BlazingPizza + +namespace BlazingPizza; + +public class OrderWithStatus { - public class OrderWithStatus - { - public readonly static TimeSpan PreparationDuration = TimeSpan.FromSeconds(10); - public readonly static TimeSpan DeliveryDuration = TimeSpan.FromMinutes(1); // Unrealistic, but more interesting to watch + public readonly static TimeSpan PreparationDuration = TimeSpan.FromSeconds(10); + public readonly static TimeSpan DeliveryDuration = TimeSpan.FromMinutes(1); // Unrealistic, but more interesting to watch - public Order Order { get; set; } + public Order Order { get; set; } - public string StatusText { get; set; } + public string StatusText { get; set; } - public bool IsDelivered => StatusText == "Delivered"; + public bool IsDelivered => StatusText == "Delivered"; - public List MapMarkers { get; set; } + public List MapMarkers { get; set; } - public static OrderWithStatus FromOrder(Order order) - { - // To simulate a real backend process, we fake status updates based on the amount - // of time since the order was placed - string statusText; - List mapMarkers; - var dispatchTime = order.CreatedTime.Add(PreparationDuration); + public static OrderWithStatus FromOrder(Order order) + { + // To simulate a real backend process, we fake status updates based on the amount + // of time since the order was placed + string statusText; + List mapMarkers; + var dispatchTime = order.CreatedTime.Add(PreparationDuration); - if (DateTime.Now < dispatchTime) - { - statusText = "Preparing"; - mapMarkers = new List - { - ToMapMarker("You", order.DeliveryLocation, showPopup: true) - }; - } - else if (DateTime.Now < dispatchTime + DeliveryDuration) - { - statusText = "Out for delivery"; + if (DateTime.Now < dispatchTime) + { + statusText = "Preparing"; + mapMarkers = new List + { + ToMapMarker("You", order.DeliveryLocation, showPopup: true) + }; + } + else if (DateTime.Now < dispatchTime + DeliveryDuration) + { + statusText = "Out for delivery"; - var startPosition = ComputeStartPosition(order); - var proportionOfDeliveryCompleted = Math.Min(1, (DateTime.Now - dispatchTime).TotalMilliseconds / DeliveryDuration.TotalMilliseconds); - var driverPosition = LatLong.Interpolate(startPosition, order.DeliveryLocation, proportionOfDeliveryCompleted); - mapMarkers = new List - { - ToMapMarker("You", order.DeliveryLocation), - ToMapMarker("Driver", driverPosition, showPopup: true), - }; - } - else - { - statusText = "Delivered"; - mapMarkers = new List - { - ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), - }; - } + var startPosition = ComputeStartPosition(order); + var proportionOfDeliveryCompleted = Math.Min(1, (DateTime.Now - dispatchTime).TotalMilliseconds / DeliveryDuration.TotalMilliseconds); + var driverPosition = LatLong.Interpolate(startPosition, order.DeliveryLocation, proportionOfDeliveryCompleted); + mapMarkers = new List + { + ToMapMarker("You", order.DeliveryLocation), + ToMapMarker("Driver", driverPosition, showPopup: true), + }; + } + else + { + statusText = "Delivered"; + mapMarkers = new List + { + ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), + }; + } - return new OrderWithStatus - { - Order = order, - StatusText = statusText, - MapMarkers = mapMarkers, - }; - } + return new OrderWithStatus + { + Order = order, + StatusText = statusText, + MapMarkers = mapMarkers, + }; + } - private static LatLong ComputeStartPosition(Order order) - { - // Random but deterministic based on order ID - var rng = new Random(order.OrderId); - var distance = 0.01 + rng.NextDouble() * 0.02; - var angle = rng.NextDouble() * Math.PI * 2; - var offset = (distance * Math.Cos(angle), distance * Math.Sin(angle)); - return new LatLong(order.DeliveryLocation.Latitude + offset.Item1, order.DeliveryLocation.Longitude + offset.Item2); - } + private static LatLong ComputeStartPosition(Order order) + { + // Random but deterministic based on order ID + var rng = new Random(order.OrderId); + var distance = 0.01 + rng.NextDouble() * 0.02; + var angle = rng.NextDouble() * Math.PI * 2; + var offset = (distance * Math.Cos(angle), distance * Math.Sin(angle)); + return new LatLong(order.DeliveryLocation.Latitude + offset.Item1, order.DeliveryLocation.Longitude + offset.Item2); + } - static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) - => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; - } -} + static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) + => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; +} \ No newline at end of file diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Pizza.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Pizza.cs index ec1108a9..459298f4 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Pizza.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Pizza.cs @@ -1,42 +1,44 @@ -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// /// Represents a customized pizza as part of an order +/// +public class Pizza { - /// - /// Represents a customized pizza as part of an order - /// - public class Pizza - { - public const int DefaultSize = 12; - public const int MinimumSize = 9; - public const int MaximumSize = 17; + public const int DefaultSize = 12; + public const int MinimumSize = 9; + public const int MaximumSize = 17; - public int Id { get; set; } + public int Id { get; set; } - public int OrderId { get; set; } + public int OrderId { get; set; } - public PizzaSpecial Special { get; set; } + public PizzaSpecial Special { get; set; } - public int SpecialId { get; set; } + public int SpecialId { get; set; } - public int Size { get; set; } + public int Size { get; set; } - public List Toppings { get; set; } + public List Toppings { get; set; } - public decimal GetBasePrice() - { - return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; - } + public decimal GetBasePrice() + { + return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; + } - public decimal GetTotalPrice() - { - return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); - } + public decimal GetTotalPrice() + { + return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); + } - public string GetFormattedTotalPrice() - { - return GetTotalPrice().ToString("0.00"); - } - } + public string GetFormattedTotalPrice() + { + return GetTotalPrice().ToString("0.00"); + } } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Serialization)] +[JsonSerializable(typeof(Pizza))] +public partial class PizzaContext : JsonSerializerContext {} \ No newline at end of file diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/PizzaSpecial.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/PizzaSpecial.cs index 2f2b3383..9653300c 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/PizzaSpecial.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/PizzaSpecial.cs @@ -1,20 +1,19 @@ -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// Represents a pre-configured template for a pizza a user can order +/// +public class PizzaSpecial { - /// - /// Represents a pre-configured template for a pizza a user can order - /// - public class PizzaSpecial - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal BasePrice { get; set; } + public decimal BasePrice { get; set; } - public string Description { get; set; } + public string Description { get; set; } - public string ImageUrl { get; set; } + public string ImageUrl { get; set; } - public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); - } -} + public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); +} \ No newline at end of file diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/PizzaTopping.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/PizzaTopping.cs index f5a6c1ac..0a711647 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/PizzaTopping.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/PizzaTopping.cs @@ -1,11 +1,11 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class PizzaTopping { - public class PizzaTopping - { - public Topping Topping { get; set; } + public Topping Topping { get; set; } + + public int ToppingId { get; set; } - public int ToppingId { get; set; } - - public int PizzaId { get; set; } - } -} + public int PizzaId { get; set; } + +} \ No newline at end of file diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Topping.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Topping.cs index 61bdeb92..376c311a 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Topping.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Topping.cs @@ -1,13 +1,13 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class Topping { - public class Topping - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal Price { get; set; } + public decimal Price { get; set; } - public string GetFormattedPrice() => Price.ToString("0.00"); - } -} + public string GetFormattedPrice() => Price.ToString("0.00"); + +} \ No newline at end of file diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/UserInfo.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/UserInfo.cs index 4996ef80..362f8f8e 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/UserInfo.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/UserInfo.cs @@ -1,9 +1,9 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class UserInfo { - public class UserInfo - { - public bool IsAuthenticated { get; set; } + public bool IsAuthenticated { get; set; } - public string Name { get; set; } - } -} + public string Name { get; set; } + +} \ No newline at end of file diff --git a/save-points/07-javascript-interop/BlazingPizza.Client/BlazingPizza.Client.csproj b/save-points/07-javascript-interop/BlazingPizza.Client/BlazingPizza.Client.csproj index 663677a1..44802d79 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/save-points/07-javascript-interop/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -2,16 +2,19 @@ $(TargetFrameworkVersion) + true + - + + diff --git a/save-points/07-javascript-interop/BlazingPizza.Client/JSRuntimeExtensions.cs b/save-points/07-javascript-interop/BlazingPizza.Client/JSRuntimeExtensions.cs index 89da520c..cc242348 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Client/JSRuntimeExtensions.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Client/JSRuntimeExtensions.cs @@ -1,13 +1,11 @@ using Microsoft.JSInterop; -using System.Threading.Tasks; -namespace BlazingPizza.Client +namespace BlazingPizza.Client; + +public static class JSRuntimeExtensions { - public static class JSRuntimeExtensions - { - public static ValueTask Confirm(this IJSRuntime jsRuntime, string message) - { - return jsRuntime.InvokeAsync("confirm", message); - } - } + public static ValueTask Confirm(this IJSRuntime jsRuntime, string message) + { + return jsRuntime.InvokeAsync("confirm", message); + } } diff --git a/save-points/07-javascript-interop/BlazingPizza.Client/OrderState.cs b/save-points/07-javascript-interop/BlazingPizza.Client/OrderState.cs index 5265ae39..4f47979d 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Client/OrderState.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Client/OrderState.cs @@ -1,55 +1,52 @@ -using System.Collections.Generic; +namespace BlazingPizza.Client; -namespace BlazingPizza.Client +public class OrderState { - public class OrderState - { - public bool ShowingConfigureDialog { get; private set; } - - public Pizza ConfiguringPizza { get; private set; } - - public Order Order { get; private set; } = new Order(); - - public void ShowConfigurePizzaDialog(PizzaSpecial special) - { - ConfiguringPizza = new Pizza() - { - Special = special, - SpecialId = special.Id, - Size = Pizza.DefaultSize, - Toppings = new List(), - }; - - ShowingConfigureDialog = true; - } - - public void CancelConfigurePizzaDialog() - { - ConfiguringPizza = null; - ShowingConfigureDialog = false; - } - - public void ConfirmConfigurePizzaDialog() - { - Order.Pizzas.Add(ConfiguringPizza); - ConfiguringPizza = null; - - ShowingConfigureDialog = false; - } - - public void RemoveConfiguredPizza(Pizza pizza) - { - Order.Pizzas.Remove(pizza); - } - - public void ResetOrder() - { - Order = new Order(); - } - - public void ReplaceOrder(Order order) - { - Order = order; - } - } + public bool ShowingConfigureDialog { get; private set; } + + public Pizza ConfiguringPizza { get; private set; } + + public Order Order { get; private set; } = new Order(); + + public void ShowConfigurePizzaDialog(PizzaSpecial special) + { + ConfiguringPizza = new Pizza() + { + Special = special, + SpecialId = special.Id, + Size = Pizza.DefaultSize, + Toppings = new List(), + }; + + ShowingConfigureDialog = true; + } + + public void CancelConfigurePizzaDialog() + { + ConfiguringPizza = null; + ShowingConfigureDialog = false; + } + + public void ConfirmConfigurePizzaDialog() + { + Order.Pizzas.Add(ConfiguringPizza); + ConfiguringPizza = null; + + ShowingConfigureDialog = false; + } + + public void RemoveConfiguredPizza(Pizza pizza) + { + Order.Pizzas.Remove(pizza); + } + + public void ResetOrder() + { + Order = new Order(); + } + + public void ReplaceOrder(Order order) + { + Order = order; + } } diff --git a/save-points/07-javascript-interop/BlazingPizza.Client/OrdersClient.cs b/save-points/07-javascript-interop/BlazingPizza.Client/OrdersClient.cs index 0f800e6f..e63bd045 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Client/OrdersClient.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Client/OrdersClient.cs @@ -1,35 +1,36 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Net.Http.Json; -using System.Threading.Tasks; - -namespace BlazingPizza.Client +using System.Net.Http.Json; +using System.Text.Json; + +namespace BlazingPizza.Client; + +public class OrdersClient { - public class OrdersClient - { - private readonly HttpClient httpClient; + private readonly HttpClient httpClient; + + public OrdersClient(HttpClient httpClient) + { + this.httpClient = httpClient; + } - public OrdersClient(HttpClient httpClient) - { - this.httpClient = httpClient; - } + public async Task> GetOrders() => + await httpClient.GetFromJsonAsync("orders", OrderContext.Default.ListOrderWithStatus); - public async Task> GetOrders() => - await httpClient.GetFromJsonAsync>("orders"); + public async Task GetOrder(int orderId) => + await httpClient.GetFromJsonAsync($"orders/{orderId}", OrderContext.Default.OrderWithStatus); - public async Task GetOrder(int orderId) => - await httpClient.GetFromJsonAsync($"orders/{orderId}"); + public async Task PlaceOrder(Order order) + { + var response = await httpClient.PostAsJsonAsync("orders", order, OrderContext.Default.Order); + response.EnsureSuccessStatusCode(); + var orderId = await response.Content.ReadFromJsonAsync(); + return orderId; + } - public async Task PlaceOrder(Order order) - { - var response = await httpClient.PostAsJsonAsync("orders", order); - response.EnsureSuccessStatusCode(); - var orderId = await response.Content.ReadFromJsonAsync(); - return orderId; - } - } -} \ No newline at end of file + public async Task SubscribeToNotifications(NotificationSubscription subscription) + { + var response = await httpClient.PutAsJsonAsync("notifications/subscribe", subscription); + response.EnsureSuccessStatusCode(); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Client/PizzaAuthenticationState.cs b/save-points/07-javascript-interop/BlazingPizza.Client/PizzaAuthenticationState.cs index 3f295928..f5bfef65 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Client/PizzaAuthenticationState.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Client/PizzaAuthenticationState.cs @@ -1,9 +1,8 @@ using Microsoft.AspNetCore.Components.WebAssembly.Authentication; -namespace BlazingPizza.Client +namespace BlazingPizza.Client; + +public class PizzaAuthenticationState : RemoteAuthenticationState { - public class PizzaAuthenticationState : RemoteAuthenticationState - { - public Order Order { get; set; } - } + public Order Order { get; set; } } diff --git a/save-points/07-javascript-interop/BlazingPizza.Client/Program.cs b/save-points/07-javascript-interop/BlazingPizza.Client/Program.cs index afeee128..41eedccb 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Client/Program.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Client/Program.cs @@ -1,31 +1,20 @@ using Microsoft.AspNetCore.Components.WebAssembly.Authentication; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; using Microsoft.Extensions.DependencyInjection; -using System; -using System.Net.Http; -using System.Threading.Tasks; +using BlazingPizza.Client; -namespace BlazingPizza.Client -{ - public class Program - { - public static async Task Main(string[] args) - { - var builder = WebAssemblyHostBuilder.CreateDefault(args); - builder.RootComponents.Add("#app"); +var builder = WebAssemblyHostBuilder.CreateDefault(args); +builder.RootComponents.Add("#app"); - builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); - builder.Services.AddHttpClient(client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)) - .AddHttpMessageHandler(); - builder.Services.AddScoped(); +builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); +builder.Services.AddHttpClient(client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)) + .AddHttpMessageHandler(); +builder.Services.AddScoped(); - // Add auth services - builder.Services.AddApiAuthorization(options => - { - options.AuthenticationPaths.LogOutSucceededPath = ""; - }); +// Add auth services +builder.Services.AddApiAuthorization(options => +{ + options.AuthenticationPaths.LogOutSucceededPath = ""; +}); - await builder.Build().RunAsync(); - } - } -} +await builder.Build().RunAsync(); diff --git a/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 61ebf623..cb996b1b 100644 --- a/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -2,6 +2,7 @@ $(TargetFrameworkVersion) + true diff --git a/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/LocalStorage.cs b/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/LocalStorage.cs index f36b098e..bb84f13c 100644 --- a/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/LocalStorage.cs +++ b/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/LocalStorage.cs @@ -1,17 +1,15 @@ using Microsoft.JSInterop; -using System.Threading.Tasks; -namespace BlazingPizza.ComponentsLibrary +namespace BlazingPizza.ComponentsLibrary; + +public static class LocalStorage { - public static class LocalStorage - { - public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) - => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); + public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) + => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); - public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object value) - => jsRuntime.InvokeVoidAsync("blazorLocalStorage.set", key, value); + public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object value) + => jsRuntime.InvokeVoidAsync("blazorLocalStorage.set", key, value); - public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key) - => jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key); - } -} + public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key) + => jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key); +} \ No newline at end of file diff --git a/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/Map/Marker.cs b/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/Map/Marker.cs index 63006067..a8e78f2a 100644 --- a/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/Map/Marker.cs +++ b/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/Map/Marker.cs @@ -1,13 +1,12 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Marker { - public class Marker - { - public string Description { get; set; } + public string Description { get; set; } - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } + public double Y { get; set; } - public bool ShowPopup { get; set; } - } + public bool ShowPopup { get; set; } } diff --git a/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/Map/Point.cs b/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/Map/Point.cs index 03841826..349046d4 100644 --- a/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/Map/Point.cs +++ b/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/Map/Point.cs @@ -1,9 +1,8 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Point { - public class Point - { - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } - } -} + public double Y { get; set; } +} \ No newline at end of file diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/BlazingPizza.Server.csproj b/save-points/07-javascript-interop/BlazingPizza.Server/BlazingPizza.Server.csproj index b9c74fc4..abd2317b 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/save-points/07-javascript-interop/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -2,6 +2,7 @@ $(TargetFrameworkVersion) + true @@ -13,6 +14,7 @@ + diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/AddressEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/AddressEntityType.cs new file mode 100644 index 00000000..82db81b6 --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/AddressEntityType.cs @@ -0,0 +1,92 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class AddressEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Address", + typeof(Address), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Address).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var city = runtimeEntityType.AddProperty( + "City", + typeof(string), + propertyInfo: typeof(Address).GetProperty("City", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var line1 = runtimeEntityType.AddProperty( + "Line1", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line1", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var line2 = runtimeEntityType.AddProperty( + "Line2", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line2", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var postalCode = runtimeEntityType.AddProperty( + "PostalCode", + typeof(string), + propertyInfo: typeof(Address).GetProperty("PostalCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var region = runtimeEntityType.AddProperty( + "Region", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Region", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Address"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs new file mode 100644 index 00000000..1dd4563b --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs @@ -0,0 +1,114 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class DeviceFlowCodesEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.DeviceFlowCodes", + typeof(DeviceFlowCodes), + baseEntityType); + + var userCode = runtimeEntityType.AddProperty( + "UserCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("UserCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var deviceCode = runtimeEntityType.AddProperty( + "DeviceCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("DeviceCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var key = runtimeEntityType.AddKey( + new[] { userCode }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deviceCode }, + unique: true); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "DeviceCodes"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs new file mode 100644 index 00000000..8946b261 --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRoleClaim", + typeof(IdentityRoleClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoleClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityRoleEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityRoleEntityType.cs new file mode 100644 index 00000000..2f1fec2b --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityRoleEntityType.cs @@ -0,0 +1,78 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRole", + typeof(IdentityRole), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedName = runtimeEntityType.AddProperty( + "NormalizedName", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("NormalizedName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedName }, + unique: true); + index.AddAnnotation("Relational:Name", "RoleNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs new file mode 100644 index 00000000..55418a1e --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserClaim", + typeof(IdentityUserClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityUserClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs new file mode 100644 index 00000000..3ca029bd --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserLoginstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserLogin", + typeof(IdentityUserLogin), + baseEntityType); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerKey = runtimeEntityType.AddProperty( + "ProviderKey", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderKey", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerDisplayName = runtimeEntityType.AddProperty( + "ProviderDisplayName", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderDisplayName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { loginProvider, providerKey }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserLogins"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs new file mode 100644 index 00000000..70078d7a --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs @@ -0,0 +1,82 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserRolestringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserRole", + typeof(IdentityUserRole), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { userId, roleId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs new file mode 100644 index 00000000..93ba6d31 --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs @@ -0,0 +1,84 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserTokenstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserToken", + typeof(IdentityUserToken), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var value = runtimeEntityType.AddProperty( + "Value", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Value", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { userId, loginProvider, name }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserTokens"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/KeyEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/KeyEntityType.cs new file mode 100644 index 00000000..f6c6b4c7 --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/KeyEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class KeyEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.Key", + typeof(Key), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var algorithm = runtimeEntityType.AddProperty( + "Algorithm", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Algorithm", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var created = runtimeEntityType.AddProperty( + "Created", + typeof(DateTime), + propertyInfo: typeof(Key).GetProperty("Created", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var dataProtected = runtimeEntityType.AddProperty( + "DataProtected", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("DataProtected", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var isX509Certificate = runtimeEntityType.AddProperty( + "IsX509Certificate", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("IsX509Certificate", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var use = runtimeEntityType.AddProperty( + "Use", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Use", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var version = runtimeEntityType.AddProperty( + "Version", + typeof(int), + propertyInfo: typeof(Key).GetProperty("Version", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { use }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Keys"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/LatLongEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/LatLongEntityType.cs new file mode 100644 index 00000000..3fd254bd --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/LatLongEntityType.cs @@ -0,0 +1,80 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class LatLongEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.LatLong", + typeof(LatLong), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var latitude = runtimeEntityType.AddProperty( + "Latitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Latitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var longitude = runtimeEntityType.AddProperty( + "Longitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Longitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + unique: true, + required: true, + ownership: true); + + var deliveryLocation = principalEntityType.AddNavigation("DeliveryLocation", + runtimeForeignKey, + onDependent: false, + typeof(LatLong), + propertyInfo: typeof(Order).GetProperty("DeliveryLocation", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + eagerLoaded: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs new file mode 100644 index 00000000..db236e4c --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs @@ -0,0 +1,77 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class NotificationSubscriptionEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.NotificationSubscription", + typeof(NotificationSubscription), + baseEntityType); + + var notificationSubscriptionId = runtimeEntityType.AddProperty( + "NotificationSubscriptionId", + typeof(int), + propertyInfo: typeof(NotificationSubscription).GetProperty("NotificationSubscriptionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var auth = runtimeEntityType.AddProperty( + "Auth", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Auth", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var p256dh = runtimeEntityType.AddProperty( + "P256dh", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("P256dh", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var url = runtimeEntityType.AddProperty( + "Url", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Url", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { notificationSubscriptionId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "NotificationSubscriptions"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/OrderEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/OrderEntityType.cs new file mode 100644 index 00000000..9d9ec6fd --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/OrderEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class OrderEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Order", + typeof(Order), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Order).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var createdTime = runtimeEntityType.AddProperty( + "CreatedTime", + typeof(DateTime), + propertyInfo: typeof(Order).GetProperty("CreatedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var deliveryAddressId = runtimeEntityType.AddProperty( + "DeliveryAddressId", + typeof(int?), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(Order).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deliveryAddressId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("DeliveryAddressId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType); + + var deliveryAddress = declaringEntityType.AddNavigation("DeliveryAddress", + runtimeForeignKey, + onDependent: true, + typeof(Address), + propertyInfo: typeof(Order).GetProperty("DeliveryAddress", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/PersistedGrantEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/PersistedGrantEntityType.cs new file mode 100644 index 00000000..842d53a5 --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/PersistedGrantEntityType.cs @@ -0,0 +1,127 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PersistedGrantEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.PersistedGrant", + typeof(PersistedGrant), + baseEntityType); + + var key = runtimeEntityType.AddProperty( + "Key", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Key", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var consumedTime = runtimeEntityType.AddProperty( + "ConsumedTime", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("ConsumedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(PersistedGrant).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var type = runtimeEntityType.AddProperty( + "Type", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Type", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var key0 = runtimeEntityType.AddKey( + new[] { key }); + runtimeEntityType.SetPrimaryKey(key0); + + var index = runtimeEntityType.AddIndex( + new[] { consumedTime }); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + var index1 = runtimeEntityType.AddIndex( + new[] { subjectId, clientId, type }); + + var index2 = runtimeEntityType.AddIndex( + new[] { subjectId, sessionId, type }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PersistedGrants"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaEntityType.cs new file mode 100644 index 00000000..3a124e63 --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaEntityType.cs @@ -0,0 +1,111 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Pizza", + typeof(Pizza), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var size = runtimeEntityType.AddProperty( + "Size", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Size", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var specialId = runtimeEntityType.AddProperty( + "SpecialId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("SpecialId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { orderId }); + + var index0 = runtimeEntityType.AddIndex( + new[] { specialId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var pizzas = principalEntityType.AddNavigation("Pizzas", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Order).GetProperty("Pizzas", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("SpecialId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var special = declaringEntityType.AddNavigation("Special", + runtimeForeignKey, + onDependent: true, + typeof(PizzaSpecial), + propertyInfo: typeof(Pizza).GetProperty("Special", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Pizzas"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs new file mode 100644 index 00000000..e86b0f50 --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs @@ -0,0 +1,76 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaSpecialEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaSpecial", + typeof(PizzaSpecial), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(PizzaSpecial).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var basePrice = runtimeEntityType.AddProperty( + "BasePrice", + typeof(decimal), + propertyInfo: typeof(PizzaSpecial).GetProperty("BasePrice", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var imageUrl = runtimeEntityType.AddProperty( + "ImageUrl", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("ImageUrl", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Specials"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaStoreContextModel.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaStoreContextModel.cs new file mode 100644 index 00000000..8b516a68 --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaStoreContextModel.cs @@ -0,0 +1,28 @@ +// +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + [DbContext(typeof(PizzaStoreContext))] + public partial class PizzaStoreContextModel : RuntimeModel + { + static PizzaStoreContextModel() + { + var model = new PizzaStoreContextModel(); + model.Initialize(); + model.Customize(); + _instance = model; + } + + private static PizzaStoreContextModel _instance; + public static IModel Instance => _instance; + + partial void Initialize(); + + partial void Customize(); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs new file mode 100644 index 00000000..d46f50f4 --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs @@ -0,0 +1,69 @@ +// +using System; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + public partial class PizzaStoreContextModel + { + partial void Initialize() + { + var address = AddressEntityType.Create(this); + var latLong = LatLongEntityType.Create(this); + var notificationSubscription = NotificationSubscriptionEntityType.Create(this); + var order = OrderEntityType.Create(this); + var pizza = PizzaEntityType.Create(this); + var pizzaSpecial = PizzaSpecialEntityType.Create(this); + var pizzaTopping = PizzaToppingEntityType.Create(this); + var pizzaStoreUser = PizzaStoreUserEntityType.Create(this); + var topping = ToppingEntityType.Create(this); + var deviceFlowCodes = DeviceFlowCodesEntityType.Create(this); + var key = KeyEntityType.Create(this); + var persistedGrant = PersistedGrantEntityType.Create(this); + var identityRole = IdentityRoleEntityType.Create(this); + var identityRoleClaimstring = IdentityRoleClaimstringEntityType.Create(this); + var identityUserClaimstring = IdentityUserClaimstringEntityType.Create(this); + var identityUserLoginstring = IdentityUserLoginstringEntityType.Create(this); + var identityUserRolestring = IdentityUserRolestringEntityType.Create(this); + var identityUserTokenstring = IdentityUserTokenstringEntityType.Create(this); + + LatLongEntityType.CreateForeignKey1(latLong, order); + OrderEntityType.CreateForeignKey1(order, address); + PizzaEntityType.CreateForeignKey1(pizza, order); + PizzaEntityType.CreateForeignKey2(pizza, pizzaSpecial); + PizzaToppingEntityType.CreateForeignKey1(pizzaTopping, pizza); + PizzaToppingEntityType.CreateForeignKey2(pizzaTopping, topping); + IdentityRoleClaimstringEntityType.CreateForeignKey1(identityRoleClaimstring, identityRole); + IdentityUserClaimstringEntityType.CreateForeignKey1(identityUserClaimstring, pizzaStoreUser); + IdentityUserLoginstringEntityType.CreateForeignKey1(identityUserLoginstring, pizzaStoreUser); + IdentityUserRolestringEntityType.CreateForeignKey1(identityUserRolestring, identityRole); + IdentityUserRolestringEntityType.CreateForeignKey2(identityUserRolestring, pizzaStoreUser); + IdentityUserTokenstringEntityType.CreateForeignKey1(identityUserTokenstring, pizzaStoreUser); + + AddressEntityType.CreateAnnotations(address); + LatLongEntityType.CreateAnnotations(latLong); + NotificationSubscriptionEntityType.CreateAnnotations(notificationSubscription); + OrderEntityType.CreateAnnotations(order); + PizzaEntityType.CreateAnnotations(pizza); + PizzaSpecialEntityType.CreateAnnotations(pizzaSpecial); + PizzaToppingEntityType.CreateAnnotations(pizzaTopping); + PizzaStoreUserEntityType.CreateAnnotations(pizzaStoreUser); + ToppingEntityType.CreateAnnotations(topping); + DeviceFlowCodesEntityType.CreateAnnotations(deviceFlowCodes); + KeyEntityType.CreateAnnotations(key); + PersistedGrantEntityType.CreateAnnotations(persistedGrant); + IdentityRoleEntityType.CreateAnnotations(identityRole); + IdentityRoleClaimstringEntityType.CreateAnnotations(identityRoleClaimstring); + IdentityUserClaimstringEntityType.CreateAnnotations(identityUserClaimstring); + IdentityUserLoginstringEntityType.CreateAnnotations(identityUserLoginstring); + IdentityUserRolestringEntityType.CreateAnnotations(identityUserRolestring); + IdentityUserTokenstringEntityType.CreateAnnotations(identityUserTokenstring); + + AddAnnotation("ProductVersion", "6.0.0"); + } + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs new file mode 100644 index 00000000..18b2d96d --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs @@ -0,0 +1,156 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaStoreUserEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Server.PizzaStoreUser", + typeof(PizzaStoreUser), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var accessFailedCount = runtimeEntityType.AddProperty( + "AccessFailedCount", + typeof(int), + propertyInfo: typeof(IdentityUser).GetProperty("AccessFailedCount", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var email = runtimeEntityType.AddProperty( + "Email", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Email", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var emailConfirmed = runtimeEntityType.AddProperty( + "EmailConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("EmailConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnabled = runtimeEntityType.AddProperty( + "LockoutEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnd = runtimeEntityType.AddProperty( + "LockoutEnd", + typeof(DateTimeOffset?), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnd", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var normalizedEmail = runtimeEntityType.AddProperty( + "NormalizedEmail", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedEmail", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedUserName = runtimeEntityType.AddProperty( + "NormalizedUserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedUserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var passwordHash = runtimeEntityType.AddProperty( + "PasswordHash", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PasswordHash", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumber = runtimeEntityType.AddProperty( + "PhoneNumber", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumber", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumberConfirmed = runtimeEntityType.AddProperty( + "PhoneNumberConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumberConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var securityStamp = runtimeEntityType.AddProperty( + "SecurityStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("SecurityStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var twoFactorEnabled = runtimeEntityType.AddProperty( + "TwoFactorEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("TwoFactorEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var userName = runtimeEntityType.AddProperty( + "UserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("UserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedEmail }); + index.AddAnnotation("Relational:Name", "EmailIndex"); + + var index0 = runtimeEntityType.AddIndex( + new[] { normalizedUserName }, + unique: true); + index0.AddAnnotation("Relational:Name", "UserNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUsers"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaToppingEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaToppingEntityType.cs new file mode 100644 index 00000000..b97d2a24 --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaToppingEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaTopping", + typeof(PizzaTopping), + baseEntityType); + + var pizzaId = runtimeEntityType.AddProperty( + "PizzaId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("PizzaId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var toppingId = runtimeEntityType.AddProperty( + "ToppingId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("ToppingId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { pizzaId, toppingId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { toppingId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("PizzaId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var toppings = principalEntityType.AddNavigation("Toppings", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Pizza).GetProperty("Toppings", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("ToppingId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var topping = declaringEntityType.AddNavigation("Topping", + runtimeForeignKey, + onDependent: true, + typeof(Topping), + propertyInfo: typeof(PizzaTopping).GetProperty("Topping", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PizzaTopping"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/ToppingEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/ToppingEntityType.cs new file mode 100644 index 00000000..9295f9bf --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/ToppingEntityType.cs @@ -0,0 +1,62 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class ToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Topping", + typeof(Topping), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Topping).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Topping).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var price = runtimeEntityType.AddProperty( + "Price", + typeof(decimal), + propertyInfo: typeof(Topping).GetProperty("Price", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Toppings"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/NotificationsController.cs b/save-points/07-javascript-interop/BlazingPizza.Server/NotificationsController.cs deleted file mode 100644 index bb3b96ff..00000000 --- a/save-points/07-javascript-interop/BlazingPizza.Server/NotificationsController.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("notifications")] - [ApiController] - [Authorize] - public class NotificationsController : Controller - { - private readonly PizzaStoreContext _db; - - public NotificationsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpPut("subscribe")] - public async Task Subscribe(NotificationSubscription subscription) - { - // We're storing at most one subscription per user, so delete old ones. - // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. - var userId = GetUserId(); - var oldSubscriptions = _db.NotificationSubscriptions.Where(e => e.UserId == userId); - _db.NotificationSubscriptions.RemoveRange(oldSubscriptions); - - // Store new subscription - subscription.UserId = userId; - _db.NotificationSubscriptions.Attach(subscription); - - await _db.SaveChangesAsync(); - return subscription; - } - - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } - } -} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/OidcConfigurationController.cs b/save-points/07-javascript-interop/BlazingPizza.Server/OidcConfigurationController.cs index c074debf..dc75ecb3 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Server/OidcConfigurationController.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Server/OidcConfigurationController.cs @@ -1,26 +1,21 @@ using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class OidcConfigurationController : Controller { - public class OidcConfigurationController : Controller - { - public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) - { - ClientRequestParametersProvider = clientRequestParametersProvider; - } + public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) + { + ClientRequestParametersProvider = clientRequestParametersProvider; + } - public IClientRequestParametersProvider ClientRequestParametersProvider { get; } + public IClientRequestParametersProvider ClientRequestParametersProvider { get; } - [HttpGet("_configuration/{clientId}")] - public IActionResult GetClientRequestParameters([FromRoute]string clientId) - { - var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); - return Ok(parameters); - } - } + [HttpGet("_configuration/{clientId}")] + public IActionResult GetClientRequestParameters([FromRoute] string clientId) + { + var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); + return Ok(parameters); + } } diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/OrdersController.cs b/save-points/07-javascript-interop/BlazingPizza.Server/OrdersController.cs index 72b59890..1859decd 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Server/OrdersController.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Server/OrdersController.cs @@ -1,115 +1,130 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; +using System.Security.Claims; +using System.Text.Json; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using WebPush; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +[Route("orders")] +[ApiController] +[Authorize] +public class OrdersController : Controller { - [Route("orders")] - [ApiController] - [Authorize] - public class OrdersController : Controller - { - private readonly PizzaStoreContext _db; - - public OrdersController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetOrders() - { - var orders = await _db.Orders - .Where(o => o.UserId == GetUserId()) - .Include(o => o.DeliveryLocation) - .Include(o => o.Pizzas).ThenInclude(p => p.Special) - .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) - .OrderByDescending(o => o.CreatedTime) - .ToListAsync(); - - return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); - } - - [HttpGet("{orderId}")] - public async Task> GetOrderWithStatus(int orderId) - { - var order = await _db.Orders - .Where(o => o.OrderId == orderId) - .Where(o => o.UserId == GetUserId()) - .Include(o => o.DeliveryLocation) - .Include(o => o.Pizzas).ThenInclude(p => p.Special) - .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) - .SingleOrDefaultAsync(); - - if (order == null) - { - return NotFound(); - } - - return OrderWithStatus.FromOrder(order); - } - - [HttpPost] - public async Task> PlaceOrder(Order order) - { - order.CreatedTime = DateTime.Now; - order.DeliveryLocation = new LatLong(51.5001, -0.1239); - order.UserId = GetUserId(); - - // Enforce existence of Pizza.SpecialId and Topping.ToppingId - // in the database - prevent the submitter from making up - // new specials and toppings - foreach (var pizza in order.Pizzas) - { - pizza.SpecialId = pizza.Special.Id; - pizza.Special = null; - - foreach (var topping in pizza.Toppings) - { - topping.ToppingId = topping.Topping.Id; - topping.Topping = null; - } - } - - _db.Orders.Attach(order); - await _db.SaveChangesAsync(); - - // In the background, send push notifications if possible - var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); - if (subscription != null) - { - _ = TrackAndSendNotificationsAsync(order, subscription); - } - - return order.OrderId; - } - - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } - - private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription subscription) - { - // In a realistic case, some other backend process would track - // order delivery progress and send us notifications when it - // changes. Since we don't have any such process here, fake it. - await Task.Delay(OrderWithStatus.PreparationDuration); - await SendNotificationAsync(order, subscription, "Your order has been dispatched!"); - - await Task.Delay(OrderWithStatus.DeliveryDuration); - await SendNotificationAsync(order, subscription, "Your order is now delivered. Enjoy!"); - } - - private static Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) - { - // This will be implemented later - return Task.CompletedTask; - } - } + private readonly PizzaStoreContext _db; + + public OrdersController(PizzaStoreContext db) + { + _db = db; + } + + [HttpGet] + public async Task>> GetOrders() + { + var orders = await _db.Orders + .Where(o => o.UserId == GetUserId()) + .Include(o => o.DeliveryLocation) + .Include(o => o.Pizzas).ThenInclude(p => p.Special) + .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) + .OrderByDescending(o => o.CreatedTime) + .ToListAsync(); + + return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); + } + + [HttpGet("{orderId}")] + public async Task> GetOrderWithStatus(int orderId) + { + var order = await _db.Orders + .Where(o => o.OrderId == orderId) + .Where(o => o.UserId == GetUserId()) + .Include(o => o.DeliveryLocation) + .Include(o => o.Pizzas).ThenInclude(p => p.Special) + .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) + .SingleOrDefaultAsync(); + + if (order == null) + { + return NotFound(); + } + + return OrderWithStatus.FromOrder(order); + } + + [HttpPost] + public async Task> PlaceOrder(Order order) + { + order.CreatedTime = DateTime.Now; + order.DeliveryLocation = new LatLong(51.5001, -0.1239); + order.UserId = GetUserId(); + + // Enforce existence of Pizza.SpecialId and Topping.ToppingId + // in the database - prevent the submitter from making up + // new specials and toppings + foreach (var pizza in order.Pizzas) + { + pizza.SpecialId = pizza.Special.Id; + pizza.Special = null; + + foreach (var topping in pizza.Toppings) + { + topping.ToppingId = topping.Topping.Id; + topping.Topping = null; + } + } + + _db.Orders.Attach(order); + await _db.SaveChangesAsync(); + + // In the background, send push notifications if possible + var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); + if (subscription != null) + { + _ = TrackAndSendNotificationsAsync(order, subscription); + } + + return order.OrderId; + } + + private string GetUserId() + { + return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); + } + + private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription subscription) + { + // In a realistic case, some other backend process would track + // order delivery progress and send us notifications when it + // changes. Since we don't have any such process here, fake it. + await Task.Delay(OrderWithStatus.PreparationDuration); + await SendNotificationAsync(order, subscription, "Your order has been dispatched!"); + + await Task.Delay(OrderWithStatus.DeliveryDuration); + await SendNotificationAsync(order, subscription, "Your order is now delivered. Enjoy!"); + } + + private static async Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) + { + // For a real application, generate your own + var publicKey = "BLC8GOevpcpjQiLkO7JmVClQjycvTCYWm6Cq_a7wJZlstGTVZvwGFFHMYfXt6Njyvgx_GlXJeo5cSiZ1y4JOx1o"; + var privateKey = "OrubzSz3yWACscZXjFQrrtDwCKg-TGFuWhluQ2wLXDo"; + + var pushSubscription = new PushSubscription(subscription.Url, subscription.P256dh, subscription.Auth); + var vapidDetails = new VapidDetails("mailto:", publicKey, privateKey); + var webPushClient = new WebPushClient(); + try + { + var payload = JsonSerializer.Serialize(new + { + message, + url = $"myorders/{order.OrderId}", + }); + await webPushClient.SendNotificationAsync(pushSubscription, payload, vapidDetails); + } + catch (Exception ex) + { + Console.Error.WriteLine("Error sending push notification: " + ex.Message); + } + } } diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/PizzaApiExtensions.cs b/save-points/07-javascript-interop/BlazingPizza.Server/PizzaApiExtensions.cs new file mode 100644 index 00000000..bf6b7bde --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/PizzaApiExtensions.cs @@ -0,0 +1,60 @@ +using System.Security.Claims; +using Microsoft.AspNetCore.Authorization; +using Microsoft.EntityFrameworkCore; + +namespace BlazingPizza.Server; + +public static class PizzaApiExtensions +{ + + public static WebApplication MapPizzaApi(this WebApplication app) + { + + // Subscribe to notifications + app.MapPut("/notifications/subscribe", [Authorize] async ( + HttpContext context, + PizzaStoreContext db, + NotificationSubscription subscription) => + { + + // We're storing at most one subscription per user, so delete old ones. + // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. + var userId = GetUserId(context); + var oldSubscriptions = db.NotificationSubscriptions.Where(e => e.UserId == userId); + db.NotificationSubscriptions.RemoveRange(oldSubscriptions); + + // Store new subscription + subscription.UserId = userId; + db.NotificationSubscriptions.Attach(subscription); + + await db.SaveChangesAsync(); + return Results.Ok(subscription); + + }); + + // Specials + app.MapGet("/specials", async (PizzaStoreContext db) => + { + + var specials = await db.Specials.ToListAsync(); + return Results.Ok(specials); + + }); + + // Toppings + app.MapGet("/toppings", async (PizzaStoreContext db) => + { + var toppings = await db.Toppings.OrderBy(t => t.Name).ToListAsync(); + return Results.Ok(toppings); + }); + + return app; + + } + + private static string GetUserId(HttpContext context) + { + return context.User.FindFirstValue(ClaimTypes.NameIdentifier); + } + +} \ No newline at end of file diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/PizzaStoreContext.cs b/save-points/07-javascript-interop/BlazingPizza.Server/PizzaStoreContext.cs index 9485bd12..9a2e17ee 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Server/PizzaStoreContext.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Server/PizzaStoreContext.cs @@ -3,37 +3,36 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class PizzaStoreContext : ApiAuthorizationDbContext { - public class PizzaStoreContext : ApiAuthorizationDbContext - { - public PizzaStoreContext( - DbContextOptions options, - IOptions operationalStoreOptions) : base(options, operationalStoreOptions) - { - } + public PizzaStoreContext( + DbContextOptions options, + IOptions operationalStoreOptions) : base(options, operationalStoreOptions) + { + } - public DbSet Orders { get; set; } + public DbSet Orders { get; set; } - public DbSet Pizzas { get; set; } + public DbSet Pizzas { get; set; } - public DbSet Specials { get; set; } + public DbSet Specials { get; set; } - public DbSet Toppings { get; set; } + public DbSet Toppings { get; set; } - public DbSet NotificationSubscriptions { get; set; } + public DbSet NotificationSubscriptions { get; set; } - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - base.OnModelCreating(modelBuilder); + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); - // Configuring a many-to-many special -> topping relationship that is friendly for serialization - modelBuilder.Entity().HasKey(pst => new { pst.PizzaId, pst.ToppingId }); - modelBuilder.Entity().HasOne().WithMany(ps => ps.Toppings); - modelBuilder.Entity().HasOne(pst => pst.Topping).WithMany(); + // Configuring a many-to-many special -> topping relationship that is friendly for serialization + modelBuilder.Entity().HasKey(pst => new { pst.PizzaId, pst.ToppingId }); + modelBuilder.Entity().HasOne().WithMany(ps => ps.Toppings); + modelBuilder.Entity().HasOne(pst => pst.Topping).WithMany(); - // Inline the Lat-Long pairs in Order rather than having a FK to another table - modelBuilder.Entity().OwnsOne(o => o.DeliveryLocation); - } - } -} \ No newline at end of file + // Inline the Lat-Long pairs in Order rather than having a FK to another table + modelBuilder.Entity().OwnsOne(o => o.DeliveryLocation); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/PizzaStoreUser.cs b/save-points/07-javascript-interop/BlazingPizza.Server/PizzaStoreUser.cs index 171ce83d..7ab40235 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Server/PizzaStoreUser.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Server/PizzaStoreUser.cs @@ -1,8 +1,5 @@ using Microsoft.AspNetCore.Identity; -namespace BlazingPizza.Server -{ - public class PizzaStoreUser : IdentityUser - { - } -} \ No newline at end of file +namespace BlazingPizza.Server; + +public class PizzaStoreUser : IdentityUser { } \ No newline at end of file diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/PizzasController.cs b/save-points/07-javascript-interop/BlazingPizza.Server/PizzasController.cs deleted file mode 100644 index c082552c..00000000 --- a/save-points/07-javascript-interop/BlazingPizza.Server/PizzasController.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("pizzas")] - [ApiController] - public class PizzasController : Controller - { - private readonly PizzaStoreContext _db; - - public PizzasController(PizzaStoreContext db) - { - _db = db; - } - } -} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Program.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Program.cs index 40a47641..4484d8f7 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Server/Program.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Program.cs @@ -1,33 +1,67 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; +using Microsoft.AspNetCore.Authentication; +using Microsoft.EntityFrameworkCore; +using BlazingPizza.Server; -namespace BlazingPizza.Server +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddControllersWithViews() + .AddJsonOptions(options => { + options.JsonSerializerOptions.AddContext(); + }); +builder.Services.AddRazorPages(); + +builder.Services.AddDbContext(options => + options.UseSqlite("Data Source=pizza.db") + .UseModel(BlazingPizza.Server.Models.PizzaStoreContextModel.Instance)); + +builder.Services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) + .AddEntityFrameworkStores(); + +builder.Services.AddIdentityServer() + .AddApiAuthorization(); + +builder.Services.AddAuthentication() + .AddIdentityServerJwt(); + +var app = builder.Build(); + +// Initialize the database +var scopeFactory = app.Services.GetRequiredService(); +using (var scope = scopeFactory.CreateScope()) +{ + var db = scope.ServiceProvider.GetRequiredService(); + if (db.Database.EnsureCreated()) + { + SeedData.Initialize(db); + } +} + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseWebAssemblyDebugging(); +} +else { - public class Program - { - public static void Main(string[] args) - { - var host = CreateHostBuilder(args).Build(); - - // Initialize the database - var scopeFactory = host.Services.GetRequiredService(); - using (var scope = scopeFactory.CreateScope()) - { - var db = scope.ServiceProvider.GetRequiredService(); - if (db.Database.EnsureCreated()) - { - SeedData.Initialize(db); - } - } - - host.Run(); - } - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); - } + app.UseExceptionHandler("/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); } + +app.UseHttpsRedirection(); +app.UseBlazorFrameworkFiles(); +app.UseStaticFiles(); + +app.UseRouting(); + +app.UseAuthentication(); +app.UseIdentityServer(); +app.UseAuthorization(); + +app.MapPizzaApi(); + +app.MapRazorPages(); +app.MapControllers(); +app.MapFallbackToFile("index.html"); + +app.Run(); \ No newline at end of file diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/SeedData.cs b/save-points/07-javascript-interop/BlazingPizza.Server/SeedData.cs index 7c86a5b2..a1e47973 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Server/SeedData.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Server/SeedData.cs @@ -1,193 +1,192 @@ -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public static class SeedData { - public static class SeedData - { - public static void Initialize(PizzaStoreContext db) - { - var toppings = new Topping[] - { - new Topping() - { - Name = "Extra cheese", - Price = 2.50m, - }, - new Topping() - { - Name = "American bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "British bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "Canadian bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "Tea and crumpets", - Price = 5.00m - }, - new Topping() - { - Name = "Fresh-baked scones", - Price = 4.50m, - }, - new Topping() - { - Name = "Bell peppers", - Price = 1.00m, - }, - new Topping() - { - Name = "Onions", - Price = 1.00m, - }, - new Topping() - { - Name = "Mushrooms", - Price = 1.00m, - }, - new Topping() - { - Name = "Pepperoni", - Price = 1.00m, - }, - new Topping() - { - Name = "Duck sausage", - Price = 3.20m, - }, - new Topping() - { - Name = "Venison meatballs", - Price = 2.50m, - }, - new Topping() - { - Name = "Served on a silver platter", - Price = 250.99m, - }, - new Topping() - { - Name = "Lobster on top", - Price = 64.50m, - }, - new Topping() - { - Name = "Sturgeon caviar", - Price = 101.75m, - }, - new Topping() - { - Name = "Artichoke hearts", - Price = 3.40m, - }, - new Topping() - { - Name = "Fresh tomatoes", - Price = 1.50m, - }, - new Topping() - { - Name = "Basil", - Price = 1.50m, - }, - new Topping() - { - Name = "Steak (medium-rare)", - Price = 8.50m, - }, - new Topping() - { - Name = "Blazing hot peppers", - Price = 4.20m, - }, - new Topping() - { - Name = "Buffalo chicken", - Price = 5.00m, - }, - new Topping() - { - Name = "Blue cheese", - Price = 2.50m, - }, - }; + public static void Initialize(PizzaStoreContext db) + { + var toppings = new Topping[] + { + new Topping() + { + Name = "Extra cheese", + Price = 2.50m, + }, + new Topping() + { + Name = "American bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "British bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "Canadian bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "Tea and crumpets", + Price = 5.00m + }, + new Topping() + { + Name = "Fresh-baked scones", + Price = 4.50m, + }, + new Topping() + { + Name = "Bell peppers", + Price = 1.00m, + }, + new Topping() + { + Name = "Onions", + Price = 1.00m, + }, + new Topping() + { + Name = "Mushrooms", + Price = 1.00m, + }, + new Topping() + { + Name = "Pepperoni", + Price = 1.00m, + }, + new Topping() + { + Name = "Duck sausage", + Price = 3.20m, + }, + new Topping() + { + Name = "Venison meatballs", + Price = 2.50m, + }, + new Topping() + { + Name = "Served on a silver platter", + Price = 250.99m, + }, + new Topping() + { + Name = "Lobster on top", + Price = 64.50m, + }, + new Topping() + { + Name = "Sturgeon caviar", + Price = 101.75m, + }, + new Topping() + { + Name = "Artichoke hearts", + Price = 3.40m, + }, + new Topping() + { + Name = "Fresh tomatoes", + Price = 1.50m, + }, + new Topping() + { + Name = "Basil", + Price = 1.50m, + }, + new Topping() + { + Name = "Steak (medium-rare)", + Price = 8.50m, + }, + new Topping() + { + Name = "Blazing hot peppers", + Price = 4.20m, + }, + new Topping() + { + Name = "Buffalo chicken", + Price = 5.00m, + }, + new Topping() + { + Name = "Blue cheese", + Price = 2.50m, + }, + }; - var specials = new PizzaSpecial[] - { - new PizzaSpecial() - { - Name = "Basic Cheese Pizza", - Description = "It's cheesy and delicious. Why wouldn't you want one?", - BasePrice = 9.99m, - ImageUrl = "img/pizzas/cheese.jpg", - }, - new PizzaSpecial() - { - Id = 2, - Name = "The Baconatorizor", - Description = "It has EVERY kind of bacon", - BasePrice = 11.99m, - ImageUrl = "img/pizzas/bacon.jpg", - }, - new PizzaSpecial() - { - Id = 3, - Name = "Classic pepperoni", - Description = "It's the pizza you grew up with, but Blazing hot!", - BasePrice = 10.50m, - ImageUrl = "img/pizzas/pepperoni.jpg", - }, - new PizzaSpecial() - { - Id = 4, - Name = "Buffalo chicken", - Description = "Spicy chicken, hot sauce and bleu cheese, guaranteed to warm you up", - BasePrice = 12.75m, - ImageUrl = "img/pizzas/meaty.jpg", - }, - new PizzaSpecial() - { - Id = 5, - Name = "Mushroom Lovers", - Description = "It has mushrooms. Isn't that obvious?", - BasePrice = 11.00m, - ImageUrl = "img/pizzas/mushroom.jpg", - }, - new PizzaSpecial() - { - Id = 6, - Name = "The Brit", - Description = "When in London...", - BasePrice = 10.25m, - ImageUrl = "img/pizzas/brit.jpg", - }, - new PizzaSpecial() - { - Id = 7, - Name = "Veggie Delight", - Description = "It's like salad, but on a pizza", - BasePrice = 11.50m, - ImageUrl = "img/pizzas/salad.jpg", - }, - new PizzaSpecial() - { - Id = 8, - Name = "Margherita", - Description = "Traditional Italian pizza with tomatoes and basil", - BasePrice = 9.99m, - ImageUrl = "img/pizzas/margherita.jpg", - }, - }; + var specials = new PizzaSpecial[] + { + new PizzaSpecial() + { + Name = "Basic Cheese Pizza", + Description = "It's cheesy and delicious. Why wouldn't you want one?", + BasePrice = 9.99m, + ImageUrl = "img/pizzas/cheese.jpg", + }, + new PizzaSpecial() + { + Id = 2, + Name = "The Baconatorizor", + Description = "It has EVERY kind of bacon", + BasePrice = 11.99m, + ImageUrl = "img/pizzas/bacon.jpg", + }, + new PizzaSpecial() + { + Id = 3, + Name = "Classic pepperoni", + Description = "It's the pizza you grew up with, but Blazing hot!", + BasePrice = 10.50m, + ImageUrl = "img/pizzas/pepperoni.jpg", + }, + new PizzaSpecial() + { + Id = 4, + Name = "Buffalo chicken", + Description = "Spicy chicken, hot sauce and bleu cheese, guaranteed to warm you up", + BasePrice = 12.75m, + ImageUrl = "img/pizzas/meaty.jpg", + }, + new PizzaSpecial() + { + Id = 5, + Name = "Mushroom Lovers", + Description = "It has mushrooms. Isn't that obvious?", + BasePrice = 11.00m, + ImageUrl = "img/pizzas/mushroom.jpg", + }, + new PizzaSpecial() + { + Id = 6, + Name = "The Brit", + Description = "When in London...", + BasePrice = 10.25m, + ImageUrl = "img/pizzas/brit.jpg", + }, + new PizzaSpecial() + { + Id = 7, + Name = "Veggie Delight", + Description = "It's like salad, but on a pizza", + BasePrice = 11.50m, + ImageUrl = "img/pizzas/salad.jpg", + }, + new PizzaSpecial() + { + Id = 8, + Name = "Margherita", + Description = "Traditional Italian pizza with tomatoes and basil", + BasePrice = 9.99m, + ImageUrl = "img/pizzas/margherita.jpg", + }, + }; - db.Toppings.AddRange(toppings); - db.Specials.AddRange(specials); - db.SaveChanges(); - } - } -} + db.Toppings.AddRange(toppings); + db.Specials.AddRange(specials); + db.SaveChanges(); + } +} \ No newline at end of file diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/SpecialsController.cs b/save-points/07-javascript-interop/BlazingPizza.Server/SpecialsController.cs deleted file mode 100644 index a176844c..00000000 --- a/save-points/07-javascript-interop/BlazingPizza.Server/SpecialsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("specials")] - [ApiController] - public class SpecialsController : Controller - { - private readonly PizzaStoreContext _db; - - public SpecialsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetSpecials() - { - return (await _db.Specials.ToListAsync()).OrderByDescending(s => s.BasePrice).ToList(); - } - } -} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Startup.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Startup.cs deleted file mode 100644 index ed3fca06..00000000 --- a/save-points/07-javascript-interop/BlazingPizza.Server/Startup.cs +++ /dev/null @@ -1,70 +0,0 @@ -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace BlazingPizza.Server -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - public void ConfigureServices(IServiceCollection services) - { - services.AddControllersWithViews(); - services.AddRazorPages(); - - services.AddDbContext(options => - options.UseSqlite("Data Source=pizza.db")); - - services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) - .AddEntityFrameworkStores(); - - services.AddIdentityServer() - .AddApiAuthorization(); - - services.AddAuthentication() - .AddIdentityServerJwt(); - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - app.UseWebAssemblyDebugging(); - } - else - { - app.UseExceptionHandler("/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); - } - - app.UseHttpsRedirection(); - app.UseBlazorFrameworkFiles(); - app.UseStaticFiles(); - - app.UseRouting(); - - app.UseAuthentication(); - app.UseIdentityServer(); - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - endpoints.MapRazorPages(); - endpoints.MapFallbackToFile("index.html"); - }); - } - } -} \ No newline at end of file diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/ToppingsController.cs b/save-points/07-javascript-interop/BlazingPizza.Server/ToppingsController.cs deleted file mode 100644 index 6a677639..00000000 --- a/save-points/07-javascript-interop/BlazingPizza.Server/ToppingsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("toppings")] - [ApiController] - public class ToppingsController : Controller - { - private readonly PizzaStoreContext _db; - - public ToppingsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetToppings() - { - return await _db.Toppings.OrderBy(t => t.Name).ToListAsync(); - } - } -} diff --git a/save-points/07-javascript-interop/BlazingPizza.Shared/Address.cs b/save-points/07-javascript-interop/BlazingPizza.Shared/Address.cs index d76bc52a..79be9c5b 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Shared/Address.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Shared/Address.cs @@ -1,27 +1,24 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class Address { - public class Address - { - public int Id { get; set; } + public int Id { get; set; } - [Required, MaxLength(100)] - public string Name { get; set; } + [Required, MaxLength(100)] + public string Name { get; set; } - [Required, MaxLength(100)] - public string Line1 { get; set; } + [Required, MaxLength(100)] + public string Line1 { get; set; } - [MaxLength(100)] - public string Line2 { get; set; } + [MaxLength(100)] + public string Line2 { get; set; } - [Required, MaxLength(50)] - public string City { get; set; } + [Required, MaxLength(50)] + public string City { get; set; } - [Required, MaxLength(20)] - public string Region { get; set; } + [Required, MaxLength(20)] + public string Region { get; set; } - [Required, MaxLength(20)] - public string PostalCode { get; set; } - } + [Required, MaxLength(20)] + public string PostalCode { get; set; } } diff --git a/save-points/07-javascript-interop/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/save-points/07-javascript-interop/BlazingPizza.Shared/BlazingPizza.Shared.csproj index f7b7dd02..fb17e53b 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/save-points/07-javascript-interop/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -3,8 +3,13 @@ $(TargetFrameworkVersion) BlazingPizza + true + + + + diff --git a/save-points/07-javascript-interop/BlazingPizza.Shared/LatLong.cs b/save-points/07-javascript-interop/BlazingPizza.Shared/LatLong.cs index 9b8c3811..14a94c26 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Shared/LatLong.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Shared/LatLong.cs @@ -1,27 +1,26 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class LatLong { - public class LatLong - { - public LatLong() - { - } + public LatLong() + { + } - public LatLong(double latitude, double longitude) : this() - { - Latitude = latitude; - Longitude = longitude; - } + public LatLong(double latitude, double longitude) : this() + { + Latitude = latitude; + Longitude = longitude; + } - public double Latitude { get; set; } + public double Latitude { get; set; } - public double Longitude { get; set; } + public double Longitude { get; set; } - public static LatLong Interpolate(LatLong start, LatLong end, double proportion) - { - // The Earth is flat, right? So no need for spherical interpolation. - return new LatLong( - start.Latitude + (end.Latitude - start.Latitude) * proportion, - start.Longitude + (end.Longitude - start.Longitude) * proportion); - } - } -} + public static LatLong Interpolate(LatLong start, LatLong end, double proportion) + { + // The Earth is flat, right? So no need for spherical interpolation. + return new LatLong( + start.Latitude + (end.Latitude - start.Latitude) * proportion, + start.Longitude + (end.Longitude - start.Longitude) * proportion); + } +} \ No newline at end of file diff --git a/save-points/07-javascript-interop/BlazingPizza.Shared/NotificationSubscription.cs b/save-points/07-javascript-interop/BlazingPizza.Shared/NotificationSubscription.cs index 04259c2f..9109ff57 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Shared/NotificationSubscription.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Shared/NotificationSubscription.cs @@ -1,17 +1,14 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class NotificationSubscription { - public class NotificationSubscription - { - public int NotificationSubscriptionId { get; set; } + public int NotificationSubscriptionId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public string Url { get; set; } + public string Url { get; set; } - public string P256dh { get; set; } + public string P256dh { get; set; } - public string Auth { get; set; } - } + public string Auth { get; set; } } diff --git a/save-points/07-javascript-interop/BlazingPizza.Shared/Order.cs b/save-points/07-javascript-interop/BlazingPizza.Shared/Order.cs index fb003bd6..aca04ca1 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Shared/Order.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Shared/Order.cs @@ -1,25 +1,32 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +public class Order { - public class Order - { - public int OrderId { get; set; } + public int OrderId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public DateTime CreatedTime { get; set; } + public DateTime CreatedTime { get; set; } - public Address DeliveryAddress { get; set; } = new Address(); + public Address DeliveryAddress { get; set; } = new Address(); - public LatLong DeliveryLocation { get; set; } + public LatLong DeliveryLocation { get; set; } - public List Pizzas { get; set; } = new List(); + public List Pizzas { get; set; } = new List(); - public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); + public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); - public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); - } + public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Default, PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] +[JsonSerializable(typeof(Order))] +[JsonSerializable(typeof(OrderWithStatus))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Pizza))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Topping))] +public partial class OrderContext : JsonSerializerContext {} \ No newline at end of file diff --git a/save-points/07-javascript-interop/BlazingPizza.Shared/OrderWithStatus.cs b/save-points/07-javascript-interop/BlazingPizza.Shared/OrderWithStatus.cs index 021de78c..f5f153b6 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Shared/OrderWithStatus.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Shared/OrderWithStatus.cs @@ -1,79 +1,78 @@ -using BlazingPizza.ComponentsLibrary.Map; -using System; -using System.Collections.Generic; +using System.Text.Json.Serialization; +using BlazingPizza.ComponentsLibrary.Map; -namespace BlazingPizza + +namespace BlazingPizza; + +public class OrderWithStatus { - public class OrderWithStatus - { - public readonly static TimeSpan PreparationDuration = TimeSpan.FromSeconds(10); - public readonly static TimeSpan DeliveryDuration = TimeSpan.FromMinutes(1); // Unrealistic, but more interesting to watch + public readonly static TimeSpan PreparationDuration = TimeSpan.FromSeconds(10); + public readonly static TimeSpan DeliveryDuration = TimeSpan.FromMinutes(1); // Unrealistic, but more interesting to watch - public Order Order { get; set; } + public Order Order { get; set; } - public string StatusText { get; set; } + public string StatusText { get; set; } - public bool IsDelivered => StatusText == "Delivered"; + public bool IsDelivered => StatusText == "Delivered"; - public List MapMarkers { get; set; } + public List MapMarkers { get; set; } - public static OrderWithStatus FromOrder(Order order) - { - // To simulate a real backend process, we fake status updates based on the amount - // of time since the order was placed - string statusText; - List mapMarkers; - var dispatchTime = order.CreatedTime.Add(PreparationDuration); + public static OrderWithStatus FromOrder(Order order) + { + // To simulate a real backend process, we fake status updates based on the amount + // of time since the order was placed + string statusText; + List mapMarkers; + var dispatchTime = order.CreatedTime.Add(PreparationDuration); - if (DateTime.Now < dispatchTime) - { - statusText = "Preparing"; - mapMarkers = new List - { - ToMapMarker("You", order.DeliveryLocation, showPopup: true) - }; - } - else if (DateTime.Now < dispatchTime + DeliveryDuration) - { - statusText = "Out for delivery"; + if (DateTime.Now < dispatchTime) + { + statusText = "Preparing"; + mapMarkers = new List + { + ToMapMarker("You", order.DeliveryLocation, showPopup: true) + }; + } + else if (DateTime.Now < dispatchTime + DeliveryDuration) + { + statusText = "Out for delivery"; - var startPosition = ComputeStartPosition(order); - var proportionOfDeliveryCompleted = Math.Min(1, (DateTime.Now - dispatchTime).TotalMilliseconds / DeliveryDuration.TotalMilliseconds); - var driverPosition = LatLong.Interpolate(startPosition, order.DeliveryLocation, proportionOfDeliveryCompleted); - mapMarkers = new List - { - ToMapMarker("You", order.DeliveryLocation), - ToMapMarker("Driver", driverPosition, showPopup: true), - }; - } - else - { - statusText = "Delivered"; - mapMarkers = new List - { - ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), - }; - } + var startPosition = ComputeStartPosition(order); + var proportionOfDeliveryCompleted = Math.Min(1, (DateTime.Now - dispatchTime).TotalMilliseconds / DeliveryDuration.TotalMilliseconds); + var driverPosition = LatLong.Interpolate(startPosition, order.DeliveryLocation, proportionOfDeliveryCompleted); + mapMarkers = new List + { + ToMapMarker("You", order.DeliveryLocation), + ToMapMarker("Driver", driverPosition, showPopup: true), + }; + } + else + { + statusText = "Delivered"; + mapMarkers = new List + { + ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), + }; + } - return new OrderWithStatus - { - Order = order, - StatusText = statusText, - MapMarkers = mapMarkers, - }; - } + return new OrderWithStatus + { + Order = order, + StatusText = statusText, + MapMarkers = mapMarkers, + }; + } - private static LatLong ComputeStartPosition(Order order) - { - // Random but deterministic based on order ID - var rng = new Random(order.OrderId); - var distance = 0.01 + rng.NextDouble() * 0.02; - var angle = rng.NextDouble() * Math.PI * 2; - var offset = (distance * Math.Cos(angle), distance * Math.Sin(angle)); - return new LatLong(order.DeliveryLocation.Latitude + offset.Item1, order.DeliveryLocation.Longitude + offset.Item2); - } + private static LatLong ComputeStartPosition(Order order) + { + // Random but deterministic based on order ID + var rng = new Random(order.OrderId); + var distance = 0.01 + rng.NextDouble() * 0.02; + var angle = rng.NextDouble() * Math.PI * 2; + var offset = (distance * Math.Cos(angle), distance * Math.Sin(angle)); + return new LatLong(order.DeliveryLocation.Latitude + offset.Item1, order.DeliveryLocation.Longitude + offset.Item2); + } - static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) - => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; - } -} + static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) + => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; +} \ No newline at end of file diff --git a/save-points/07-javascript-interop/BlazingPizza.Shared/Pizza.cs b/save-points/07-javascript-interop/BlazingPizza.Shared/Pizza.cs index ec1108a9..459298f4 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Shared/Pizza.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Shared/Pizza.cs @@ -1,42 +1,44 @@ -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// /// Represents a customized pizza as part of an order +/// +public class Pizza { - /// - /// Represents a customized pizza as part of an order - /// - public class Pizza - { - public const int DefaultSize = 12; - public const int MinimumSize = 9; - public const int MaximumSize = 17; + public const int DefaultSize = 12; + public const int MinimumSize = 9; + public const int MaximumSize = 17; - public int Id { get; set; } + public int Id { get; set; } - public int OrderId { get; set; } + public int OrderId { get; set; } - public PizzaSpecial Special { get; set; } + public PizzaSpecial Special { get; set; } - public int SpecialId { get; set; } + public int SpecialId { get; set; } - public int Size { get; set; } + public int Size { get; set; } - public List Toppings { get; set; } + public List Toppings { get; set; } - public decimal GetBasePrice() - { - return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; - } + public decimal GetBasePrice() + { + return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; + } - public decimal GetTotalPrice() - { - return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); - } + public decimal GetTotalPrice() + { + return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); + } - public string GetFormattedTotalPrice() - { - return GetTotalPrice().ToString("0.00"); - } - } + public string GetFormattedTotalPrice() + { + return GetTotalPrice().ToString("0.00"); + } } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Serialization)] +[JsonSerializable(typeof(Pizza))] +public partial class PizzaContext : JsonSerializerContext {} \ No newline at end of file diff --git a/save-points/07-javascript-interop/BlazingPizza.Shared/PizzaSpecial.cs b/save-points/07-javascript-interop/BlazingPizza.Shared/PizzaSpecial.cs index 2f2b3383..9653300c 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Shared/PizzaSpecial.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Shared/PizzaSpecial.cs @@ -1,20 +1,19 @@ -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// Represents a pre-configured template for a pizza a user can order +/// +public class PizzaSpecial { - /// - /// Represents a pre-configured template for a pizza a user can order - /// - public class PizzaSpecial - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal BasePrice { get; set; } + public decimal BasePrice { get; set; } - public string Description { get; set; } + public string Description { get; set; } - public string ImageUrl { get; set; } + public string ImageUrl { get; set; } - public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); - } -} + public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); +} \ No newline at end of file diff --git a/save-points/07-javascript-interop/BlazingPizza.Shared/PizzaTopping.cs b/save-points/07-javascript-interop/BlazingPizza.Shared/PizzaTopping.cs index f5a6c1ac..0a711647 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Shared/PizzaTopping.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Shared/PizzaTopping.cs @@ -1,11 +1,11 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class PizzaTopping { - public class PizzaTopping - { - public Topping Topping { get; set; } + public Topping Topping { get; set; } + + public int ToppingId { get; set; } - public int ToppingId { get; set; } - - public int PizzaId { get; set; } - } -} + public int PizzaId { get; set; } + +} \ No newline at end of file diff --git a/save-points/07-javascript-interop/BlazingPizza.Shared/Topping.cs b/save-points/07-javascript-interop/BlazingPizza.Shared/Topping.cs index 61bdeb92..376c311a 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Shared/Topping.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Shared/Topping.cs @@ -1,13 +1,13 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class Topping { - public class Topping - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal Price { get; set; } + public decimal Price { get; set; } - public string GetFormattedPrice() => Price.ToString("0.00"); - } -} + public string GetFormattedPrice() => Price.ToString("0.00"); + +} \ No newline at end of file diff --git a/save-points/07-javascript-interop/BlazingPizza.Shared/UserInfo.cs b/save-points/07-javascript-interop/BlazingPizza.Shared/UserInfo.cs index 4996ef80..362f8f8e 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Shared/UserInfo.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Shared/UserInfo.cs @@ -1,9 +1,9 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class UserInfo { - public class UserInfo - { - public bool IsAuthenticated { get; set; } + public bool IsAuthenticated { get; set; } - public string Name { get; set; } - } -} + public string Name { get; set; } + +} \ No newline at end of file diff --git a/save-points/08-templated-components/BlazingPizza.Client/BlazingPizza.Client.csproj b/save-points/08-templated-components/BlazingPizza.Client/BlazingPizza.Client.csproj index 7fecc21b..44802d79 100644 --- a/save-points/08-templated-components/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/save-points/08-templated-components/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -2,12 +2,14 @@ $(TargetFrameworkVersion) + true + - + diff --git a/save-points/08-templated-components/BlazingPizza.Client/JSRuntimeExtensions.cs b/save-points/08-templated-components/BlazingPizza.Client/JSRuntimeExtensions.cs index 89da520c..cc242348 100644 --- a/save-points/08-templated-components/BlazingPizza.Client/JSRuntimeExtensions.cs +++ b/save-points/08-templated-components/BlazingPizza.Client/JSRuntimeExtensions.cs @@ -1,13 +1,11 @@ using Microsoft.JSInterop; -using System.Threading.Tasks; -namespace BlazingPizza.Client +namespace BlazingPizza.Client; + +public static class JSRuntimeExtensions { - public static class JSRuntimeExtensions - { - public static ValueTask Confirm(this IJSRuntime jsRuntime, string message) - { - return jsRuntime.InvokeAsync("confirm", message); - } - } + public static ValueTask Confirm(this IJSRuntime jsRuntime, string message) + { + return jsRuntime.InvokeAsync("confirm", message); + } } diff --git a/save-points/08-templated-components/BlazingPizza.Client/OrderState.cs b/save-points/08-templated-components/BlazingPizza.Client/OrderState.cs index 5265ae39..4f47979d 100644 --- a/save-points/08-templated-components/BlazingPizza.Client/OrderState.cs +++ b/save-points/08-templated-components/BlazingPizza.Client/OrderState.cs @@ -1,55 +1,52 @@ -using System.Collections.Generic; +namespace BlazingPizza.Client; -namespace BlazingPizza.Client +public class OrderState { - public class OrderState - { - public bool ShowingConfigureDialog { get; private set; } - - public Pizza ConfiguringPizza { get; private set; } - - public Order Order { get; private set; } = new Order(); - - public void ShowConfigurePizzaDialog(PizzaSpecial special) - { - ConfiguringPizza = new Pizza() - { - Special = special, - SpecialId = special.Id, - Size = Pizza.DefaultSize, - Toppings = new List(), - }; - - ShowingConfigureDialog = true; - } - - public void CancelConfigurePizzaDialog() - { - ConfiguringPizza = null; - ShowingConfigureDialog = false; - } - - public void ConfirmConfigurePizzaDialog() - { - Order.Pizzas.Add(ConfiguringPizza); - ConfiguringPizza = null; - - ShowingConfigureDialog = false; - } - - public void RemoveConfiguredPizza(Pizza pizza) - { - Order.Pizzas.Remove(pizza); - } - - public void ResetOrder() - { - Order = new Order(); - } - - public void ReplaceOrder(Order order) - { - Order = order; - } - } + public bool ShowingConfigureDialog { get; private set; } + + public Pizza ConfiguringPizza { get; private set; } + + public Order Order { get; private set; } = new Order(); + + public void ShowConfigurePizzaDialog(PizzaSpecial special) + { + ConfiguringPizza = new Pizza() + { + Special = special, + SpecialId = special.Id, + Size = Pizza.DefaultSize, + Toppings = new List(), + }; + + ShowingConfigureDialog = true; + } + + public void CancelConfigurePizzaDialog() + { + ConfiguringPizza = null; + ShowingConfigureDialog = false; + } + + public void ConfirmConfigurePizzaDialog() + { + Order.Pizzas.Add(ConfiguringPizza); + ConfiguringPizza = null; + + ShowingConfigureDialog = false; + } + + public void RemoveConfiguredPizza(Pizza pizza) + { + Order.Pizzas.Remove(pizza); + } + + public void ResetOrder() + { + Order = new Order(); + } + + public void ReplaceOrder(Order order) + { + Order = order; + } } diff --git a/save-points/08-templated-components/BlazingPizza.Client/OrdersClient.cs b/save-points/08-templated-components/BlazingPizza.Client/OrdersClient.cs index 0f800e6f..e63bd045 100644 --- a/save-points/08-templated-components/BlazingPizza.Client/OrdersClient.cs +++ b/save-points/08-templated-components/BlazingPizza.Client/OrdersClient.cs @@ -1,35 +1,36 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Net.Http.Json; -using System.Threading.Tasks; - -namespace BlazingPizza.Client +using System.Net.Http.Json; +using System.Text.Json; + +namespace BlazingPizza.Client; + +public class OrdersClient { - public class OrdersClient - { - private readonly HttpClient httpClient; + private readonly HttpClient httpClient; + + public OrdersClient(HttpClient httpClient) + { + this.httpClient = httpClient; + } - public OrdersClient(HttpClient httpClient) - { - this.httpClient = httpClient; - } + public async Task> GetOrders() => + await httpClient.GetFromJsonAsync("orders", OrderContext.Default.ListOrderWithStatus); - public async Task> GetOrders() => - await httpClient.GetFromJsonAsync>("orders"); + public async Task GetOrder(int orderId) => + await httpClient.GetFromJsonAsync($"orders/{orderId}", OrderContext.Default.OrderWithStatus); - public async Task GetOrder(int orderId) => - await httpClient.GetFromJsonAsync($"orders/{orderId}"); + public async Task PlaceOrder(Order order) + { + var response = await httpClient.PostAsJsonAsync("orders", order, OrderContext.Default.Order); + response.EnsureSuccessStatusCode(); + var orderId = await response.Content.ReadFromJsonAsync(); + return orderId; + } - public async Task PlaceOrder(Order order) - { - var response = await httpClient.PostAsJsonAsync("orders", order); - response.EnsureSuccessStatusCode(); - var orderId = await response.Content.ReadFromJsonAsync(); - return orderId; - } - } -} \ No newline at end of file + public async Task SubscribeToNotifications(NotificationSubscription subscription) + { + var response = await httpClient.PutAsJsonAsync("notifications/subscribe", subscription); + response.EnsureSuccessStatusCode(); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Client/PizzaAuthenticationState.cs b/save-points/08-templated-components/BlazingPizza.Client/PizzaAuthenticationState.cs index 3f295928..f5bfef65 100644 --- a/save-points/08-templated-components/BlazingPizza.Client/PizzaAuthenticationState.cs +++ b/save-points/08-templated-components/BlazingPizza.Client/PizzaAuthenticationState.cs @@ -1,9 +1,8 @@ using Microsoft.AspNetCore.Components.WebAssembly.Authentication; -namespace BlazingPizza.Client +namespace BlazingPizza.Client; + +public class PizzaAuthenticationState : RemoteAuthenticationState { - public class PizzaAuthenticationState : RemoteAuthenticationState - { - public Order Order { get; set; } - } + public Order Order { get; set; } } diff --git a/save-points/08-templated-components/BlazingPizza.Client/Program.cs b/save-points/08-templated-components/BlazingPizza.Client/Program.cs index afeee128..41eedccb 100644 --- a/save-points/08-templated-components/BlazingPizza.Client/Program.cs +++ b/save-points/08-templated-components/BlazingPizza.Client/Program.cs @@ -1,31 +1,20 @@ using Microsoft.AspNetCore.Components.WebAssembly.Authentication; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; using Microsoft.Extensions.DependencyInjection; -using System; -using System.Net.Http; -using System.Threading.Tasks; +using BlazingPizza.Client; -namespace BlazingPizza.Client -{ - public class Program - { - public static async Task Main(string[] args) - { - var builder = WebAssemblyHostBuilder.CreateDefault(args); - builder.RootComponents.Add("#app"); +var builder = WebAssemblyHostBuilder.CreateDefault(args); +builder.RootComponents.Add("#app"); - builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); - builder.Services.AddHttpClient(client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)) - .AddHttpMessageHandler(); - builder.Services.AddScoped(); +builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); +builder.Services.AddHttpClient(client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)) + .AddHttpMessageHandler(); +builder.Services.AddScoped(); - // Add auth services - builder.Services.AddApiAuthorization(options => - { - options.AuthenticationPaths.LogOutSucceededPath = ""; - }); +// Add auth services +builder.Services.AddApiAuthorization(options => +{ + options.AuthenticationPaths.LogOutSucceededPath = ""; +}); - await builder.Build().RunAsync(); - } - } -} +await builder.Build().RunAsync(); diff --git a/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 61ebf623..cb996b1b 100644 --- a/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -2,6 +2,7 @@ $(TargetFrameworkVersion) + true diff --git a/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/LocalStorage.cs b/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/LocalStorage.cs index f36b098e..bb84f13c 100644 --- a/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/LocalStorage.cs +++ b/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/LocalStorage.cs @@ -1,17 +1,15 @@ using Microsoft.JSInterop; -using System.Threading.Tasks; -namespace BlazingPizza.ComponentsLibrary +namespace BlazingPizza.ComponentsLibrary; + +public static class LocalStorage { - public static class LocalStorage - { - public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) - => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); + public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) + => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); - public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object value) - => jsRuntime.InvokeVoidAsync("blazorLocalStorage.set", key, value); + public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object value) + => jsRuntime.InvokeVoidAsync("blazorLocalStorage.set", key, value); - public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key) - => jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key); - } -} + public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key) + => jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key); +} \ No newline at end of file diff --git a/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/Map/Marker.cs b/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/Map/Marker.cs index 63006067..a8e78f2a 100644 --- a/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/Map/Marker.cs +++ b/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/Map/Marker.cs @@ -1,13 +1,12 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Marker { - public class Marker - { - public string Description { get; set; } + public string Description { get; set; } - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } + public double Y { get; set; } - public bool ShowPopup { get; set; } - } + public bool ShowPopup { get; set; } } diff --git a/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/Map/Point.cs b/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/Map/Point.cs index 03841826..349046d4 100644 --- a/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/Map/Point.cs +++ b/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/Map/Point.cs @@ -1,9 +1,8 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Point { - public class Point - { - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } - } -} + public double Y { get; set; } +} \ No newline at end of file diff --git a/save-points/08-templated-components/BlazingPizza.Server/BlazingPizza.Server.csproj b/save-points/08-templated-components/BlazingPizza.Server/BlazingPizza.Server.csproj index b9c74fc4..abd2317b 100644 --- a/save-points/08-templated-components/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/save-points/08-templated-components/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -2,6 +2,7 @@ $(TargetFrameworkVersion) + true @@ -13,6 +14,7 @@ + diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/AddressEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/AddressEntityType.cs new file mode 100644 index 00000000..82db81b6 --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/AddressEntityType.cs @@ -0,0 +1,92 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class AddressEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Address", + typeof(Address), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Address).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var city = runtimeEntityType.AddProperty( + "City", + typeof(string), + propertyInfo: typeof(Address).GetProperty("City", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var line1 = runtimeEntityType.AddProperty( + "Line1", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line1", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var line2 = runtimeEntityType.AddProperty( + "Line2", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line2", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var postalCode = runtimeEntityType.AddProperty( + "PostalCode", + typeof(string), + propertyInfo: typeof(Address).GetProperty("PostalCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var region = runtimeEntityType.AddProperty( + "Region", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Region", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Address"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs new file mode 100644 index 00000000..1dd4563b --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs @@ -0,0 +1,114 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class DeviceFlowCodesEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.DeviceFlowCodes", + typeof(DeviceFlowCodes), + baseEntityType); + + var userCode = runtimeEntityType.AddProperty( + "UserCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("UserCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var deviceCode = runtimeEntityType.AddProperty( + "DeviceCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("DeviceCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var key = runtimeEntityType.AddKey( + new[] { userCode }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deviceCode }, + unique: true); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "DeviceCodes"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs new file mode 100644 index 00000000..8946b261 --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRoleClaim", + typeof(IdentityRoleClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoleClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityRoleEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityRoleEntityType.cs new file mode 100644 index 00000000..2f1fec2b --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityRoleEntityType.cs @@ -0,0 +1,78 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRole", + typeof(IdentityRole), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedName = runtimeEntityType.AddProperty( + "NormalizedName", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("NormalizedName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedName }, + unique: true); + index.AddAnnotation("Relational:Name", "RoleNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs new file mode 100644 index 00000000..55418a1e --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserClaim", + typeof(IdentityUserClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityUserClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs new file mode 100644 index 00000000..3ca029bd --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserLoginstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserLogin", + typeof(IdentityUserLogin), + baseEntityType); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerKey = runtimeEntityType.AddProperty( + "ProviderKey", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderKey", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerDisplayName = runtimeEntityType.AddProperty( + "ProviderDisplayName", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderDisplayName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { loginProvider, providerKey }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserLogins"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs new file mode 100644 index 00000000..70078d7a --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs @@ -0,0 +1,82 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserRolestringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserRole", + typeof(IdentityUserRole), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { userId, roleId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs new file mode 100644 index 00000000..93ba6d31 --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs @@ -0,0 +1,84 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserTokenstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserToken", + typeof(IdentityUserToken), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var value = runtimeEntityType.AddProperty( + "Value", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Value", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { userId, loginProvider, name }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserTokens"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/KeyEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/KeyEntityType.cs new file mode 100644 index 00000000..f6c6b4c7 --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/KeyEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class KeyEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.Key", + typeof(Key), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var algorithm = runtimeEntityType.AddProperty( + "Algorithm", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Algorithm", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var created = runtimeEntityType.AddProperty( + "Created", + typeof(DateTime), + propertyInfo: typeof(Key).GetProperty("Created", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var dataProtected = runtimeEntityType.AddProperty( + "DataProtected", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("DataProtected", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var isX509Certificate = runtimeEntityType.AddProperty( + "IsX509Certificate", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("IsX509Certificate", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var use = runtimeEntityType.AddProperty( + "Use", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Use", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var version = runtimeEntityType.AddProperty( + "Version", + typeof(int), + propertyInfo: typeof(Key).GetProperty("Version", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { use }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Keys"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/LatLongEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/LatLongEntityType.cs new file mode 100644 index 00000000..3fd254bd --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/LatLongEntityType.cs @@ -0,0 +1,80 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class LatLongEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.LatLong", + typeof(LatLong), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var latitude = runtimeEntityType.AddProperty( + "Latitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Latitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var longitude = runtimeEntityType.AddProperty( + "Longitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Longitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + unique: true, + required: true, + ownership: true); + + var deliveryLocation = principalEntityType.AddNavigation("DeliveryLocation", + runtimeForeignKey, + onDependent: false, + typeof(LatLong), + propertyInfo: typeof(Order).GetProperty("DeliveryLocation", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + eagerLoaded: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs new file mode 100644 index 00000000..db236e4c --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs @@ -0,0 +1,77 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class NotificationSubscriptionEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.NotificationSubscription", + typeof(NotificationSubscription), + baseEntityType); + + var notificationSubscriptionId = runtimeEntityType.AddProperty( + "NotificationSubscriptionId", + typeof(int), + propertyInfo: typeof(NotificationSubscription).GetProperty("NotificationSubscriptionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var auth = runtimeEntityType.AddProperty( + "Auth", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Auth", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var p256dh = runtimeEntityType.AddProperty( + "P256dh", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("P256dh", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var url = runtimeEntityType.AddProperty( + "Url", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Url", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { notificationSubscriptionId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "NotificationSubscriptions"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/OrderEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/OrderEntityType.cs new file mode 100644 index 00000000..9d9ec6fd --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/OrderEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class OrderEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Order", + typeof(Order), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Order).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var createdTime = runtimeEntityType.AddProperty( + "CreatedTime", + typeof(DateTime), + propertyInfo: typeof(Order).GetProperty("CreatedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var deliveryAddressId = runtimeEntityType.AddProperty( + "DeliveryAddressId", + typeof(int?), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(Order).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deliveryAddressId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("DeliveryAddressId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType); + + var deliveryAddress = declaringEntityType.AddNavigation("DeliveryAddress", + runtimeForeignKey, + onDependent: true, + typeof(Address), + propertyInfo: typeof(Order).GetProperty("DeliveryAddress", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/PersistedGrantEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/PersistedGrantEntityType.cs new file mode 100644 index 00000000..842d53a5 --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/PersistedGrantEntityType.cs @@ -0,0 +1,127 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PersistedGrantEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.PersistedGrant", + typeof(PersistedGrant), + baseEntityType); + + var key = runtimeEntityType.AddProperty( + "Key", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Key", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var consumedTime = runtimeEntityType.AddProperty( + "ConsumedTime", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("ConsumedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(PersistedGrant).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var type = runtimeEntityType.AddProperty( + "Type", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Type", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var key0 = runtimeEntityType.AddKey( + new[] { key }); + runtimeEntityType.SetPrimaryKey(key0); + + var index = runtimeEntityType.AddIndex( + new[] { consumedTime }); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + var index1 = runtimeEntityType.AddIndex( + new[] { subjectId, clientId, type }); + + var index2 = runtimeEntityType.AddIndex( + new[] { subjectId, sessionId, type }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PersistedGrants"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaEntityType.cs new file mode 100644 index 00000000..3a124e63 --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaEntityType.cs @@ -0,0 +1,111 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Pizza", + typeof(Pizza), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var size = runtimeEntityType.AddProperty( + "Size", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Size", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var specialId = runtimeEntityType.AddProperty( + "SpecialId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("SpecialId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { orderId }); + + var index0 = runtimeEntityType.AddIndex( + new[] { specialId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var pizzas = principalEntityType.AddNavigation("Pizzas", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Order).GetProperty("Pizzas", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("SpecialId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var special = declaringEntityType.AddNavigation("Special", + runtimeForeignKey, + onDependent: true, + typeof(PizzaSpecial), + propertyInfo: typeof(Pizza).GetProperty("Special", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Pizzas"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs new file mode 100644 index 00000000..e86b0f50 --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs @@ -0,0 +1,76 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaSpecialEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaSpecial", + typeof(PizzaSpecial), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(PizzaSpecial).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var basePrice = runtimeEntityType.AddProperty( + "BasePrice", + typeof(decimal), + propertyInfo: typeof(PizzaSpecial).GetProperty("BasePrice", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var imageUrl = runtimeEntityType.AddProperty( + "ImageUrl", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("ImageUrl", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Specials"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaStoreContextModel.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaStoreContextModel.cs new file mode 100644 index 00000000..8b516a68 --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaStoreContextModel.cs @@ -0,0 +1,28 @@ +// +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + [DbContext(typeof(PizzaStoreContext))] + public partial class PizzaStoreContextModel : RuntimeModel + { + static PizzaStoreContextModel() + { + var model = new PizzaStoreContextModel(); + model.Initialize(); + model.Customize(); + _instance = model; + } + + private static PizzaStoreContextModel _instance; + public static IModel Instance => _instance; + + partial void Initialize(); + + partial void Customize(); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs new file mode 100644 index 00000000..d46f50f4 --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs @@ -0,0 +1,69 @@ +// +using System; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + public partial class PizzaStoreContextModel + { + partial void Initialize() + { + var address = AddressEntityType.Create(this); + var latLong = LatLongEntityType.Create(this); + var notificationSubscription = NotificationSubscriptionEntityType.Create(this); + var order = OrderEntityType.Create(this); + var pizza = PizzaEntityType.Create(this); + var pizzaSpecial = PizzaSpecialEntityType.Create(this); + var pizzaTopping = PizzaToppingEntityType.Create(this); + var pizzaStoreUser = PizzaStoreUserEntityType.Create(this); + var topping = ToppingEntityType.Create(this); + var deviceFlowCodes = DeviceFlowCodesEntityType.Create(this); + var key = KeyEntityType.Create(this); + var persistedGrant = PersistedGrantEntityType.Create(this); + var identityRole = IdentityRoleEntityType.Create(this); + var identityRoleClaimstring = IdentityRoleClaimstringEntityType.Create(this); + var identityUserClaimstring = IdentityUserClaimstringEntityType.Create(this); + var identityUserLoginstring = IdentityUserLoginstringEntityType.Create(this); + var identityUserRolestring = IdentityUserRolestringEntityType.Create(this); + var identityUserTokenstring = IdentityUserTokenstringEntityType.Create(this); + + LatLongEntityType.CreateForeignKey1(latLong, order); + OrderEntityType.CreateForeignKey1(order, address); + PizzaEntityType.CreateForeignKey1(pizza, order); + PizzaEntityType.CreateForeignKey2(pizza, pizzaSpecial); + PizzaToppingEntityType.CreateForeignKey1(pizzaTopping, pizza); + PizzaToppingEntityType.CreateForeignKey2(pizzaTopping, topping); + IdentityRoleClaimstringEntityType.CreateForeignKey1(identityRoleClaimstring, identityRole); + IdentityUserClaimstringEntityType.CreateForeignKey1(identityUserClaimstring, pizzaStoreUser); + IdentityUserLoginstringEntityType.CreateForeignKey1(identityUserLoginstring, pizzaStoreUser); + IdentityUserRolestringEntityType.CreateForeignKey1(identityUserRolestring, identityRole); + IdentityUserRolestringEntityType.CreateForeignKey2(identityUserRolestring, pizzaStoreUser); + IdentityUserTokenstringEntityType.CreateForeignKey1(identityUserTokenstring, pizzaStoreUser); + + AddressEntityType.CreateAnnotations(address); + LatLongEntityType.CreateAnnotations(latLong); + NotificationSubscriptionEntityType.CreateAnnotations(notificationSubscription); + OrderEntityType.CreateAnnotations(order); + PizzaEntityType.CreateAnnotations(pizza); + PizzaSpecialEntityType.CreateAnnotations(pizzaSpecial); + PizzaToppingEntityType.CreateAnnotations(pizzaTopping); + PizzaStoreUserEntityType.CreateAnnotations(pizzaStoreUser); + ToppingEntityType.CreateAnnotations(topping); + DeviceFlowCodesEntityType.CreateAnnotations(deviceFlowCodes); + KeyEntityType.CreateAnnotations(key); + PersistedGrantEntityType.CreateAnnotations(persistedGrant); + IdentityRoleEntityType.CreateAnnotations(identityRole); + IdentityRoleClaimstringEntityType.CreateAnnotations(identityRoleClaimstring); + IdentityUserClaimstringEntityType.CreateAnnotations(identityUserClaimstring); + IdentityUserLoginstringEntityType.CreateAnnotations(identityUserLoginstring); + IdentityUserRolestringEntityType.CreateAnnotations(identityUserRolestring); + IdentityUserTokenstringEntityType.CreateAnnotations(identityUserTokenstring); + + AddAnnotation("ProductVersion", "6.0.0"); + } + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs new file mode 100644 index 00000000..18b2d96d --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs @@ -0,0 +1,156 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaStoreUserEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Server.PizzaStoreUser", + typeof(PizzaStoreUser), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var accessFailedCount = runtimeEntityType.AddProperty( + "AccessFailedCount", + typeof(int), + propertyInfo: typeof(IdentityUser).GetProperty("AccessFailedCount", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var email = runtimeEntityType.AddProperty( + "Email", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Email", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var emailConfirmed = runtimeEntityType.AddProperty( + "EmailConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("EmailConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnabled = runtimeEntityType.AddProperty( + "LockoutEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnd = runtimeEntityType.AddProperty( + "LockoutEnd", + typeof(DateTimeOffset?), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnd", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var normalizedEmail = runtimeEntityType.AddProperty( + "NormalizedEmail", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedEmail", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedUserName = runtimeEntityType.AddProperty( + "NormalizedUserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedUserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var passwordHash = runtimeEntityType.AddProperty( + "PasswordHash", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PasswordHash", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumber = runtimeEntityType.AddProperty( + "PhoneNumber", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumber", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumberConfirmed = runtimeEntityType.AddProperty( + "PhoneNumberConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumberConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var securityStamp = runtimeEntityType.AddProperty( + "SecurityStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("SecurityStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var twoFactorEnabled = runtimeEntityType.AddProperty( + "TwoFactorEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("TwoFactorEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var userName = runtimeEntityType.AddProperty( + "UserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("UserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedEmail }); + index.AddAnnotation("Relational:Name", "EmailIndex"); + + var index0 = runtimeEntityType.AddIndex( + new[] { normalizedUserName }, + unique: true); + index0.AddAnnotation("Relational:Name", "UserNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUsers"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaToppingEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaToppingEntityType.cs new file mode 100644 index 00000000..b97d2a24 --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaToppingEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaTopping", + typeof(PizzaTopping), + baseEntityType); + + var pizzaId = runtimeEntityType.AddProperty( + "PizzaId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("PizzaId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var toppingId = runtimeEntityType.AddProperty( + "ToppingId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("ToppingId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { pizzaId, toppingId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { toppingId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("PizzaId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var toppings = principalEntityType.AddNavigation("Toppings", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Pizza).GetProperty("Toppings", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("ToppingId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var topping = declaringEntityType.AddNavigation("Topping", + runtimeForeignKey, + onDependent: true, + typeof(Topping), + propertyInfo: typeof(PizzaTopping).GetProperty("Topping", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PizzaTopping"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/ToppingEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/ToppingEntityType.cs new file mode 100644 index 00000000..9295f9bf --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/ToppingEntityType.cs @@ -0,0 +1,62 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class ToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Topping", + typeof(Topping), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Topping).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Topping).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var price = runtimeEntityType.AddProperty( + "Price", + typeof(decimal), + propertyInfo: typeof(Topping).GetProperty("Price", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Toppings"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/NotificationsController.cs b/save-points/08-templated-components/BlazingPizza.Server/NotificationsController.cs deleted file mode 100644 index bb3b96ff..00000000 --- a/save-points/08-templated-components/BlazingPizza.Server/NotificationsController.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("notifications")] - [ApiController] - [Authorize] - public class NotificationsController : Controller - { - private readonly PizzaStoreContext _db; - - public NotificationsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpPut("subscribe")] - public async Task Subscribe(NotificationSubscription subscription) - { - // We're storing at most one subscription per user, so delete old ones. - // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. - var userId = GetUserId(); - var oldSubscriptions = _db.NotificationSubscriptions.Where(e => e.UserId == userId); - _db.NotificationSubscriptions.RemoveRange(oldSubscriptions); - - // Store new subscription - subscription.UserId = userId; - _db.NotificationSubscriptions.Attach(subscription); - - await _db.SaveChangesAsync(); - return subscription; - } - - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } - } -} diff --git a/save-points/08-templated-components/BlazingPizza.Server/OidcConfigurationController.cs b/save-points/08-templated-components/BlazingPizza.Server/OidcConfigurationController.cs index c074debf..dc75ecb3 100644 --- a/save-points/08-templated-components/BlazingPizza.Server/OidcConfigurationController.cs +++ b/save-points/08-templated-components/BlazingPizza.Server/OidcConfigurationController.cs @@ -1,26 +1,21 @@ using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class OidcConfigurationController : Controller { - public class OidcConfigurationController : Controller - { - public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) - { - ClientRequestParametersProvider = clientRequestParametersProvider; - } + public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) + { + ClientRequestParametersProvider = clientRequestParametersProvider; + } - public IClientRequestParametersProvider ClientRequestParametersProvider { get; } + public IClientRequestParametersProvider ClientRequestParametersProvider { get; } - [HttpGet("_configuration/{clientId}")] - public IActionResult GetClientRequestParameters([FromRoute]string clientId) - { - var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); - return Ok(parameters); - } - } + [HttpGet("_configuration/{clientId}")] + public IActionResult GetClientRequestParameters([FromRoute] string clientId) + { + var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); + return Ok(parameters); + } } diff --git a/save-points/08-templated-components/BlazingPizza.Server/OrdersController.cs b/save-points/08-templated-components/BlazingPizza.Server/OrdersController.cs index 72b59890..1859decd 100644 --- a/save-points/08-templated-components/BlazingPizza.Server/OrdersController.cs +++ b/save-points/08-templated-components/BlazingPizza.Server/OrdersController.cs @@ -1,115 +1,130 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; +using System.Security.Claims; +using System.Text.Json; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using WebPush; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +[Route("orders")] +[ApiController] +[Authorize] +public class OrdersController : Controller { - [Route("orders")] - [ApiController] - [Authorize] - public class OrdersController : Controller - { - private readonly PizzaStoreContext _db; - - public OrdersController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetOrders() - { - var orders = await _db.Orders - .Where(o => o.UserId == GetUserId()) - .Include(o => o.DeliveryLocation) - .Include(o => o.Pizzas).ThenInclude(p => p.Special) - .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) - .OrderByDescending(o => o.CreatedTime) - .ToListAsync(); - - return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); - } - - [HttpGet("{orderId}")] - public async Task> GetOrderWithStatus(int orderId) - { - var order = await _db.Orders - .Where(o => o.OrderId == orderId) - .Where(o => o.UserId == GetUserId()) - .Include(o => o.DeliveryLocation) - .Include(o => o.Pizzas).ThenInclude(p => p.Special) - .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) - .SingleOrDefaultAsync(); - - if (order == null) - { - return NotFound(); - } - - return OrderWithStatus.FromOrder(order); - } - - [HttpPost] - public async Task> PlaceOrder(Order order) - { - order.CreatedTime = DateTime.Now; - order.DeliveryLocation = new LatLong(51.5001, -0.1239); - order.UserId = GetUserId(); - - // Enforce existence of Pizza.SpecialId and Topping.ToppingId - // in the database - prevent the submitter from making up - // new specials and toppings - foreach (var pizza in order.Pizzas) - { - pizza.SpecialId = pizza.Special.Id; - pizza.Special = null; - - foreach (var topping in pizza.Toppings) - { - topping.ToppingId = topping.Topping.Id; - topping.Topping = null; - } - } - - _db.Orders.Attach(order); - await _db.SaveChangesAsync(); - - // In the background, send push notifications if possible - var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); - if (subscription != null) - { - _ = TrackAndSendNotificationsAsync(order, subscription); - } - - return order.OrderId; - } - - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } - - private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription subscription) - { - // In a realistic case, some other backend process would track - // order delivery progress and send us notifications when it - // changes. Since we don't have any such process here, fake it. - await Task.Delay(OrderWithStatus.PreparationDuration); - await SendNotificationAsync(order, subscription, "Your order has been dispatched!"); - - await Task.Delay(OrderWithStatus.DeliveryDuration); - await SendNotificationAsync(order, subscription, "Your order is now delivered. Enjoy!"); - } - - private static Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) - { - // This will be implemented later - return Task.CompletedTask; - } - } + private readonly PizzaStoreContext _db; + + public OrdersController(PizzaStoreContext db) + { + _db = db; + } + + [HttpGet] + public async Task>> GetOrders() + { + var orders = await _db.Orders + .Where(o => o.UserId == GetUserId()) + .Include(o => o.DeliveryLocation) + .Include(o => o.Pizzas).ThenInclude(p => p.Special) + .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) + .OrderByDescending(o => o.CreatedTime) + .ToListAsync(); + + return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); + } + + [HttpGet("{orderId}")] + public async Task> GetOrderWithStatus(int orderId) + { + var order = await _db.Orders + .Where(o => o.OrderId == orderId) + .Where(o => o.UserId == GetUserId()) + .Include(o => o.DeliveryLocation) + .Include(o => o.Pizzas).ThenInclude(p => p.Special) + .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) + .SingleOrDefaultAsync(); + + if (order == null) + { + return NotFound(); + } + + return OrderWithStatus.FromOrder(order); + } + + [HttpPost] + public async Task> PlaceOrder(Order order) + { + order.CreatedTime = DateTime.Now; + order.DeliveryLocation = new LatLong(51.5001, -0.1239); + order.UserId = GetUserId(); + + // Enforce existence of Pizza.SpecialId and Topping.ToppingId + // in the database - prevent the submitter from making up + // new specials and toppings + foreach (var pizza in order.Pizzas) + { + pizza.SpecialId = pizza.Special.Id; + pizza.Special = null; + + foreach (var topping in pizza.Toppings) + { + topping.ToppingId = topping.Topping.Id; + topping.Topping = null; + } + } + + _db.Orders.Attach(order); + await _db.SaveChangesAsync(); + + // In the background, send push notifications if possible + var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); + if (subscription != null) + { + _ = TrackAndSendNotificationsAsync(order, subscription); + } + + return order.OrderId; + } + + private string GetUserId() + { + return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); + } + + private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription subscription) + { + // In a realistic case, some other backend process would track + // order delivery progress and send us notifications when it + // changes. Since we don't have any such process here, fake it. + await Task.Delay(OrderWithStatus.PreparationDuration); + await SendNotificationAsync(order, subscription, "Your order has been dispatched!"); + + await Task.Delay(OrderWithStatus.DeliveryDuration); + await SendNotificationAsync(order, subscription, "Your order is now delivered. Enjoy!"); + } + + private static async Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) + { + // For a real application, generate your own + var publicKey = "BLC8GOevpcpjQiLkO7JmVClQjycvTCYWm6Cq_a7wJZlstGTVZvwGFFHMYfXt6Njyvgx_GlXJeo5cSiZ1y4JOx1o"; + var privateKey = "OrubzSz3yWACscZXjFQrrtDwCKg-TGFuWhluQ2wLXDo"; + + var pushSubscription = new PushSubscription(subscription.Url, subscription.P256dh, subscription.Auth); + var vapidDetails = new VapidDetails("mailto:", publicKey, privateKey); + var webPushClient = new WebPushClient(); + try + { + var payload = JsonSerializer.Serialize(new + { + message, + url = $"myorders/{order.OrderId}", + }); + await webPushClient.SendNotificationAsync(pushSubscription, payload, vapidDetails); + } + catch (Exception ex) + { + Console.Error.WriteLine("Error sending push notification: " + ex.Message); + } + } } diff --git a/save-points/08-templated-components/BlazingPizza.Server/PizzaApiExtensions.cs b/save-points/08-templated-components/BlazingPizza.Server/PizzaApiExtensions.cs new file mode 100644 index 00000000..bf6b7bde --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/PizzaApiExtensions.cs @@ -0,0 +1,60 @@ +using System.Security.Claims; +using Microsoft.AspNetCore.Authorization; +using Microsoft.EntityFrameworkCore; + +namespace BlazingPizza.Server; + +public static class PizzaApiExtensions +{ + + public static WebApplication MapPizzaApi(this WebApplication app) + { + + // Subscribe to notifications + app.MapPut("/notifications/subscribe", [Authorize] async ( + HttpContext context, + PizzaStoreContext db, + NotificationSubscription subscription) => + { + + // We're storing at most one subscription per user, so delete old ones. + // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. + var userId = GetUserId(context); + var oldSubscriptions = db.NotificationSubscriptions.Where(e => e.UserId == userId); + db.NotificationSubscriptions.RemoveRange(oldSubscriptions); + + // Store new subscription + subscription.UserId = userId; + db.NotificationSubscriptions.Attach(subscription); + + await db.SaveChangesAsync(); + return Results.Ok(subscription); + + }); + + // Specials + app.MapGet("/specials", async (PizzaStoreContext db) => + { + + var specials = await db.Specials.ToListAsync(); + return Results.Ok(specials); + + }); + + // Toppings + app.MapGet("/toppings", async (PizzaStoreContext db) => + { + var toppings = await db.Toppings.OrderBy(t => t.Name).ToListAsync(); + return Results.Ok(toppings); + }); + + return app; + + } + + private static string GetUserId(HttpContext context) + { + return context.User.FindFirstValue(ClaimTypes.NameIdentifier); + } + +} \ No newline at end of file diff --git a/save-points/08-templated-components/BlazingPizza.Server/PizzaStoreContext.cs b/save-points/08-templated-components/BlazingPizza.Server/PizzaStoreContext.cs index 9485bd12..9a2e17ee 100644 --- a/save-points/08-templated-components/BlazingPizza.Server/PizzaStoreContext.cs +++ b/save-points/08-templated-components/BlazingPizza.Server/PizzaStoreContext.cs @@ -3,37 +3,36 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class PizzaStoreContext : ApiAuthorizationDbContext { - public class PizzaStoreContext : ApiAuthorizationDbContext - { - public PizzaStoreContext( - DbContextOptions options, - IOptions operationalStoreOptions) : base(options, operationalStoreOptions) - { - } + public PizzaStoreContext( + DbContextOptions options, + IOptions operationalStoreOptions) : base(options, operationalStoreOptions) + { + } - public DbSet Orders { get; set; } + public DbSet Orders { get; set; } - public DbSet Pizzas { get; set; } + public DbSet Pizzas { get; set; } - public DbSet Specials { get; set; } + public DbSet Specials { get; set; } - public DbSet Toppings { get; set; } + public DbSet Toppings { get; set; } - public DbSet NotificationSubscriptions { get; set; } + public DbSet NotificationSubscriptions { get; set; } - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - base.OnModelCreating(modelBuilder); + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); - // Configuring a many-to-many special -> topping relationship that is friendly for serialization - modelBuilder.Entity().HasKey(pst => new { pst.PizzaId, pst.ToppingId }); - modelBuilder.Entity().HasOne().WithMany(ps => ps.Toppings); - modelBuilder.Entity().HasOne(pst => pst.Topping).WithMany(); + // Configuring a many-to-many special -> topping relationship that is friendly for serialization + modelBuilder.Entity().HasKey(pst => new { pst.PizzaId, pst.ToppingId }); + modelBuilder.Entity().HasOne().WithMany(ps => ps.Toppings); + modelBuilder.Entity().HasOne(pst => pst.Topping).WithMany(); - // Inline the Lat-Long pairs in Order rather than having a FK to another table - modelBuilder.Entity().OwnsOne(o => o.DeliveryLocation); - } - } -} \ No newline at end of file + // Inline the Lat-Long pairs in Order rather than having a FK to another table + modelBuilder.Entity().OwnsOne(o => o.DeliveryLocation); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/PizzaStoreUser.cs b/save-points/08-templated-components/BlazingPizza.Server/PizzaStoreUser.cs index 171ce83d..7ab40235 100644 --- a/save-points/08-templated-components/BlazingPizza.Server/PizzaStoreUser.cs +++ b/save-points/08-templated-components/BlazingPizza.Server/PizzaStoreUser.cs @@ -1,8 +1,5 @@ using Microsoft.AspNetCore.Identity; -namespace BlazingPizza.Server -{ - public class PizzaStoreUser : IdentityUser - { - } -} \ No newline at end of file +namespace BlazingPizza.Server; + +public class PizzaStoreUser : IdentityUser { } \ No newline at end of file diff --git a/save-points/08-templated-components/BlazingPizza.Server/PizzasController.cs b/save-points/08-templated-components/BlazingPizza.Server/PizzasController.cs deleted file mode 100644 index c082552c..00000000 --- a/save-points/08-templated-components/BlazingPizza.Server/PizzasController.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("pizzas")] - [ApiController] - public class PizzasController : Controller - { - private readonly PizzaStoreContext _db; - - public PizzasController(PizzaStoreContext db) - { - _db = db; - } - } -} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Program.cs b/save-points/08-templated-components/BlazingPizza.Server/Program.cs index 40a47641..4484d8f7 100644 --- a/save-points/08-templated-components/BlazingPizza.Server/Program.cs +++ b/save-points/08-templated-components/BlazingPizza.Server/Program.cs @@ -1,33 +1,67 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; +using Microsoft.AspNetCore.Authentication; +using Microsoft.EntityFrameworkCore; +using BlazingPizza.Server; -namespace BlazingPizza.Server +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddControllersWithViews() + .AddJsonOptions(options => { + options.JsonSerializerOptions.AddContext(); + }); +builder.Services.AddRazorPages(); + +builder.Services.AddDbContext(options => + options.UseSqlite("Data Source=pizza.db") + .UseModel(BlazingPizza.Server.Models.PizzaStoreContextModel.Instance)); + +builder.Services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) + .AddEntityFrameworkStores(); + +builder.Services.AddIdentityServer() + .AddApiAuthorization(); + +builder.Services.AddAuthentication() + .AddIdentityServerJwt(); + +var app = builder.Build(); + +// Initialize the database +var scopeFactory = app.Services.GetRequiredService(); +using (var scope = scopeFactory.CreateScope()) +{ + var db = scope.ServiceProvider.GetRequiredService(); + if (db.Database.EnsureCreated()) + { + SeedData.Initialize(db); + } +} + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseWebAssemblyDebugging(); +} +else { - public class Program - { - public static void Main(string[] args) - { - var host = CreateHostBuilder(args).Build(); - - // Initialize the database - var scopeFactory = host.Services.GetRequiredService(); - using (var scope = scopeFactory.CreateScope()) - { - var db = scope.ServiceProvider.GetRequiredService(); - if (db.Database.EnsureCreated()) - { - SeedData.Initialize(db); - } - } - - host.Run(); - } - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); - } + app.UseExceptionHandler("/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); } + +app.UseHttpsRedirection(); +app.UseBlazorFrameworkFiles(); +app.UseStaticFiles(); + +app.UseRouting(); + +app.UseAuthentication(); +app.UseIdentityServer(); +app.UseAuthorization(); + +app.MapPizzaApi(); + +app.MapRazorPages(); +app.MapControllers(); +app.MapFallbackToFile("index.html"); + +app.Run(); \ No newline at end of file diff --git a/save-points/08-templated-components/BlazingPizza.Server/SeedData.cs b/save-points/08-templated-components/BlazingPizza.Server/SeedData.cs index 7c86a5b2..a1e47973 100644 --- a/save-points/08-templated-components/BlazingPizza.Server/SeedData.cs +++ b/save-points/08-templated-components/BlazingPizza.Server/SeedData.cs @@ -1,193 +1,192 @@ -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public static class SeedData { - public static class SeedData - { - public static void Initialize(PizzaStoreContext db) - { - var toppings = new Topping[] - { - new Topping() - { - Name = "Extra cheese", - Price = 2.50m, - }, - new Topping() - { - Name = "American bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "British bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "Canadian bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "Tea and crumpets", - Price = 5.00m - }, - new Topping() - { - Name = "Fresh-baked scones", - Price = 4.50m, - }, - new Topping() - { - Name = "Bell peppers", - Price = 1.00m, - }, - new Topping() - { - Name = "Onions", - Price = 1.00m, - }, - new Topping() - { - Name = "Mushrooms", - Price = 1.00m, - }, - new Topping() - { - Name = "Pepperoni", - Price = 1.00m, - }, - new Topping() - { - Name = "Duck sausage", - Price = 3.20m, - }, - new Topping() - { - Name = "Venison meatballs", - Price = 2.50m, - }, - new Topping() - { - Name = "Served on a silver platter", - Price = 250.99m, - }, - new Topping() - { - Name = "Lobster on top", - Price = 64.50m, - }, - new Topping() - { - Name = "Sturgeon caviar", - Price = 101.75m, - }, - new Topping() - { - Name = "Artichoke hearts", - Price = 3.40m, - }, - new Topping() - { - Name = "Fresh tomatoes", - Price = 1.50m, - }, - new Topping() - { - Name = "Basil", - Price = 1.50m, - }, - new Topping() - { - Name = "Steak (medium-rare)", - Price = 8.50m, - }, - new Topping() - { - Name = "Blazing hot peppers", - Price = 4.20m, - }, - new Topping() - { - Name = "Buffalo chicken", - Price = 5.00m, - }, - new Topping() - { - Name = "Blue cheese", - Price = 2.50m, - }, - }; + public static void Initialize(PizzaStoreContext db) + { + var toppings = new Topping[] + { + new Topping() + { + Name = "Extra cheese", + Price = 2.50m, + }, + new Topping() + { + Name = "American bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "British bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "Canadian bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "Tea and crumpets", + Price = 5.00m + }, + new Topping() + { + Name = "Fresh-baked scones", + Price = 4.50m, + }, + new Topping() + { + Name = "Bell peppers", + Price = 1.00m, + }, + new Topping() + { + Name = "Onions", + Price = 1.00m, + }, + new Topping() + { + Name = "Mushrooms", + Price = 1.00m, + }, + new Topping() + { + Name = "Pepperoni", + Price = 1.00m, + }, + new Topping() + { + Name = "Duck sausage", + Price = 3.20m, + }, + new Topping() + { + Name = "Venison meatballs", + Price = 2.50m, + }, + new Topping() + { + Name = "Served on a silver platter", + Price = 250.99m, + }, + new Topping() + { + Name = "Lobster on top", + Price = 64.50m, + }, + new Topping() + { + Name = "Sturgeon caviar", + Price = 101.75m, + }, + new Topping() + { + Name = "Artichoke hearts", + Price = 3.40m, + }, + new Topping() + { + Name = "Fresh tomatoes", + Price = 1.50m, + }, + new Topping() + { + Name = "Basil", + Price = 1.50m, + }, + new Topping() + { + Name = "Steak (medium-rare)", + Price = 8.50m, + }, + new Topping() + { + Name = "Blazing hot peppers", + Price = 4.20m, + }, + new Topping() + { + Name = "Buffalo chicken", + Price = 5.00m, + }, + new Topping() + { + Name = "Blue cheese", + Price = 2.50m, + }, + }; - var specials = new PizzaSpecial[] - { - new PizzaSpecial() - { - Name = "Basic Cheese Pizza", - Description = "It's cheesy and delicious. Why wouldn't you want one?", - BasePrice = 9.99m, - ImageUrl = "img/pizzas/cheese.jpg", - }, - new PizzaSpecial() - { - Id = 2, - Name = "The Baconatorizor", - Description = "It has EVERY kind of bacon", - BasePrice = 11.99m, - ImageUrl = "img/pizzas/bacon.jpg", - }, - new PizzaSpecial() - { - Id = 3, - Name = "Classic pepperoni", - Description = "It's the pizza you grew up with, but Blazing hot!", - BasePrice = 10.50m, - ImageUrl = "img/pizzas/pepperoni.jpg", - }, - new PizzaSpecial() - { - Id = 4, - Name = "Buffalo chicken", - Description = "Spicy chicken, hot sauce and bleu cheese, guaranteed to warm you up", - BasePrice = 12.75m, - ImageUrl = "img/pizzas/meaty.jpg", - }, - new PizzaSpecial() - { - Id = 5, - Name = "Mushroom Lovers", - Description = "It has mushrooms. Isn't that obvious?", - BasePrice = 11.00m, - ImageUrl = "img/pizzas/mushroom.jpg", - }, - new PizzaSpecial() - { - Id = 6, - Name = "The Brit", - Description = "When in London...", - BasePrice = 10.25m, - ImageUrl = "img/pizzas/brit.jpg", - }, - new PizzaSpecial() - { - Id = 7, - Name = "Veggie Delight", - Description = "It's like salad, but on a pizza", - BasePrice = 11.50m, - ImageUrl = "img/pizzas/salad.jpg", - }, - new PizzaSpecial() - { - Id = 8, - Name = "Margherita", - Description = "Traditional Italian pizza with tomatoes and basil", - BasePrice = 9.99m, - ImageUrl = "img/pizzas/margherita.jpg", - }, - }; + var specials = new PizzaSpecial[] + { + new PizzaSpecial() + { + Name = "Basic Cheese Pizza", + Description = "It's cheesy and delicious. Why wouldn't you want one?", + BasePrice = 9.99m, + ImageUrl = "img/pizzas/cheese.jpg", + }, + new PizzaSpecial() + { + Id = 2, + Name = "The Baconatorizor", + Description = "It has EVERY kind of bacon", + BasePrice = 11.99m, + ImageUrl = "img/pizzas/bacon.jpg", + }, + new PizzaSpecial() + { + Id = 3, + Name = "Classic pepperoni", + Description = "It's the pizza you grew up with, but Blazing hot!", + BasePrice = 10.50m, + ImageUrl = "img/pizzas/pepperoni.jpg", + }, + new PizzaSpecial() + { + Id = 4, + Name = "Buffalo chicken", + Description = "Spicy chicken, hot sauce and bleu cheese, guaranteed to warm you up", + BasePrice = 12.75m, + ImageUrl = "img/pizzas/meaty.jpg", + }, + new PizzaSpecial() + { + Id = 5, + Name = "Mushroom Lovers", + Description = "It has mushrooms. Isn't that obvious?", + BasePrice = 11.00m, + ImageUrl = "img/pizzas/mushroom.jpg", + }, + new PizzaSpecial() + { + Id = 6, + Name = "The Brit", + Description = "When in London...", + BasePrice = 10.25m, + ImageUrl = "img/pizzas/brit.jpg", + }, + new PizzaSpecial() + { + Id = 7, + Name = "Veggie Delight", + Description = "It's like salad, but on a pizza", + BasePrice = 11.50m, + ImageUrl = "img/pizzas/salad.jpg", + }, + new PizzaSpecial() + { + Id = 8, + Name = "Margherita", + Description = "Traditional Italian pizza with tomatoes and basil", + BasePrice = 9.99m, + ImageUrl = "img/pizzas/margherita.jpg", + }, + }; - db.Toppings.AddRange(toppings); - db.Specials.AddRange(specials); - db.SaveChanges(); - } - } -} + db.Toppings.AddRange(toppings); + db.Specials.AddRange(specials); + db.SaveChanges(); + } +} \ No newline at end of file diff --git a/save-points/08-templated-components/BlazingPizza.Server/SpecialsController.cs b/save-points/08-templated-components/BlazingPizza.Server/SpecialsController.cs deleted file mode 100644 index a176844c..00000000 --- a/save-points/08-templated-components/BlazingPizza.Server/SpecialsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("specials")] - [ApiController] - public class SpecialsController : Controller - { - private readonly PizzaStoreContext _db; - - public SpecialsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetSpecials() - { - return (await _db.Specials.ToListAsync()).OrderByDescending(s => s.BasePrice).ToList(); - } - } -} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Startup.cs b/save-points/08-templated-components/BlazingPizza.Server/Startup.cs deleted file mode 100644 index ed3fca06..00000000 --- a/save-points/08-templated-components/BlazingPizza.Server/Startup.cs +++ /dev/null @@ -1,70 +0,0 @@ -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace BlazingPizza.Server -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - public void ConfigureServices(IServiceCollection services) - { - services.AddControllersWithViews(); - services.AddRazorPages(); - - services.AddDbContext(options => - options.UseSqlite("Data Source=pizza.db")); - - services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) - .AddEntityFrameworkStores(); - - services.AddIdentityServer() - .AddApiAuthorization(); - - services.AddAuthentication() - .AddIdentityServerJwt(); - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - app.UseWebAssemblyDebugging(); - } - else - { - app.UseExceptionHandler("/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); - } - - app.UseHttpsRedirection(); - app.UseBlazorFrameworkFiles(); - app.UseStaticFiles(); - - app.UseRouting(); - - app.UseAuthentication(); - app.UseIdentityServer(); - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - endpoints.MapRazorPages(); - endpoints.MapFallbackToFile("index.html"); - }); - } - } -} \ No newline at end of file diff --git a/save-points/08-templated-components/BlazingPizza.Server/ToppingsController.cs b/save-points/08-templated-components/BlazingPizza.Server/ToppingsController.cs deleted file mode 100644 index 6a677639..00000000 --- a/save-points/08-templated-components/BlazingPizza.Server/ToppingsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("toppings")] - [ApiController] - public class ToppingsController : Controller - { - private readonly PizzaStoreContext _db; - - public ToppingsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetToppings() - { - return await _db.Toppings.OrderBy(t => t.Name).ToListAsync(); - } - } -} diff --git a/save-points/08-templated-components/BlazingPizza.Server/pizza.db-shm b/save-points/08-templated-components/BlazingPizza.Server/pizza.db-shm new file mode 100644 index 0000000000000000000000000000000000000000..7b8f383c3b8a7ccffba7f5c3993270d890352888 GIT binary patch literal 32768 zcmeI*H%>!A6oug-XE51BlcULL4^*s*9Z=9w&{Duw*a0;ywK<0*IxZ5DnbCiwqbFHo zztPwG-s;m%a@y3ElqzR>9;o%<<>$-V&Ba5bwsL=aae8$=|2TH{a$Wu9dHvK|{JV{B z`S|$jp?9ZN)%R#uJJe3KOYK&B)Lyku?NY}=&E~_i*s=B7Gs~hU3x}|Qbb=7LS>Ylo<+RS(VywB%d{XK#J0tg_0 z00IagfB*srAbzQ0{-Vci3oV^0f`8B>O>y#%n1?^@Wc-i5%9c~Jn}xH zCXc%|_m-Y@Lm~og=`eEaADr==ArcYrlqV7q@QkfI;t5+MBH;OEBqHGHa(TqF^^k~w_au?B z1iYh)L)hl6R+*V4bWJ1f5ReNs#a$K;j%%#$y5E{UizU#(@{W0$5^! z1$Gx8!1K*TkCPK$>anLzn>v%)Gj`)~>Kl*UUel?a)Nzx#NvCcdw{BynZf(c0W5;Ri z`aJe{-1ffi?X3 z@{=D)IDe`?^oQTR@xmFBq|>I)y#2+sW54l7|1zD7uo7b|@j{K3jCNA`(4ncf8I2_G zA@a{Em+609AU~(o9r9DDPqRO6^U&0_`122uBZn4#EFXVr;b#j!p8fRP(?_Rg@95uq zR8DVd2m#y5sYmaaH`kOS}El!+OK%)4IEtBs$MAaiPcvV(%bSC8{=|)o`oKp)XQo*P@ zwP_4fn^*gFcm;-*m|}*lF(zY%%90BDm8dz^L`IMs=^Z4ss|S1x$F>=v8{rGI#PaoA zg#3_NMN$#zc0}pPne80@@Vo_j3acG2t_O)a5t7FXd%jDF~Y3lIDQ&cbzlSgm7 zY}%h;k#yTnrKp&fN*hi6f<)UyI3IG5~vK{Xt4FNsQ!F-I9O`( zAY4P^m=LK!DNU@5?zK!j7$fyZsaQrOjnRXU4OC1Cfh~-NQttfDywdsGZl&|-22)^Z zPE>y`40m2ler=r}l)7){J+#P->!~_8A0rk7wjoceF*7e%qsz>iz>PUHqC!S~`|NSO z;mQ@=i%n(Z337I^BAN05fv!v9$nM;*!^qJAN0{lVjZcW=zM>ivb(CI?W$M!4;kbtGZ_mgkt>aN~yV&Iu*F zFp3|`Zmk~G8&00o-4PW;GP_0j-|R4roHS4vgnz;r(95nFl{)p@T$vYGsZvu1 zGdk~k_oN9&?=`2%bWaGpL?$3J=C-J|9~83=i_6Oh{i#AG<>(z$%}TJ;ZfGX*x_k|h zuS}!G2<4^O8N*vnPMXfLNzN*NKX&VRz20!)g6_rM71_tM$%Wg?7a38rd1N>Onj?ci z$N`nhsU4jVj-j$+qH@2BksOrQ>1s3R+Q=BxFzmk^jZB%>dPyRIavYg41TRbq)Sycw zUYebwcesa?u>Hz87;y#709h2b4E zIr5rkX}{E%S^5A|Z$cCYp&rQ~vrONgMd_2uqU^}8gh%8zyTqXx`H^r_!RbG9h)lCZ zP7r2f_wW$X$id5X@(_NNlw7=ZMW;8MIitH{?t%ASUHUH(hlc9Vyjt{M!XD(oVefrJ zV?6#b!Aqv2IdZr?s@a9oQS_8 zkQML+0SG_<0uX=z1Rwwb2tWV=5ID#JGxFfn&kH==`TgH~=X<~Q6MSCaAcq`dg8&2| z009U<00Izz00bZa0SN2~=;bYSUEtgAdilS7{z&K_;qwA}KG=W&1Rwwb2tWV=5P$## zAOHaf9Ap9I{})1C7kK7<-}%z79{FuEJ}+>PLyoaQ00Izz00bZa0SG_<0uX=z1oi}u z%3JEXz?m!m#(wr!^JRQqV9y5|5P$##AOHafKmY;|fB*y_0D*%npezBX>jEEr=Q}?3 zgQu51fX@pY{2BGv`=e6Rrl2tWV= z5P$##AOHafKmY;|ILHEz%7ata1zuu4VcuDDd<5$P2RY;z8w4N#0SG_<0uX=z1Rwwb z2tZ&@;Do%Tt_v7G{0INx_#dB3&dqnG<_`-~^M5k`OLO$Rd-l_FPamD0y`z8ck+05# zr~k<`cUU;|itaeccHqC}JBLb!)2DTJFG+NsW8y-Q5yam2N4zP@ouP~ww+lK;EiuImTVqVd43#An^ea(wtci>uH_|&uYF7{V7>;c-LN~$}Xo=>zB!?ozv9ekEf_$ASRFAc-gc+!y@Un zpGr|NFO@c$`UQ!$iF9CbZg%nJGYfjd*|WM^0VPlwzR_UoWl{b4@Nlry2KPYwI&U1R%2#futt}eHGvy*XhemK{H=2{hU6996k9Jc z9kI!=5|g7_60hv%669oKMREoN1iCJXIqOKm{Oz;H^@b}~bT2j)xRJvnyK}>gBS#0C zVWzA0eZoZ8S5!l)B6&HMsY`=%bL7PJ@^!IQ8$P!+6Gb`miSIp5eIG5+BmGp{zITAA zPJ zNa}Z!hqE~D!1yy{-}RiF zBezzM>J2AP>h6dNBAK3|{BL%cMot0UBLtt5HB5P)c z_tOQ57w!u)W<2sNow?U6)l89`RkNeN`S!!gEWNGM%+eIkG5uMpY)+4xrOJ`lJWKnf z#>~;9zG0lZRi$79bf+x=l+?achdLpKnvT~msda)$oBO!Q9j)S@` z@E*fMAN$vzd4ZifRG2zC^|`49@7xEDT%Y;)^uL&?9{R|1cj|M;ugv}E*hi1KW?z}L z9{tqRJLJ-@{fkteKYu}Y^QiLhuUun-@@s+S)OoTWt6*n>peM1 zOoKVvyI?Kee!`$Pn9aHudCiF@pV}F|%G5RYh~EC=BQs;K_TJ&ac_>%0?~b7|NBA;Z zCl5YtmaHA9AsmU-J;Jz7bFICnhe71EFW6)eVK8#FZ`zr7+0^ghRikORJ0wAAd$HeJ zZMEdReY9Flf|yfBJ^bq4PaSz*-=mYCQI&UgIbc32LXi~|uRHB^`zSK?$mDUS&695X z`+B3fs`iF`=633&@(%PKv!&b0|pt1}4R*U*~;; zqEyq5NpHJf(l{IwwZ7ps6eT7~vB@#H-?ZqpI&ghmX2n}i-D{Cx(0H#inn|G~oW5;2 zp`7)1doQ7b{K~1IIqQ4-rzXvc-r>Qt7(SE6ug|IHJ$b2^aO$f$e5}~u=&trkFgV-Q z^LK0`6K9#);o)gE+--6JPjNw791O47;Lf%U;+@5;0ccr(F zTnD@y&DJzA@9m$Q6!YHULChcMVPNlKru#Rk z-+uqh?L93FI?zit-J=IX1xLHkFHZWPK8D=XJu$Hl{qtb75545`_vph=!O=eS4$2N{ zAGou6!zJ=ydq!c9b>yqO=Gj(}Gxi%?iv^Qw6j{Ae9&v|qYnxKa$gK>Xa(hp5H+63w zJ7T#&zvJ>|usC`Ko|`b@eFaCmF&J^LViS3VIQ*Xt7cc7W#+A!&g5BMv`@cQWZlCS9 z*#8xp_R!#bS5n7achv{%e#Q65GIEC;Zby4%xNK5eBlpEYy%X+=+In)zj@bJlcV+kq zOs#hKvA9=84k9VBxc`ZG{L|M^vq~p#KlQL4zonFaxvI{I{l7pQEC&y=Y3BvGJokPR zi{Da?``uq}UErkrRLUeOA{6e(jbm6BcmqZfU4{SzAOHafKmY;|fB*y_009WRb^(K2L|qs7 z*4>wX{%2Qy@^@$DMCJd%P~N~71Rwwb2tWV=5P$##AOHafKmY;bk&RqRGe*8kp}^C5g*;DAOO!-4<=AOHafKmY;|fB*y_009UL3!IgA)pdct z|0CZk@0LF7!n(jP680bf0SG_<0uX=z1Rwwb2tWV=2UOq*d0gtcz`I{+d_ViczxjLk zJAwlmZ43(n5P$##AOHafKmY;|fB*y_Ff4FR-c{EHLN9;T@n3KL?yFcA7)HV#1Rwwb z2tWV=5P$##AOHafK;VE180B%P>jIy({ja%?zVqWRU|ryVMjOL|00bZa0SG_<0uX=z z1Rwwb2n-9Hmv_~50srpfuYT{sOJBsgz%UZ_AOHafKmY;|fB*y_009U<00IY8z$A}L zT^Hzl?T5AJeZFH@7dW8N#;_m&0SG_<0uX=z1Rwwb2tWV=!vYuNU3FdHe~P|W#eb;( z_gEJgM#3HhAOHafKmY;|fB*y_009U<;D8D|DUVBC7x?q}Z_hb?>93cuE^t7jjbT9m z0uX=z1Rwwb2tWV=5P$##h6OIlyXv~Y#vlEjqxJ0j{}Ss0!${bJ00bZa0SG_<0uX=z z1Rwwb2pmv>r{r;|>jHoMvyXj0`QN|(%{h{G>hSE;!oQmPtK%1refL;t_9wH_(Z4y` zJi2h?H;+87|Db+-<|{L+4}IpL!_$Go-#vVnWX2Z+4xGTQS#P*;QFrq!TQ4%5U^bUv zcX#Ow-)OM)a<2a~Sk$Iky(!9_p^U+pkIEWN6U&&4@tD!1Eom}dHtkhuTFhV78|R-E8hv&j=zbN=z{z&~=G)v6bIu3R19`OEaR#@^!M6={A_eaK3B% zdoY|~VnzMF4d+%2)Rs+Gji$ZEb$JkDx^8|AT_39F z!FsM1(RBRiWxXLlI&PlSajMf`1zIB7Bg|Lt+t)$SiQUs=S-iP$NpA>~zBnfJ#mm>l zR*flU*xG2&uiUpc+QJk2Gn8p@_bI)>OU|i_YKN4`D&~9)$F>=v>n;`rG82QvUi#Df z`YO!yWE9xjTnTev>kHMCB zso(ZmESOx=UKTZZG$qG&VUX3d*f8l0m&oWZC_Nw`LX564LHYXZ78@}}l9R-XV_O}{ z-D^oxMjmX87iu)e?lMI+uW9ie=kFiBS8VcIIY{6`7Ay)33<7!khq{%gTe|vjJ)o0>~S+pHfBP-_mxAVQ$hhwTH5684uMn)YRe=ULC zdothKkjFjTvgQ$eD5U-Ld(0>j(i?A@F{I6tPU^umJi}KRa%s1Yrko+KahK#*Idxs& zpC9}6SHAFE?nQiF;K04$Vn7gp00bZa0SG_<0uX=z1Rwx`aRQg+M0H&t_=SHu_sM6k z$FVLjjtXfIfB*y_009U<00Izz00bZafdeP7D33^87ufp5=USh=_1M?3E^y%Di~&Ia z0uX=z1Rwwb2tWV=5P$###tA$vC#vfLD_?fiKJequJd1UKaa2fy00bZa0SG_<0uX=z z1Rwwb2pl+pEAoicb%D>v&$OQMU41*&1rA)CF(3#)00Izz00bZa0SG_<0uX?}IDxBj zqPi|%|AW@tpT7JdJ=O)rQ6UWi5P$##AOHafKmY;|fB*y_aNq>Y@`%)Rfm`qS<}087 zVdbY-7dUWn#(*FI0SG_<0uX=z1Rwwb2tWV=;{>kBiR!w*A2Kh0|0~-+O=DeP92L?a z009U<00Izz00bZa0SG_<0tZgux;!FvUEmwS_Z(mS@hh)jUEsjQ83Td<1Rwwb2tWV= z5P$##AOHafj1#cPiR!w*3%~sfbMv83+`ziPI4Yz;00Izz00bZa0SG_<0uX=z1P+{l zm5j)$t_$dN?|aqyvv0i*>jDQZ&KM8`AOHafKmY;|fB*y_009UmU5w_q89$>jFpS98(Lwz7U!Ji+N%G%-lET zevKsH3jz>;00bZa0SG_<0uX=z1g55b@yN{7N&d!p*EN?bBhW=wV);7F8G{ndv2@+o zV0U+E;|?oTj1pg?C7uzDbiHWI(;~~Uweoc(gLu703*`zUuo8W3yHSqr?S=KE{;*@w zYQ5$NN|!_<$5t7mNON@YsxjY^jC|cl_gc}^rW}_mT4%~-mNEJmjxATD<(Zi&!*%;v ztL2)_u~A{_Mz(H@@bw~Jzjp1KrhJ}sL@u7GFh&pAUVDi2V&g4WNG~iw$ylL9W344t z1fH*n*Nj22en~P)6`J%W-)8xictcZ{no${7zYuA(%?P3}t)DX7JmI)vwOw0wq#JCZ zYb;dQLY1jsHCA|ujI&i>dR`pUBF7j;WUd;^En1-K62lY;s&R)FYQ`?#GPWApW*J)Q z%58dDr4r5YYQ@FFa=_ktofz~$B{Ifdl;k?f0<%LZQXZ28(xkUMYdqvOAH+%(r(9f0_Jk{#i(^EwP~!fB>H@bOn?F@JeUB={+_vfkW3bV z-Q|Unj`VnE*(y&lWeO+^U4^Ac0$Y&9uNgNgUE>bl;)-%G1m8$-lk7Bgnt+>lgmybCxg5>jJ0d{`b_v_ZGgi@R@~=EWEVPSa^0J zvhd8p<%JXTKb`;5{HNzXH2<#o#(aL>KmYXnqa-uFAOHafKmY;|fB*y_009U<;0-45 z=&9+c3nx5Wi|N09+palIot&P!a$@Ag+HuYD_+!&kc9M7Rg}MJiEG}KMJ$^zymX;X0 zYP?)yifpT97HEN4T)E~r{^<0S;eLXr&+PfwXoxCMzV zRCuxmQekL867AQPPA`z&oK8zEq0ErgkOJLiX~Al-k|l*x^Q5Yi5k43VE92 zL;`T)*!0xJ6TViVDlbupbeXYVvpqaJJ$3FxLR}XiOC=87x;zun!lU=)Dz#5*9CMB{d|i2hc5^~00I#B|3%>aQ@Yux!Tnpcqesph zwXN9PzGZ6JX7RaJ+{;T#7O!o^y5jV>mX@4L4qGa1b2x1lo6T&on=LM*&GL-H@r=!R zZOLVI*;l+JUuY%X2rjo<4Atd&`>1X@dldcd6PMt8S;=CWfexng71edVfu)w3ehw_DvxVOrk|SG56<59Hwt3m=*>PF&X&2Mo^6v=Ir5fLfc(QHx`euPjIl5GA zCG4dNORaz{Wo8pzhlg!ML&;2WD`4BqC$sIXM4{5~aofpiVr99Vu(z6V#}Zq%a8#Ts zC!3fzHd8#^ zN+df%W7`q6TI0^(wv&&oNFm3TGgykJ+O=rb)r?97#^3D(A}fOEuZpFK-%U71G#zRY_04TpDaW4YPP z@YRB}$VH$jF(*wUpSezH##+eaa0nUqH{ap z-u8rC%gtP9Ih60ZDLP)*?5?NF)o_vP?$*RDDUuB=S1j&iuuajD5Z$yUY7v_?kfPGz zPBOf;!!`>IkDJZ;GMQvGQnuHUIe*gL2nJS!be)cuGKusmovQeA8KL2I!P2(9LFMK_+&c@x%Hu_=(l z+eyJ+iLOVsc}LtGOveK|S5 z+ANt@t?9(Fb2mXtsnuG$Kvz9dg!9Csop>_ZE*6##*mf~HQP)PdEYt&B$6rgVrHYmUlWh3os~u05jyfG#Y9|m{OXkC3d?#vN z*=n(?bxWM5GP{YQGuKE}H)DA}*QthhubEFcGR2L0C&jHgwxbrI72Tra*&U~aV;dc| z7PE^i-QJ;+T#07GJ5hT%lg-k}3fmM{Y|*ZlcTt_-=B_1T*_7hBZepGC*g}cOR>ihr z5Bei^k6CnVZCWf;utJrbCA!hhIy<3g!@1s(Y}R7JQniHI!A{cNu`PKwZL88oR&>{@ zD_hG^pJT~FuEnt(cO{4=tv)J32 zU5YD|b1sX2s~hXmwXIyK$WujUCc2zWx4rQw6VGM*?M|~BaBaoS3BFP9xF`n`-bqWo zoINabGh5|CC%Z&fnqjv&BxJMoT##ybTS8&8wcD|Uy2d^(M+@Lk`Ugl)Myh$F zjuDnUR(G=Gv+a<3)^3}2m*c6zDpTBbIm>aIrxXa)7%sxD2bf~QWvL{JnQFvS5<4Zk ztKDLnjAxCuIXkiDQpsA4EayGDN!Lc(=iHH2z3zfNkl)DEqJgllCY7C4hts>BZWiKg zPi}X2Da?77OVMSA-)g1v=}g{TD=$Zz^m5h1+FfpRR&RoegaXlM))`wW_?)ROXBC&EWx8FZwm03I zzLlbb+*NZsF4snLJ-WI|Te^Z!a4kEd-R+Pskta985L+s(N%ak`$x9_F%6CGAx@U7O z*tV8;=uTlvqH2|ZnA{+9&|+b2fo02X$G7IA))Qe{gpG1^cx|PV2rmov zWYn5p&srUu@oXWv)!d=-mVDj36$$J{+Yuid%Y>r&vRm59(L9&WvF-IjFj@0f-RXFn zPPX!yf;HyM1_M-*4Rp=9;3%okD@ah|I;OH_0AOHafKmY;|fB*y_009U< R00NT*W)Gh^+W)-3{{=7jX*K`= literal 0 HcmV?d00001 diff --git a/save-points/08-templated-components/BlazingPizza.Shared/Address.cs b/save-points/08-templated-components/BlazingPizza.Shared/Address.cs index d76bc52a..79be9c5b 100644 --- a/save-points/08-templated-components/BlazingPizza.Shared/Address.cs +++ b/save-points/08-templated-components/BlazingPizza.Shared/Address.cs @@ -1,27 +1,24 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class Address { - public class Address - { - public int Id { get; set; } + public int Id { get; set; } - [Required, MaxLength(100)] - public string Name { get; set; } + [Required, MaxLength(100)] + public string Name { get; set; } - [Required, MaxLength(100)] - public string Line1 { get; set; } + [Required, MaxLength(100)] + public string Line1 { get; set; } - [MaxLength(100)] - public string Line2 { get; set; } + [MaxLength(100)] + public string Line2 { get; set; } - [Required, MaxLength(50)] - public string City { get; set; } + [Required, MaxLength(50)] + public string City { get; set; } - [Required, MaxLength(20)] - public string Region { get; set; } + [Required, MaxLength(20)] + public string Region { get; set; } - [Required, MaxLength(20)] - public string PostalCode { get; set; } - } + [Required, MaxLength(20)] + public string PostalCode { get; set; } } diff --git a/save-points/08-templated-components/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/save-points/08-templated-components/BlazingPizza.Shared/BlazingPizza.Shared.csproj index f7b7dd02..fb17e53b 100644 --- a/save-points/08-templated-components/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/save-points/08-templated-components/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -3,8 +3,13 @@ $(TargetFrameworkVersion) BlazingPizza + true + + + + diff --git a/save-points/08-templated-components/BlazingPizza.Shared/LatLong.cs b/save-points/08-templated-components/BlazingPizza.Shared/LatLong.cs index 9b8c3811..14a94c26 100644 --- a/save-points/08-templated-components/BlazingPizza.Shared/LatLong.cs +++ b/save-points/08-templated-components/BlazingPizza.Shared/LatLong.cs @@ -1,27 +1,26 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class LatLong { - public class LatLong - { - public LatLong() - { - } + public LatLong() + { + } - public LatLong(double latitude, double longitude) : this() - { - Latitude = latitude; - Longitude = longitude; - } + public LatLong(double latitude, double longitude) : this() + { + Latitude = latitude; + Longitude = longitude; + } - public double Latitude { get; set; } + public double Latitude { get; set; } - public double Longitude { get; set; } + public double Longitude { get; set; } - public static LatLong Interpolate(LatLong start, LatLong end, double proportion) - { - // The Earth is flat, right? So no need for spherical interpolation. - return new LatLong( - start.Latitude + (end.Latitude - start.Latitude) * proportion, - start.Longitude + (end.Longitude - start.Longitude) * proportion); - } - } -} + public static LatLong Interpolate(LatLong start, LatLong end, double proportion) + { + // The Earth is flat, right? So no need for spherical interpolation. + return new LatLong( + start.Latitude + (end.Latitude - start.Latitude) * proportion, + start.Longitude + (end.Longitude - start.Longitude) * proportion); + } +} \ No newline at end of file diff --git a/save-points/08-templated-components/BlazingPizza.Shared/NotificationSubscription.cs b/save-points/08-templated-components/BlazingPizza.Shared/NotificationSubscription.cs index 04259c2f..9109ff57 100644 --- a/save-points/08-templated-components/BlazingPizza.Shared/NotificationSubscription.cs +++ b/save-points/08-templated-components/BlazingPizza.Shared/NotificationSubscription.cs @@ -1,17 +1,14 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class NotificationSubscription { - public class NotificationSubscription - { - public int NotificationSubscriptionId { get; set; } + public int NotificationSubscriptionId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public string Url { get; set; } + public string Url { get; set; } - public string P256dh { get; set; } + public string P256dh { get; set; } - public string Auth { get; set; } - } + public string Auth { get; set; } } diff --git a/save-points/08-templated-components/BlazingPizza.Shared/Order.cs b/save-points/08-templated-components/BlazingPizza.Shared/Order.cs index fb003bd6..aca04ca1 100644 --- a/save-points/08-templated-components/BlazingPizza.Shared/Order.cs +++ b/save-points/08-templated-components/BlazingPizza.Shared/Order.cs @@ -1,25 +1,32 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +public class Order { - public class Order - { - public int OrderId { get; set; } + public int OrderId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public DateTime CreatedTime { get; set; } + public DateTime CreatedTime { get; set; } - public Address DeliveryAddress { get; set; } = new Address(); + public Address DeliveryAddress { get; set; } = new Address(); - public LatLong DeliveryLocation { get; set; } + public LatLong DeliveryLocation { get; set; } - public List Pizzas { get; set; } = new List(); + public List Pizzas { get; set; } = new List(); - public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); + public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); - public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); - } + public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Default, PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] +[JsonSerializable(typeof(Order))] +[JsonSerializable(typeof(OrderWithStatus))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Pizza))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Topping))] +public partial class OrderContext : JsonSerializerContext {} \ No newline at end of file diff --git a/save-points/08-templated-components/BlazingPizza.Shared/OrderWithStatus.cs b/save-points/08-templated-components/BlazingPizza.Shared/OrderWithStatus.cs index 021de78c..f5f153b6 100644 --- a/save-points/08-templated-components/BlazingPizza.Shared/OrderWithStatus.cs +++ b/save-points/08-templated-components/BlazingPizza.Shared/OrderWithStatus.cs @@ -1,79 +1,78 @@ -using BlazingPizza.ComponentsLibrary.Map; -using System; -using System.Collections.Generic; +using System.Text.Json.Serialization; +using BlazingPizza.ComponentsLibrary.Map; -namespace BlazingPizza + +namespace BlazingPizza; + +public class OrderWithStatus { - public class OrderWithStatus - { - public readonly static TimeSpan PreparationDuration = TimeSpan.FromSeconds(10); - public readonly static TimeSpan DeliveryDuration = TimeSpan.FromMinutes(1); // Unrealistic, but more interesting to watch + public readonly static TimeSpan PreparationDuration = TimeSpan.FromSeconds(10); + public readonly static TimeSpan DeliveryDuration = TimeSpan.FromMinutes(1); // Unrealistic, but more interesting to watch - public Order Order { get; set; } + public Order Order { get; set; } - public string StatusText { get; set; } + public string StatusText { get; set; } - public bool IsDelivered => StatusText == "Delivered"; + public bool IsDelivered => StatusText == "Delivered"; - public List MapMarkers { get; set; } + public List MapMarkers { get; set; } - public static OrderWithStatus FromOrder(Order order) - { - // To simulate a real backend process, we fake status updates based on the amount - // of time since the order was placed - string statusText; - List mapMarkers; - var dispatchTime = order.CreatedTime.Add(PreparationDuration); + public static OrderWithStatus FromOrder(Order order) + { + // To simulate a real backend process, we fake status updates based on the amount + // of time since the order was placed + string statusText; + List mapMarkers; + var dispatchTime = order.CreatedTime.Add(PreparationDuration); - if (DateTime.Now < dispatchTime) - { - statusText = "Preparing"; - mapMarkers = new List - { - ToMapMarker("You", order.DeliveryLocation, showPopup: true) - }; - } - else if (DateTime.Now < dispatchTime + DeliveryDuration) - { - statusText = "Out for delivery"; + if (DateTime.Now < dispatchTime) + { + statusText = "Preparing"; + mapMarkers = new List + { + ToMapMarker("You", order.DeliveryLocation, showPopup: true) + }; + } + else if (DateTime.Now < dispatchTime + DeliveryDuration) + { + statusText = "Out for delivery"; - var startPosition = ComputeStartPosition(order); - var proportionOfDeliveryCompleted = Math.Min(1, (DateTime.Now - dispatchTime).TotalMilliseconds / DeliveryDuration.TotalMilliseconds); - var driverPosition = LatLong.Interpolate(startPosition, order.DeliveryLocation, proportionOfDeliveryCompleted); - mapMarkers = new List - { - ToMapMarker("You", order.DeliveryLocation), - ToMapMarker("Driver", driverPosition, showPopup: true), - }; - } - else - { - statusText = "Delivered"; - mapMarkers = new List - { - ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), - }; - } + var startPosition = ComputeStartPosition(order); + var proportionOfDeliveryCompleted = Math.Min(1, (DateTime.Now - dispatchTime).TotalMilliseconds / DeliveryDuration.TotalMilliseconds); + var driverPosition = LatLong.Interpolate(startPosition, order.DeliveryLocation, proportionOfDeliveryCompleted); + mapMarkers = new List + { + ToMapMarker("You", order.DeliveryLocation), + ToMapMarker("Driver", driverPosition, showPopup: true), + }; + } + else + { + statusText = "Delivered"; + mapMarkers = new List + { + ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), + }; + } - return new OrderWithStatus - { - Order = order, - StatusText = statusText, - MapMarkers = mapMarkers, - }; - } + return new OrderWithStatus + { + Order = order, + StatusText = statusText, + MapMarkers = mapMarkers, + }; + } - private static LatLong ComputeStartPosition(Order order) - { - // Random but deterministic based on order ID - var rng = new Random(order.OrderId); - var distance = 0.01 + rng.NextDouble() * 0.02; - var angle = rng.NextDouble() * Math.PI * 2; - var offset = (distance * Math.Cos(angle), distance * Math.Sin(angle)); - return new LatLong(order.DeliveryLocation.Latitude + offset.Item1, order.DeliveryLocation.Longitude + offset.Item2); - } + private static LatLong ComputeStartPosition(Order order) + { + // Random but deterministic based on order ID + var rng = new Random(order.OrderId); + var distance = 0.01 + rng.NextDouble() * 0.02; + var angle = rng.NextDouble() * Math.PI * 2; + var offset = (distance * Math.Cos(angle), distance * Math.Sin(angle)); + return new LatLong(order.DeliveryLocation.Latitude + offset.Item1, order.DeliveryLocation.Longitude + offset.Item2); + } - static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) - => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; - } -} + static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) + => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; +} \ No newline at end of file diff --git a/save-points/08-templated-components/BlazingPizza.Shared/Pizza.cs b/save-points/08-templated-components/BlazingPizza.Shared/Pizza.cs index ec1108a9..459298f4 100644 --- a/save-points/08-templated-components/BlazingPizza.Shared/Pizza.cs +++ b/save-points/08-templated-components/BlazingPizza.Shared/Pizza.cs @@ -1,42 +1,44 @@ -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// /// Represents a customized pizza as part of an order +/// +public class Pizza { - /// - /// Represents a customized pizza as part of an order - /// - public class Pizza - { - public const int DefaultSize = 12; - public const int MinimumSize = 9; - public const int MaximumSize = 17; + public const int DefaultSize = 12; + public const int MinimumSize = 9; + public const int MaximumSize = 17; - public int Id { get; set; } + public int Id { get; set; } - public int OrderId { get; set; } + public int OrderId { get; set; } - public PizzaSpecial Special { get; set; } + public PizzaSpecial Special { get; set; } - public int SpecialId { get; set; } + public int SpecialId { get; set; } - public int Size { get; set; } + public int Size { get; set; } - public List Toppings { get; set; } + public List Toppings { get; set; } - public decimal GetBasePrice() - { - return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; - } + public decimal GetBasePrice() + { + return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; + } - public decimal GetTotalPrice() - { - return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); - } + public decimal GetTotalPrice() + { + return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); + } - public string GetFormattedTotalPrice() - { - return GetTotalPrice().ToString("0.00"); - } - } + public string GetFormattedTotalPrice() + { + return GetTotalPrice().ToString("0.00"); + } } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Serialization)] +[JsonSerializable(typeof(Pizza))] +public partial class PizzaContext : JsonSerializerContext {} \ No newline at end of file diff --git a/save-points/08-templated-components/BlazingPizza.Shared/PizzaSpecial.cs b/save-points/08-templated-components/BlazingPizza.Shared/PizzaSpecial.cs index 2f2b3383..9653300c 100644 --- a/save-points/08-templated-components/BlazingPizza.Shared/PizzaSpecial.cs +++ b/save-points/08-templated-components/BlazingPizza.Shared/PizzaSpecial.cs @@ -1,20 +1,19 @@ -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// Represents a pre-configured template for a pizza a user can order +/// +public class PizzaSpecial { - /// - /// Represents a pre-configured template for a pizza a user can order - /// - public class PizzaSpecial - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal BasePrice { get; set; } + public decimal BasePrice { get; set; } - public string Description { get; set; } + public string Description { get; set; } - public string ImageUrl { get; set; } + public string ImageUrl { get; set; } - public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); - } -} + public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); +} \ No newline at end of file diff --git a/save-points/08-templated-components/BlazingPizza.Shared/PizzaTopping.cs b/save-points/08-templated-components/BlazingPizza.Shared/PizzaTopping.cs index f5a6c1ac..0a711647 100644 --- a/save-points/08-templated-components/BlazingPizza.Shared/PizzaTopping.cs +++ b/save-points/08-templated-components/BlazingPizza.Shared/PizzaTopping.cs @@ -1,11 +1,11 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class PizzaTopping { - public class PizzaTopping - { - public Topping Topping { get; set; } + public Topping Topping { get; set; } + + public int ToppingId { get; set; } - public int ToppingId { get; set; } - - public int PizzaId { get; set; } - } -} + public int PizzaId { get; set; } + +} \ No newline at end of file diff --git a/save-points/08-templated-components/BlazingPizza.Shared/Topping.cs b/save-points/08-templated-components/BlazingPizza.Shared/Topping.cs index 61bdeb92..376c311a 100644 --- a/save-points/08-templated-components/BlazingPizza.Shared/Topping.cs +++ b/save-points/08-templated-components/BlazingPizza.Shared/Topping.cs @@ -1,13 +1,13 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class Topping { - public class Topping - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal Price { get; set; } + public decimal Price { get; set; } - public string GetFormattedPrice() => Price.ToString("0.00"); - } -} + public string GetFormattedPrice() => Price.ToString("0.00"); + +} \ No newline at end of file diff --git a/save-points/08-templated-components/BlazingPizza.Shared/UserInfo.cs b/save-points/08-templated-components/BlazingPizza.Shared/UserInfo.cs index 4996ef80..362f8f8e 100644 --- a/save-points/08-templated-components/BlazingPizza.Shared/UserInfo.cs +++ b/save-points/08-templated-components/BlazingPizza.Shared/UserInfo.cs @@ -1,9 +1,9 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class UserInfo { - public class UserInfo - { - public bool IsAuthenticated { get; set; } + public bool IsAuthenticated { get; set; } - public string Name { get; set; } - } -} + public string Name { get; set; } + +} \ No newline at end of file diff --git a/save-points/09-progressive-web-app/BlazingPizza.Client/BlazingPizza.Client.csproj b/save-points/09-progressive-web-app/BlazingPizza.Client/BlazingPizza.Client.csproj index 7fecc21b..3573ae56 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/save-points/09-progressive-web-app/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -2,6 +2,7 @@ $(TargetFrameworkVersion) + enable diff --git a/save-points/09-progressive-web-app/BlazingPizza.Client/JSRuntimeExtensions.cs b/save-points/09-progressive-web-app/BlazingPizza.Client/JSRuntimeExtensions.cs index 89da520c..cc242348 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Client/JSRuntimeExtensions.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Client/JSRuntimeExtensions.cs @@ -1,13 +1,11 @@ using Microsoft.JSInterop; -using System.Threading.Tasks; -namespace BlazingPizza.Client +namespace BlazingPizza.Client; + +public static class JSRuntimeExtensions { - public static class JSRuntimeExtensions - { - public static ValueTask Confirm(this IJSRuntime jsRuntime, string message) - { - return jsRuntime.InvokeAsync("confirm", message); - } - } + public static ValueTask Confirm(this IJSRuntime jsRuntime, string message) + { + return jsRuntime.InvokeAsync("confirm", message); + } } diff --git a/save-points/09-progressive-web-app/BlazingPizza.Client/OrderState.cs b/save-points/09-progressive-web-app/BlazingPizza.Client/OrderState.cs index 5265ae39..4f47979d 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Client/OrderState.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Client/OrderState.cs @@ -1,55 +1,52 @@ -using System.Collections.Generic; +namespace BlazingPizza.Client; -namespace BlazingPizza.Client +public class OrderState { - public class OrderState - { - public bool ShowingConfigureDialog { get; private set; } - - public Pizza ConfiguringPizza { get; private set; } - - public Order Order { get; private set; } = new Order(); - - public void ShowConfigurePizzaDialog(PizzaSpecial special) - { - ConfiguringPizza = new Pizza() - { - Special = special, - SpecialId = special.Id, - Size = Pizza.DefaultSize, - Toppings = new List(), - }; - - ShowingConfigureDialog = true; - } - - public void CancelConfigurePizzaDialog() - { - ConfiguringPizza = null; - ShowingConfigureDialog = false; - } - - public void ConfirmConfigurePizzaDialog() - { - Order.Pizzas.Add(ConfiguringPizza); - ConfiguringPizza = null; - - ShowingConfigureDialog = false; - } - - public void RemoveConfiguredPizza(Pizza pizza) - { - Order.Pizzas.Remove(pizza); - } - - public void ResetOrder() - { - Order = new Order(); - } - - public void ReplaceOrder(Order order) - { - Order = order; - } - } + public bool ShowingConfigureDialog { get; private set; } + + public Pizza ConfiguringPizza { get; private set; } + + public Order Order { get; private set; } = new Order(); + + public void ShowConfigurePizzaDialog(PizzaSpecial special) + { + ConfiguringPizza = new Pizza() + { + Special = special, + SpecialId = special.Id, + Size = Pizza.DefaultSize, + Toppings = new List(), + }; + + ShowingConfigureDialog = true; + } + + public void CancelConfigurePizzaDialog() + { + ConfiguringPizza = null; + ShowingConfigureDialog = false; + } + + public void ConfirmConfigurePizzaDialog() + { + Order.Pizzas.Add(ConfiguringPizza); + ConfiguringPizza = null; + + ShowingConfigureDialog = false; + } + + public void RemoveConfiguredPizza(Pizza pizza) + { + Order.Pizzas.Remove(pizza); + } + + public void ResetOrder() + { + Order = new Order(); + } + + public void ReplaceOrder(Order order) + { + Order = order; + } } diff --git a/save-points/09-progressive-web-app/BlazingPizza.Client/OrdersClient.cs b/save-points/09-progressive-web-app/BlazingPizza.Client/OrdersClient.cs index 01c63572..59dcb35b 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Client/OrdersClient.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Client/OrdersClient.cs @@ -1,41 +1,35 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Net.Http.Json; -using System.Threading.Tasks; - -namespace BlazingPizza.Client +using System.Net.Http.Json; + +namespace BlazingPizza.Client; + +public class OrdersClient { - public class OrdersClient - { - private readonly HttpClient httpClient; + private readonly HttpClient httpClient; - public OrdersClient(HttpClient httpClient) - { - this.httpClient = httpClient; - } + public OrdersClient(HttpClient httpClient) + { + this.httpClient = httpClient; + } - public async Task> GetOrders() => - await httpClient.GetFromJsonAsync>("orders"); + public async Task> GetOrders() => + await httpClient.GetFromJsonAsync("orders", OrderContext.Default.ListOrderWithStatus); - public async Task GetOrder(int orderId) => - await httpClient.GetFromJsonAsync($"orders/{orderId}"); + public async Task GetOrder(int orderId) => + await httpClient.GetFromJsonAsync($"orders/{orderId}", OrderContext.Default.OrderWithStatus); - public async Task PlaceOrder(Order order) - { - var response = await httpClient.PostAsJsonAsync("orders", order); - response.EnsureSuccessStatusCode(); - var orderId = await response.Content.ReadFromJsonAsync(); - return orderId; - } + public async Task PlaceOrder(Order order) + { + var response = await httpClient.PostAsJsonAsync("orders", order, OrderContext.Default.Order); + response.EnsureSuccessStatusCode(); + var orderId = await response.Content.ReadFromJsonAsync(); + return orderId; + } - public async Task SubscribeToNotifications(NotificationSubscription subscription) - { - var response = await httpClient.PutAsJsonAsync("notifications/subscribe", subscription); - response.EnsureSuccessStatusCode(); - } - } + public async Task SubscribeToNotifications(NotificationSubscription subscription) + { + var response = await httpClient.PutAsJsonAsync("notifications/subscribe", subscription); + response.EnsureSuccessStatusCode(); + } } diff --git a/save-points/09-progressive-web-app/BlazingPizza.Client/PizzaAuthenticationState.cs b/save-points/09-progressive-web-app/BlazingPizza.Client/PizzaAuthenticationState.cs index 3f295928..f5bfef65 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Client/PizzaAuthenticationState.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Client/PizzaAuthenticationState.cs @@ -1,9 +1,8 @@ using Microsoft.AspNetCore.Components.WebAssembly.Authentication; -namespace BlazingPizza.Client +namespace BlazingPizza.Client; + +public class PizzaAuthenticationState : RemoteAuthenticationState { - public class PizzaAuthenticationState : RemoteAuthenticationState - { - public Order Order { get; set; } - } + public Order Order { get; set; } } diff --git a/save-points/09-progressive-web-app/BlazingPizza.Client/Program.cs b/save-points/09-progressive-web-app/BlazingPizza.Client/Program.cs index afeee128..41eedccb 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Client/Program.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Client/Program.cs @@ -1,31 +1,20 @@ using Microsoft.AspNetCore.Components.WebAssembly.Authentication; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; using Microsoft.Extensions.DependencyInjection; -using System; -using System.Net.Http; -using System.Threading.Tasks; +using BlazingPizza.Client; -namespace BlazingPizza.Client -{ - public class Program - { - public static async Task Main(string[] args) - { - var builder = WebAssemblyHostBuilder.CreateDefault(args); - builder.RootComponents.Add("#app"); +var builder = WebAssemblyHostBuilder.CreateDefault(args); +builder.RootComponents.Add("#app"); - builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); - builder.Services.AddHttpClient(client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)) - .AddHttpMessageHandler(); - builder.Services.AddScoped(); +builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); +builder.Services.AddHttpClient(client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)) + .AddHttpMessageHandler(); +builder.Services.AddScoped(); - // Add auth services - builder.Services.AddApiAuthorization(options => - { - options.AuthenticationPaths.LogOutSucceededPath = ""; - }); +// Add auth services +builder.Services.AddApiAuthorization(options => +{ + options.AuthenticationPaths.LogOutSucceededPath = ""; +}); - await builder.Build().RunAsync(); - } - } -} +await builder.Build().RunAsync(); diff --git a/save-points/09-progressive-web-app/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/save-points/09-progressive-web-app/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 1ec992ad..edb7908d 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/save-points/09-progressive-web-app/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -2,6 +2,7 @@ $(TargetFrameworkVersion) + enable diff --git a/save-points/09-progressive-web-app/BlazingPizza.ComponentsLibrary/LocalStorage.cs b/save-points/09-progressive-web-app/BlazingPizza.ComponentsLibrary/LocalStorage.cs index f36b098e..bb84f13c 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.ComponentsLibrary/LocalStorage.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.ComponentsLibrary/LocalStorage.cs @@ -1,17 +1,15 @@ using Microsoft.JSInterop; -using System.Threading.Tasks; -namespace BlazingPizza.ComponentsLibrary +namespace BlazingPizza.ComponentsLibrary; + +public static class LocalStorage { - public static class LocalStorage - { - public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) - => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); + public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) + => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); - public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object value) - => jsRuntime.InvokeVoidAsync("blazorLocalStorage.set", key, value); + public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object value) + => jsRuntime.InvokeVoidAsync("blazorLocalStorage.set", key, value); - public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key) - => jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key); - } -} + public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key) + => jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key); +} \ No newline at end of file diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/BlazingPizza.Server.csproj b/save-points/09-progressive-web-app/BlazingPizza.Server/BlazingPizza.Server.csproj index e1e7aaef..abd2317b 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -2,6 +2,7 @@ $(TargetFrameworkVersion) + true diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/AddressEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/AddressEntityType.cs new file mode 100644 index 00000000..82db81b6 --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/AddressEntityType.cs @@ -0,0 +1,92 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class AddressEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Address", + typeof(Address), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Address).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var city = runtimeEntityType.AddProperty( + "City", + typeof(string), + propertyInfo: typeof(Address).GetProperty("City", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var line1 = runtimeEntityType.AddProperty( + "Line1", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line1", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var line2 = runtimeEntityType.AddProperty( + "Line2", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line2", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var postalCode = runtimeEntityType.AddProperty( + "PostalCode", + typeof(string), + propertyInfo: typeof(Address).GetProperty("PostalCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var region = runtimeEntityType.AddProperty( + "Region", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Region", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Address"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs new file mode 100644 index 00000000..1dd4563b --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs @@ -0,0 +1,114 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class DeviceFlowCodesEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.DeviceFlowCodes", + typeof(DeviceFlowCodes), + baseEntityType); + + var userCode = runtimeEntityType.AddProperty( + "UserCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("UserCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var deviceCode = runtimeEntityType.AddProperty( + "DeviceCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("DeviceCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var key = runtimeEntityType.AddKey( + new[] { userCode }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deviceCode }, + unique: true); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "DeviceCodes"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs new file mode 100644 index 00000000..8946b261 --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRoleClaim", + typeof(IdentityRoleClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoleClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityRoleEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityRoleEntityType.cs new file mode 100644 index 00000000..2f1fec2b --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityRoleEntityType.cs @@ -0,0 +1,78 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRole", + typeof(IdentityRole), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedName = runtimeEntityType.AddProperty( + "NormalizedName", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("NormalizedName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedName }, + unique: true); + index.AddAnnotation("Relational:Name", "RoleNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs new file mode 100644 index 00000000..55418a1e --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserClaim", + typeof(IdentityUserClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityUserClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs new file mode 100644 index 00000000..3ca029bd --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserLoginstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserLogin", + typeof(IdentityUserLogin), + baseEntityType); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerKey = runtimeEntityType.AddProperty( + "ProviderKey", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderKey", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerDisplayName = runtimeEntityType.AddProperty( + "ProviderDisplayName", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderDisplayName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { loginProvider, providerKey }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserLogins"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs new file mode 100644 index 00000000..70078d7a --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs @@ -0,0 +1,82 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserRolestringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserRole", + typeof(IdentityUserRole), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { userId, roleId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs new file mode 100644 index 00000000..93ba6d31 --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs @@ -0,0 +1,84 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserTokenstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserToken", + typeof(IdentityUserToken), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var value = runtimeEntityType.AddProperty( + "Value", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Value", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { userId, loginProvider, name }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserTokens"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/KeyEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/KeyEntityType.cs new file mode 100644 index 00000000..f6c6b4c7 --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/KeyEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class KeyEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.Key", + typeof(Key), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var algorithm = runtimeEntityType.AddProperty( + "Algorithm", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Algorithm", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var created = runtimeEntityType.AddProperty( + "Created", + typeof(DateTime), + propertyInfo: typeof(Key).GetProperty("Created", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var dataProtected = runtimeEntityType.AddProperty( + "DataProtected", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("DataProtected", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var isX509Certificate = runtimeEntityType.AddProperty( + "IsX509Certificate", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("IsX509Certificate", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var use = runtimeEntityType.AddProperty( + "Use", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Use", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var version = runtimeEntityType.AddProperty( + "Version", + typeof(int), + propertyInfo: typeof(Key).GetProperty("Version", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { use }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Keys"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/LatLongEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/LatLongEntityType.cs new file mode 100644 index 00000000..3fd254bd --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/LatLongEntityType.cs @@ -0,0 +1,80 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class LatLongEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.LatLong", + typeof(LatLong), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var latitude = runtimeEntityType.AddProperty( + "Latitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Latitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var longitude = runtimeEntityType.AddProperty( + "Longitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Longitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + unique: true, + required: true, + ownership: true); + + var deliveryLocation = principalEntityType.AddNavigation("DeliveryLocation", + runtimeForeignKey, + onDependent: false, + typeof(LatLong), + propertyInfo: typeof(Order).GetProperty("DeliveryLocation", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + eagerLoaded: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs new file mode 100644 index 00000000..db236e4c --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs @@ -0,0 +1,77 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class NotificationSubscriptionEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.NotificationSubscription", + typeof(NotificationSubscription), + baseEntityType); + + var notificationSubscriptionId = runtimeEntityType.AddProperty( + "NotificationSubscriptionId", + typeof(int), + propertyInfo: typeof(NotificationSubscription).GetProperty("NotificationSubscriptionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var auth = runtimeEntityType.AddProperty( + "Auth", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Auth", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var p256dh = runtimeEntityType.AddProperty( + "P256dh", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("P256dh", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var url = runtimeEntityType.AddProperty( + "Url", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Url", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { notificationSubscriptionId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "NotificationSubscriptions"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/OrderEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/OrderEntityType.cs new file mode 100644 index 00000000..9d9ec6fd --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/OrderEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class OrderEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Order", + typeof(Order), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Order).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var createdTime = runtimeEntityType.AddProperty( + "CreatedTime", + typeof(DateTime), + propertyInfo: typeof(Order).GetProperty("CreatedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var deliveryAddressId = runtimeEntityType.AddProperty( + "DeliveryAddressId", + typeof(int?), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(Order).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deliveryAddressId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("DeliveryAddressId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType); + + var deliveryAddress = declaringEntityType.AddNavigation("DeliveryAddress", + runtimeForeignKey, + onDependent: true, + typeof(Address), + propertyInfo: typeof(Order).GetProperty("DeliveryAddress", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PersistedGrantEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PersistedGrantEntityType.cs new file mode 100644 index 00000000..842d53a5 --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PersistedGrantEntityType.cs @@ -0,0 +1,127 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PersistedGrantEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.PersistedGrant", + typeof(PersistedGrant), + baseEntityType); + + var key = runtimeEntityType.AddProperty( + "Key", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Key", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var consumedTime = runtimeEntityType.AddProperty( + "ConsumedTime", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("ConsumedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(PersistedGrant).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var type = runtimeEntityType.AddProperty( + "Type", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Type", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var key0 = runtimeEntityType.AddKey( + new[] { key }); + runtimeEntityType.SetPrimaryKey(key0); + + var index = runtimeEntityType.AddIndex( + new[] { consumedTime }); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + var index1 = runtimeEntityType.AddIndex( + new[] { subjectId, clientId, type }); + + var index2 = runtimeEntityType.AddIndex( + new[] { subjectId, sessionId, type }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PersistedGrants"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaEntityType.cs new file mode 100644 index 00000000..3a124e63 --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaEntityType.cs @@ -0,0 +1,111 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Pizza", + typeof(Pizza), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var size = runtimeEntityType.AddProperty( + "Size", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Size", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var specialId = runtimeEntityType.AddProperty( + "SpecialId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("SpecialId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { orderId }); + + var index0 = runtimeEntityType.AddIndex( + new[] { specialId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var pizzas = principalEntityType.AddNavigation("Pizzas", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Order).GetProperty("Pizzas", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("SpecialId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var special = declaringEntityType.AddNavigation("Special", + runtimeForeignKey, + onDependent: true, + typeof(PizzaSpecial), + propertyInfo: typeof(Pizza).GetProperty("Special", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Pizzas"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs new file mode 100644 index 00000000..e86b0f50 --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs @@ -0,0 +1,76 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaSpecialEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaSpecial", + typeof(PizzaSpecial), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(PizzaSpecial).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var basePrice = runtimeEntityType.AddProperty( + "BasePrice", + typeof(decimal), + propertyInfo: typeof(PizzaSpecial).GetProperty("BasePrice", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var imageUrl = runtimeEntityType.AddProperty( + "ImageUrl", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("ImageUrl", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Specials"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaStoreContextModel.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaStoreContextModel.cs new file mode 100644 index 00000000..8b516a68 --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaStoreContextModel.cs @@ -0,0 +1,28 @@ +// +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + [DbContext(typeof(PizzaStoreContext))] + public partial class PizzaStoreContextModel : RuntimeModel + { + static PizzaStoreContextModel() + { + var model = new PizzaStoreContextModel(); + model.Initialize(); + model.Customize(); + _instance = model; + } + + private static PizzaStoreContextModel _instance; + public static IModel Instance => _instance; + + partial void Initialize(); + + partial void Customize(); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs new file mode 100644 index 00000000..d46f50f4 --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs @@ -0,0 +1,69 @@ +// +using System; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + public partial class PizzaStoreContextModel + { + partial void Initialize() + { + var address = AddressEntityType.Create(this); + var latLong = LatLongEntityType.Create(this); + var notificationSubscription = NotificationSubscriptionEntityType.Create(this); + var order = OrderEntityType.Create(this); + var pizza = PizzaEntityType.Create(this); + var pizzaSpecial = PizzaSpecialEntityType.Create(this); + var pizzaTopping = PizzaToppingEntityType.Create(this); + var pizzaStoreUser = PizzaStoreUserEntityType.Create(this); + var topping = ToppingEntityType.Create(this); + var deviceFlowCodes = DeviceFlowCodesEntityType.Create(this); + var key = KeyEntityType.Create(this); + var persistedGrant = PersistedGrantEntityType.Create(this); + var identityRole = IdentityRoleEntityType.Create(this); + var identityRoleClaimstring = IdentityRoleClaimstringEntityType.Create(this); + var identityUserClaimstring = IdentityUserClaimstringEntityType.Create(this); + var identityUserLoginstring = IdentityUserLoginstringEntityType.Create(this); + var identityUserRolestring = IdentityUserRolestringEntityType.Create(this); + var identityUserTokenstring = IdentityUserTokenstringEntityType.Create(this); + + LatLongEntityType.CreateForeignKey1(latLong, order); + OrderEntityType.CreateForeignKey1(order, address); + PizzaEntityType.CreateForeignKey1(pizza, order); + PizzaEntityType.CreateForeignKey2(pizza, pizzaSpecial); + PizzaToppingEntityType.CreateForeignKey1(pizzaTopping, pizza); + PizzaToppingEntityType.CreateForeignKey2(pizzaTopping, topping); + IdentityRoleClaimstringEntityType.CreateForeignKey1(identityRoleClaimstring, identityRole); + IdentityUserClaimstringEntityType.CreateForeignKey1(identityUserClaimstring, pizzaStoreUser); + IdentityUserLoginstringEntityType.CreateForeignKey1(identityUserLoginstring, pizzaStoreUser); + IdentityUserRolestringEntityType.CreateForeignKey1(identityUserRolestring, identityRole); + IdentityUserRolestringEntityType.CreateForeignKey2(identityUserRolestring, pizzaStoreUser); + IdentityUserTokenstringEntityType.CreateForeignKey1(identityUserTokenstring, pizzaStoreUser); + + AddressEntityType.CreateAnnotations(address); + LatLongEntityType.CreateAnnotations(latLong); + NotificationSubscriptionEntityType.CreateAnnotations(notificationSubscription); + OrderEntityType.CreateAnnotations(order); + PizzaEntityType.CreateAnnotations(pizza); + PizzaSpecialEntityType.CreateAnnotations(pizzaSpecial); + PizzaToppingEntityType.CreateAnnotations(pizzaTopping); + PizzaStoreUserEntityType.CreateAnnotations(pizzaStoreUser); + ToppingEntityType.CreateAnnotations(topping); + DeviceFlowCodesEntityType.CreateAnnotations(deviceFlowCodes); + KeyEntityType.CreateAnnotations(key); + PersistedGrantEntityType.CreateAnnotations(persistedGrant); + IdentityRoleEntityType.CreateAnnotations(identityRole); + IdentityRoleClaimstringEntityType.CreateAnnotations(identityRoleClaimstring); + IdentityUserClaimstringEntityType.CreateAnnotations(identityUserClaimstring); + IdentityUserLoginstringEntityType.CreateAnnotations(identityUserLoginstring); + IdentityUserRolestringEntityType.CreateAnnotations(identityUserRolestring); + IdentityUserTokenstringEntityType.CreateAnnotations(identityUserTokenstring); + + AddAnnotation("ProductVersion", "6.0.0"); + } + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs new file mode 100644 index 00000000..18b2d96d --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs @@ -0,0 +1,156 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaStoreUserEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Server.PizzaStoreUser", + typeof(PizzaStoreUser), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var accessFailedCount = runtimeEntityType.AddProperty( + "AccessFailedCount", + typeof(int), + propertyInfo: typeof(IdentityUser).GetProperty("AccessFailedCount", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var email = runtimeEntityType.AddProperty( + "Email", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Email", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var emailConfirmed = runtimeEntityType.AddProperty( + "EmailConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("EmailConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnabled = runtimeEntityType.AddProperty( + "LockoutEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnd = runtimeEntityType.AddProperty( + "LockoutEnd", + typeof(DateTimeOffset?), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnd", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var normalizedEmail = runtimeEntityType.AddProperty( + "NormalizedEmail", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedEmail", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedUserName = runtimeEntityType.AddProperty( + "NormalizedUserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedUserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var passwordHash = runtimeEntityType.AddProperty( + "PasswordHash", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PasswordHash", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumber = runtimeEntityType.AddProperty( + "PhoneNumber", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumber", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumberConfirmed = runtimeEntityType.AddProperty( + "PhoneNumberConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumberConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var securityStamp = runtimeEntityType.AddProperty( + "SecurityStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("SecurityStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var twoFactorEnabled = runtimeEntityType.AddProperty( + "TwoFactorEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("TwoFactorEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var userName = runtimeEntityType.AddProperty( + "UserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("UserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedEmail }); + index.AddAnnotation("Relational:Name", "EmailIndex"); + + var index0 = runtimeEntityType.AddIndex( + new[] { normalizedUserName }, + unique: true); + index0.AddAnnotation("Relational:Name", "UserNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUsers"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaToppingEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaToppingEntityType.cs new file mode 100644 index 00000000..b97d2a24 --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaToppingEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaTopping", + typeof(PizzaTopping), + baseEntityType); + + var pizzaId = runtimeEntityType.AddProperty( + "PizzaId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("PizzaId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var toppingId = runtimeEntityType.AddProperty( + "ToppingId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("ToppingId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { pizzaId, toppingId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { toppingId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("PizzaId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var toppings = principalEntityType.AddNavigation("Toppings", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Pizza).GetProperty("Toppings", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("ToppingId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var topping = declaringEntityType.AddNavigation("Topping", + runtimeForeignKey, + onDependent: true, + typeof(Topping), + propertyInfo: typeof(PizzaTopping).GetProperty("Topping", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PizzaTopping"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/ToppingEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/ToppingEntityType.cs new file mode 100644 index 00000000..9295f9bf --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/ToppingEntityType.cs @@ -0,0 +1,62 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class ToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Topping", + typeof(Topping), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Topping).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Topping).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var price = runtimeEntityType.AddProperty( + "Price", + typeof(decimal), + propertyInfo: typeof(Topping).GetProperty("Price", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Toppings"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/OidcConfigurationController.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/OidcConfigurationController.cs index c074debf..dc75ecb3 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Server/OidcConfigurationController.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/OidcConfigurationController.cs @@ -1,26 +1,21 @@ using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class OidcConfigurationController : Controller { - public class OidcConfigurationController : Controller - { - public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) - { - ClientRequestParametersProvider = clientRequestParametersProvider; - } + public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) + { + ClientRequestParametersProvider = clientRequestParametersProvider; + } - public IClientRequestParametersProvider ClientRequestParametersProvider { get; } + public IClientRequestParametersProvider ClientRequestParametersProvider { get; } - [HttpGet("_configuration/{clientId}")] - public IActionResult GetClientRequestParameters([FromRoute]string clientId) - { - var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); - return Ok(parameters); - } - } + [HttpGet("_configuration/{clientId}")] + public IActionResult GetClientRequestParameters([FromRoute] string clientId) + { + var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); + return Ok(parameters); + } } diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/OrdersController.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/OrdersController.cs index bab775e4..1859decd 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Server/OrdersController.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/OrdersController.cs @@ -1,135 +1,130 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; +using System.Security.Claims; using System.Text.Json; -using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using WebPush; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +[Route("orders")] +[ApiController] +[Authorize] +public class OrdersController : Controller { - [Route("orders")] - [ApiController] - [Authorize] - public class OrdersController : Controller - { - private readonly PizzaStoreContext _db; - - public OrdersController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetOrders() - { - var orders = await _db.Orders - .Where(o => o.UserId == GetUserId()) - .Include(o => o.DeliveryLocation) - .Include(o => o.Pizzas).ThenInclude(p => p.Special) - .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) - .OrderByDescending(o => o.CreatedTime) - .ToListAsync(); - - return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); - } - - [HttpGet("{orderId}")] - public async Task> GetOrderWithStatus(int orderId) - { - var order = await _db.Orders - .Where(o => o.OrderId == orderId) - .Where(o => o.UserId == GetUserId()) - .Include(o => o.DeliveryLocation) - .Include(o => o.Pizzas).ThenInclude(p => p.Special) - .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) - .SingleOrDefaultAsync(); - - if (order == null) - { - return NotFound(); - } - - return OrderWithStatus.FromOrder(order); - } - - [HttpPost] - public async Task> PlaceOrder(Order order) - { - order.CreatedTime = DateTime.Now; - order.DeliveryLocation = new LatLong(51.5001, -0.1239); - order.UserId = GetUserId(); - - // Enforce existence of Pizza.SpecialId and Topping.ToppingId - // in the database - prevent the submitter from making up - // new specials and toppings - foreach (var pizza in order.Pizzas) - { - pizza.SpecialId = pizza.Special.Id; - pizza.Special = null; - - foreach (var topping in pizza.Toppings) - { - topping.ToppingId = topping.Topping.Id; - topping.Topping = null; - } - } - - _db.Orders.Attach(order); - await _db.SaveChangesAsync(); - - // In the background, send push notifications if possible - var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); - if (subscription != null) - { - _ = TrackAndSendNotificationsAsync(order, subscription); - } - - return order.OrderId; - } - - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } - - private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription subscription) - { - // In a realistic case, some other backend process would track - // order delivery progress and send us notifications when it - // changes. Since we don't have any such process here, fake it. - await Task.Delay(OrderWithStatus.PreparationDuration); - await SendNotificationAsync(order, subscription, "Your order has been dispatched!"); - - await Task.Delay(OrderWithStatus.DeliveryDuration); - await SendNotificationAsync(order, subscription, "Your order is now delivered. Enjoy!"); - } - - private static async Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) - { - // For a real application, generate your own - var publicKey = "BLC8GOevpcpjQiLkO7JmVClQjycvTCYWm6Cq_a7wJZlstGTVZvwGFFHMYfXt6Njyvgx_GlXJeo5cSiZ1y4JOx1o"; - var privateKey = "OrubzSz3yWACscZXjFQrrtDwCKg-TGFuWhluQ2wLXDo"; - - var pushSubscription = new PushSubscription(subscription.Url, subscription.P256dh, subscription.Auth); - var vapidDetails = new VapidDetails("mailto:", publicKey, privateKey); - var webPushClient = new WebPushClient(); - try - { - var payload = JsonSerializer.Serialize(new - { - message, - url = $"myorders/{order.OrderId}", - }); - await webPushClient.SendNotificationAsync(pushSubscription, payload, vapidDetails); - } - catch (Exception ex) - { - Console.Error.WriteLine("Error sending push notification: " + ex.Message); - } - } - } + private readonly PizzaStoreContext _db; + + public OrdersController(PizzaStoreContext db) + { + _db = db; + } + + [HttpGet] + public async Task>> GetOrders() + { + var orders = await _db.Orders + .Where(o => o.UserId == GetUserId()) + .Include(o => o.DeliveryLocation) + .Include(o => o.Pizzas).ThenInclude(p => p.Special) + .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) + .OrderByDescending(o => o.CreatedTime) + .ToListAsync(); + + return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); + } + + [HttpGet("{orderId}")] + public async Task> GetOrderWithStatus(int orderId) + { + var order = await _db.Orders + .Where(o => o.OrderId == orderId) + .Where(o => o.UserId == GetUserId()) + .Include(o => o.DeliveryLocation) + .Include(o => o.Pizzas).ThenInclude(p => p.Special) + .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) + .SingleOrDefaultAsync(); + + if (order == null) + { + return NotFound(); + } + + return OrderWithStatus.FromOrder(order); + } + + [HttpPost] + public async Task> PlaceOrder(Order order) + { + order.CreatedTime = DateTime.Now; + order.DeliveryLocation = new LatLong(51.5001, -0.1239); + order.UserId = GetUserId(); + + // Enforce existence of Pizza.SpecialId and Topping.ToppingId + // in the database - prevent the submitter from making up + // new specials and toppings + foreach (var pizza in order.Pizzas) + { + pizza.SpecialId = pizza.Special.Id; + pizza.Special = null; + + foreach (var topping in pizza.Toppings) + { + topping.ToppingId = topping.Topping.Id; + topping.Topping = null; + } + } + + _db.Orders.Attach(order); + await _db.SaveChangesAsync(); + + // In the background, send push notifications if possible + var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); + if (subscription != null) + { + _ = TrackAndSendNotificationsAsync(order, subscription); + } + + return order.OrderId; + } + + private string GetUserId() + { + return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); + } + + private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription subscription) + { + // In a realistic case, some other backend process would track + // order delivery progress and send us notifications when it + // changes. Since we don't have any such process here, fake it. + await Task.Delay(OrderWithStatus.PreparationDuration); + await SendNotificationAsync(order, subscription, "Your order has been dispatched!"); + + await Task.Delay(OrderWithStatus.DeliveryDuration); + await SendNotificationAsync(order, subscription, "Your order is now delivered. Enjoy!"); + } + + private static async Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) + { + // For a real application, generate your own + var publicKey = "BLC8GOevpcpjQiLkO7JmVClQjycvTCYWm6Cq_a7wJZlstGTVZvwGFFHMYfXt6Njyvgx_GlXJeo5cSiZ1y4JOx1o"; + var privateKey = "OrubzSz3yWACscZXjFQrrtDwCKg-TGFuWhluQ2wLXDo"; + + var pushSubscription = new PushSubscription(subscription.Url, subscription.P256dh, subscription.Auth); + var vapidDetails = new VapidDetails("mailto:", publicKey, privateKey); + var webPushClient = new WebPushClient(); + try + { + var payload = JsonSerializer.Serialize(new + { + message, + url = $"myorders/{order.OrderId}", + }); + await webPushClient.SendNotificationAsync(pushSubscription, payload, vapidDetails); + } + catch (Exception ex) + { + Console.Error.WriteLine("Error sending push notification: " + ex.Message); + } + } } diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/PizzaApiExtensions.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/PizzaApiExtensions.cs new file mode 100644 index 00000000..bf6b7bde --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/PizzaApiExtensions.cs @@ -0,0 +1,60 @@ +using System.Security.Claims; +using Microsoft.AspNetCore.Authorization; +using Microsoft.EntityFrameworkCore; + +namespace BlazingPizza.Server; + +public static class PizzaApiExtensions +{ + + public static WebApplication MapPizzaApi(this WebApplication app) + { + + // Subscribe to notifications + app.MapPut("/notifications/subscribe", [Authorize] async ( + HttpContext context, + PizzaStoreContext db, + NotificationSubscription subscription) => + { + + // We're storing at most one subscription per user, so delete old ones. + // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. + var userId = GetUserId(context); + var oldSubscriptions = db.NotificationSubscriptions.Where(e => e.UserId == userId); + db.NotificationSubscriptions.RemoveRange(oldSubscriptions); + + // Store new subscription + subscription.UserId = userId; + db.NotificationSubscriptions.Attach(subscription); + + await db.SaveChangesAsync(); + return Results.Ok(subscription); + + }); + + // Specials + app.MapGet("/specials", async (PizzaStoreContext db) => + { + + var specials = await db.Specials.ToListAsync(); + return Results.Ok(specials); + + }); + + // Toppings + app.MapGet("/toppings", async (PizzaStoreContext db) => + { + var toppings = await db.Toppings.OrderBy(t => t.Name).ToListAsync(); + return Results.Ok(toppings); + }); + + return app; + + } + + private static string GetUserId(HttpContext context) + { + return context.User.FindFirstValue(ClaimTypes.NameIdentifier); + } + +} \ No newline at end of file diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/PizzaStoreContext.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/PizzaStoreContext.cs index 9485bd12..992baa19 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Server/PizzaStoreContext.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/PizzaStoreContext.cs @@ -1,39 +1,38 @@ -using Duende.IdentityServer.EntityFramework.Options; +using Duende.IdentityServer.EntityFramework.Options; using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class PizzaStoreContext : ApiAuthorizationDbContext { - public class PizzaStoreContext : ApiAuthorizationDbContext - { - public PizzaStoreContext( - DbContextOptions options, - IOptions operationalStoreOptions) : base(options, operationalStoreOptions) - { - } + public PizzaStoreContext( + DbContextOptions options, + IOptions operationalStoreOptions) : base(options, operationalStoreOptions) + { + } - public DbSet Orders { get; set; } + public DbSet Orders { get; set; } - public DbSet Pizzas { get; set; } + public DbSet Pizzas { get; set; } - public DbSet Specials { get; set; } + public DbSet Specials { get; set; } - public DbSet Toppings { get; set; } + public DbSet Toppings { get; set; } - public DbSet NotificationSubscriptions { get; set; } + public DbSet NotificationSubscriptions { get; set; } - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - base.OnModelCreating(modelBuilder); + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); - // Configuring a many-to-many special -> topping relationship that is friendly for serialization - modelBuilder.Entity().HasKey(pst => new { pst.PizzaId, pst.ToppingId }); - modelBuilder.Entity().HasOne().WithMany(ps => ps.Toppings); - modelBuilder.Entity().HasOne(pst => pst.Topping).WithMany(); + // Configuring a many-to-many special -> topping relationship that is friendly for serialization + modelBuilder.Entity().HasKey(pst => new { pst.PizzaId, pst.ToppingId }); + modelBuilder.Entity().HasOne().WithMany(ps => ps.Toppings); + modelBuilder.Entity().HasOne(pst => pst.Topping).WithMany(); - // Inline the Lat-Long pairs in Order rather than having a FK to another table - modelBuilder.Entity().OwnsOne(o => o.DeliveryLocation); - } - } -} \ No newline at end of file + // Inline the Lat-Long pairs in Order rather than having a FK to another table + modelBuilder.Entity().OwnsOne(o => o.DeliveryLocation); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/PizzaStoreUser.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/PizzaStoreUser.cs index 171ce83d..7ab40235 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Server/PizzaStoreUser.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/PizzaStoreUser.cs @@ -1,8 +1,5 @@ using Microsoft.AspNetCore.Identity; -namespace BlazingPizza.Server -{ - public class PizzaStoreUser : IdentityUser - { - } -} \ No newline at end of file +namespace BlazingPizza.Server; + +public class PizzaStoreUser : IdentityUser { } \ No newline at end of file diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/PizzasController.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/PizzasController.cs deleted file mode 100644 index c082552c..00000000 --- a/save-points/09-progressive-web-app/BlazingPizza.Server/PizzasController.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("pizzas")] - [ApiController] - public class PizzasController : Controller - { - private readonly PizzaStoreContext _db; - - public PizzasController(PizzaStoreContext db) - { - _db = db; - } - } -} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Program.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Program.cs index 40a47641..4484d8f7 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Server/Program.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Program.cs @@ -1,33 +1,67 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; +using Microsoft.AspNetCore.Authentication; +using Microsoft.EntityFrameworkCore; +using BlazingPizza.Server; -namespace BlazingPizza.Server +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddControllersWithViews() + .AddJsonOptions(options => { + options.JsonSerializerOptions.AddContext(); + }); +builder.Services.AddRazorPages(); + +builder.Services.AddDbContext(options => + options.UseSqlite("Data Source=pizza.db") + .UseModel(BlazingPizza.Server.Models.PizzaStoreContextModel.Instance)); + +builder.Services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) + .AddEntityFrameworkStores(); + +builder.Services.AddIdentityServer() + .AddApiAuthorization(); + +builder.Services.AddAuthentication() + .AddIdentityServerJwt(); + +var app = builder.Build(); + +// Initialize the database +var scopeFactory = app.Services.GetRequiredService(); +using (var scope = scopeFactory.CreateScope()) +{ + var db = scope.ServiceProvider.GetRequiredService(); + if (db.Database.EnsureCreated()) + { + SeedData.Initialize(db); + } +} + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseWebAssemblyDebugging(); +} +else { - public class Program - { - public static void Main(string[] args) - { - var host = CreateHostBuilder(args).Build(); - - // Initialize the database - var scopeFactory = host.Services.GetRequiredService(); - using (var scope = scopeFactory.CreateScope()) - { - var db = scope.ServiceProvider.GetRequiredService(); - if (db.Database.EnsureCreated()) - { - SeedData.Initialize(db); - } - } - - host.Run(); - } - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); - } + app.UseExceptionHandler("/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); } + +app.UseHttpsRedirection(); +app.UseBlazorFrameworkFiles(); +app.UseStaticFiles(); + +app.UseRouting(); + +app.UseAuthentication(); +app.UseIdentityServer(); +app.UseAuthorization(); + +app.MapPizzaApi(); + +app.MapRazorPages(); +app.MapControllers(); +app.MapFallbackToFile("index.html"); + +app.Run(); \ No newline at end of file diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/SeedData.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/SeedData.cs index 7c86a5b2..a1e47973 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Server/SeedData.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/SeedData.cs @@ -1,193 +1,192 @@ -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public static class SeedData { - public static class SeedData - { - public static void Initialize(PizzaStoreContext db) - { - var toppings = new Topping[] - { - new Topping() - { - Name = "Extra cheese", - Price = 2.50m, - }, - new Topping() - { - Name = "American bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "British bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "Canadian bacon", - Price = 2.99m, - }, - new Topping() - { - Name = "Tea and crumpets", - Price = 5.00m - }, - new Topping() - { - Name = "Fresh-baked scones", - Price = 4.50m, - }, - new Topping() - { - Name = "Bell peppers", - Price = 1.00m, - }, - new Topping() - { - Name = "Onions", - Price = 1.00m, - }, - new Topping() - { - Name = "Mushrooms", - Price = 1.00m, - }, - new Topping() - { - Name = "Pepperoni", - Price = 1.00m, - }, - new Topping() - { - Name = "Duck sausage", - Price = 3.20m, - }, - new Topping() - { - Name = "Venison meatballs", - Price = 2.50m, - }, - new Topping() - { - Name = "Served on a silver platter", - Price = 250.99m, - }, - new Topping() - { - Name = "Lobster on top", - Price = 64.50m, - }, - new Topping() - { - Name = "Sturgeon caviar", - Price = 101.75m, - }, - new Topping() - { - Name = "Artichoke hearts", - Price = 3.40m, - }, - new Topping() - { - Name = "Fresh tomatoes", - Price = 1.50m, - }, - new Topping() - { - Name = "Basil", - Price = 1.50m, - }, - new Topping() - { - Name = "Steak (medium-rare)", - Price = 8.50m, - }, - new Topping() - { - Name = "Blazing hot peppers", - Price = 4.20m, - }, - new Topping() - { - Name = "Buffalo chicken", - Price = 5.00m, - }, - new Topping() - { - Name = "Blue cheese", - Price = 2.50m, - }, - }; + public static void Initialize(PizzaStoreContext db) + { + var toppings = new Topping[] + { + new Topping() + { + Name = "Extra cheese", + Price = 2.50m, + }, + new Topping() + { + Name = "American bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "British bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "Canadian bacon", + Price = 2.99m, + }, + new Topping() + { + Name = "Tea and crumpets", + Price = 5.00m + }, + new Topping() + { + Name = "Fresh-baked scones", + Price = 4.50m, + }, + new Topping() + { + Name = "Bell peppers", + Price = 1.00m, + }, + new Topping() + { + Name = "Onions", + Price = 1.00m, + }, + new Topping() + { + Name = "Mushrooms", + Price = 1.00m, + }, + new Topping() + { + Name = "Pepperoni", + Price = 1.00m, + }, + new Topping() + { + Name = "Duck sausage", + Price = 3.20m, + }, + new Topping() + { + Name = "Venison meatballs", + Price = 2.50m, + }, + new Topping() + { + Name = "Served on a silver platter", + Price = 250.99m, + }, + new Topping() + { + Name = "Lobster on top", + Price = 64.50m, + }, + new Topping() + { + Name = "Sturgeon caviar", + Price = 101.75m, + }, + new Topping() + { + Name = "Artichoke hearts", + Price = 3.40m, + }, + new Topping() + { + Name = "Fresh tomatoes", + Price = 1.50m, + }, + new Topping() + { + Name = "Basil", + Price = 1.50m, + }, + new Topping() + { + Name = "Steak (medium-rare)", + Price = 8.50m, + }, + new Topping() + { + Name = "Blazing hot peppers", + Price = 4.20m, + }, + new Topping() + { + Name = "Buffalo chicken", + Price = 5.00m, + }, + new Topping() + { + Name = "Blue cheese", + Price = 2.50m, + }, + }; - var specials = new PizzaSpecial[] - { - new PizzaSpecial() - { - Name = "Basic Cheese Pizza", - Description = "It's cheesy and delicious. Why wouldn't you want one?", - BasePrice = 9.99m, - ImageUrl = "img/pizzas/cheese.jpg", - }, - new PizzaSpecial() - { - Id = 2, - Name = "The Baconatorizor", - Description = "It has EVERY kind of bacon", - BasePrice = 11.99m, - ImageUrl = "img/pizzas/bacon.jpg", - }, - new PizzaSpecial() - { - Id = 3, - Name = "Classic pepperoni", - Description = "It's the pizza you grew up with, but Blazing hot!", - BasePrice = 10.50m, - ImageUrl = "img/pizzas/pepperoni.jpg", - }, - new PizzaSpecial() - { - Id = 4, - Name = "Buffalo chicken", - Description = "Spicy chicken, hot sauce and bleu cheese, guaranteed to warm you up", - BasePrice = 12.75m, - ImageUrl = "img/pizzas/meaty.jpg", - }, - new PizzaSpecial() - { - Id = 5, - Name = "Mushroom Lovers", - Description = "It has mushrooms. Isn't that obvious?", - BasePrice = 11.00m, - ImageUrl = "img/pizzas/mushroom.jpg", - }, - new PizzaSpecial() - { - Id = 6, - Name = "The Brit", - Description = "When in London...", - BasePrice = 10.25m, - ImageUrl = "img/pizzas/brit.jpg", - }, - new PizzaSpecial() - { - Id = 7, - Name = "Veggie Delight", - Description = "It's like salad, but on a pizza", - BasePrice = 11.50m, - ImageUrl = "img/pizzas/salad.jpg", - }, - new PizzaSpecial() - { - Id = 8, - Name = "Margherita", - Description = "Traditional Italian pizza with tomatoes and basil", - BasePrice = 9.99m, - ImageUrl = "img/pizzas/margherita.jpg", - }, - }; + var specials = new PizzaSpecial[] + { + new PizzaSpecial() + { + Name = "Basic Cheese Pizza", + Description = "It's cheesy and delicious. Why wouldn't you want one?", + BasePrice = 9.99m, + ImageUrl = "img/pizzas/cheese.jpg", + }, + new PizzaSpecial() + { + Id = 2, + Name = "The Baconatorizor", + Description = "It has EVERY kind of bacon", + BasePrice = 11.99m, + ImageUrl = "img/pizzas/bacon.jpg", + }, + new PizzaSpecial() + { + Id = 3, + Name = "Classic pepperoni", + Description = "It's the pizza you grew up with, but Blazing hot!", + BasePrice = 10.50m, + ImageUrl = "img/pizzas/pepperoni.jpg", + }, + new PizzaSpecial() + { + Id = 4, + Name = "Buffalo chicken", + Description = "Spicy chicken, hot sauce and bleu cheese, guaranteed to warm you up", + BasePrice = 12.75m, + ImageUrl = "img/pizzas/meaty.jpg", + }, + new PizzaSpecial() + { + Id = 5, + Name = "Mushroom Lovers", + Description = "It has mushrooms. Isn't that obvious?", + BasePrice = 11.00m, + ImageUrl = "img/pizzas/mushroom.jpg", + }, + new PizzaSpecial() + { + Id = 6, + Name = "The Brit", + Description = "When in London...", + BasePrice = 10.25m, + ImageUrl = "img/pizzas/brit.jpg", + }, + new PizzaSpecial() + { + Id = 7, + Name = "Veggie Delight", + Description = "It's like salad, but on a pizza", + BasePrice = 11.50m, + ImageUrl = "img/pizzas/salad.jpg", + }, + new PizzaSpecial() + { + Id = 8, + Name = "Margherita", + Description = "Traditional Italian pizza with tomatoes and basil", + BasePrice = 9.99m, + ImageUrl = "img/pizzas/margherita.jpg", + }, + }; - db.Toppings.AddRange(toppings); - db.Specials.AddRange(specials); - db.SaveChanges(); - } - } -} + db.Toppings.AddRange(toppings); + db.Specials.AddRange(specials); + db.SaveChanges(); + } +} \ No newline at end of file diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/SpecialsController.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/SpecialsController.cs deleted file mode 100644 index a176844c..00000000 --- a/save-points/09-progressive-web-app/BlazingPizza.Server/SpecialsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("specials")] - [ApiController] - public class SpecialsController : Controller - { - private readonly PizzaStoreContext _db; - - public SpecialsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetSpecials() - { - return (await _db.Specials.ToListAsync()).OrderByDescending(s => s.BasePrice).ToList(); - } - } -} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Startup.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Startup.cs deleted file mode 100644 index 3d59708b..00000000 --- a/save-points/09-progressive-web-app/BlazingPizza.Server/Startup.cs +++ /dev/null @@ -1,70 +0,0 @@ -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace BlazingPizza.Server -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - public void ConfigureServices(IServiceCollection services) - { - services.AddControllersWithViews(); - services.AddRazorPages(); - - services.AddDbContext(options => - options.UseSqlite("Data Source=pizza.db")); - - services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) - .AddEntityFrameworkStores(); - - services.AddIdentityServer() - .AddApiAuthorization(); - - services.AddAuthentication() - .AddIdentityServerJwt(); - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - app.UseWebAssemblyDebugging(); - } - else - { - app.UseExceptionHandler("/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); - } - - app.UseHttpsRedirection(); - app.UseBlazorFrameworkFiles(); - app.UseStaticFiles(); - - app.UseRouting(); - - app.UseAuthentication(); - app.UseIdentityServer(); - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - endpoints.MapRazorPages(); - endpoints.MapFallbackToFile("index.html"); - }); - } - } -} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/ToppingsController.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/ToppingsController.cs deleted file mode 100644 index 6a677639..00000000 --- a/save-points/09-progressive-web-app/BlazingPizza.Server/ToppingsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("toppings")] - [ApiController] - public class ToppingsController : Controller - { - private readonly PizzaStoreContext _db; - - public ToppingsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetToppings() - { - return await _db.Toppings.OrderBy(t => t.Name).ToListAsync(); - } - } -} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Shared/Address.cs b/save-points/09-progressive-web-app/BlazingPizza.Shared/Address.cs index d76bc52a..79be9c5b 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Shared/Address.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Shared/Address.cs @@ -1,27 +1,24 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class Address { - public class Address - { - public int Id { get; set; } + public int Id { get; set; } - [Required, MaxLength(100)] - public string Name { get; set; } + [Required, MaxLength(100)] + public string Name { get; set; } - [Required, MaxLength(100)] - public string Line1 { get; set; } + [Required, MaxLength(100)] + public string Line1 { get; set; } - [MaxLength(100)] - public string Line2 { get; set; } + [MaxLength(100)] + public string Line2 { get; set; } - [Required, MaxLength(50)] - public string City { get; set; } + [Required, MaxLength(50)] + public string City { get; set; } - [Required, MaxLength(20)] - public string Region { get; set; } + [Required, MaxLength(20)] + public string Region { get; set; } - [Required, MaxLength(20)] - public string PostalCode { get; set; } - } + [Required, MaxLength(20)] + public string PostalCode { get; set; } } diff --git a/save-points/09-progressive-web-app/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/save-points/09-progressive-web-app/BlazingPizza.Shared/BlazingPizza.Shared.csproj index f7b7dd02..fb17e53b 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/save-points/09-progressive-web-app/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -3,8 +3,13 @@ $(TargetFrameworkVersion) BlazingPizza + true + + + + diff --git a/save-points/09-progressive-web-app/BlazingPizza.Shared/LatLong.cs b/save-points/09-progressive-web-app/BlazingPizza.Shared/LatLong.cs index 9b8c3811..14a94c26 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Shared/LatLong.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Shared/LatLong.cs @@ -1,27 +1,26 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class LatLong { - public class LatLong - { - public LatLong() - { - } + public LatLong() + { + } - public LatLong(double latitude, double longitude) : this() - { - Latitude = latitude; - Longitude = longitude; - } + public LatLong(double latitude, double longitude) : this() + { + Latitude = latitude; + Longitude = longitude; + } - public double Latitude { get; set; } + public double Latitude { get; set; } - public double Longitude { get; set; } + public double Longitude { get; set; } - public static LatLong Interpolate(LatLong start, LatLong end, double proportion) - { - // The Earth is flat, right? So no need for spherical interpolation. - return new LatLong( - start.Latitude + (end.Latitude - start.Latitude) * proportion, - start.Longitude + (end.Longitude - start.Longitude) * proportion); - } - } -} + public static LatLong Interpolate(LatLong start, LatLong end, double proportion) + { + // The Earth is flat, right? So no need for spherical interpolation. + return new LatLong( + start.Latitude + (end.Latitude - start.Latitude) * proportion, + start.Longitude + (end.Longitude - start.Longitude) * proportion); + } +} \ No newline at end of file diff --git a/save-points/09-progressive-web-app/BlazingPizza.Shared/NotificationSubscription.cs b/save-points/09-progressive-web-app/BlazingPizza.Shared/NotificationSubscription.cs index 04259c2f..9109ff57 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Shared/NotificationSubscription.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Shared/NotificationSubscription.cs @@ -1,17 +1,14 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class NotificationSubscription { - public class NotificationSubscription - { - public int NotificationSubscriptionId { get; set; } + public int NotificationSubscriptionId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public string Url { get; set; } + public string Url { get; set; } - public string P256dh { get; set; } + public string P256dh { get; set; } - public string Auth { get; set; } - } + public string Auth { get; set; } } diff --git a/save-points/09-progressive-web-app/BlazingPizza.Shared/Order.cs b/save-points/09-progressive-web-app/BlazingPizza.Shared/Order.cs index fb003bd6..aca04ca1 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Shared/Order.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Shared/Order.cs @@ -1,25 +1,32 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +public class Order { - public class Order - { - public int OrderId { get; set; } + public int OrderId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public DateTime CreatedTime { get; set; } + public DateTime CreatedTime { get; set; } - public Address DeliveryAddress { get; set; } = new Address(); + public Address DeliveryAddress { get; set; } = new Address(); - public LatLong DeliveryLocation { get; set; } + public LatLong DeliveryLocation { get; set; } - public List Pizzas { get; set; } = new List(); + public List Pizzas { get; set; } = new List(); - public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); + public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); - public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); - } + public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Default, PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] +[JsonSerializable(typeof(Order))] +[JsonSerializable(typeof(OrderWithStatus))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Pizza))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Topping))] +public partial class OrderContext : JsonSerializerContext {} \ No newline at end of file diff --git a/save-points/09-progressive-web-app/BlazingPizza.Shared/OrderWithStatus.cs b/save-points/09-progressive-web-app/BlazingPizza.Shared/OrderWithStatus.cs index 021de78c..f5f153b6 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Shared/OrderWithStatus.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Shared/OrderWithStatus.cs @@ -1,79 +1,78 @@ -using BlazingPizza.ComponentsLibrary.Map; -using System; -using System.Collections.Generic; +using System.Text.Json.Serialization; +using BlazingPizza.ComponentsLibrary.Map; -namespace BlazingPizza + +namespace BlazingPizza; + +public class OrderWithStatus { - public class OrderWithStatus - { - public readonly static TimeSpan PreparationDuration = TimeSpan.FromSeconds(10); - public readonly static TimeSpan DeliveryDuration = TimeSpan.FromMinutes(1); // Unrealistic, but more interesting to watch + public readonly static TimeSpan PreparationDuration = TimeSpan.FromSeconds(10); + public readonly static TimeSpan DeliveryDuration = TimeSpan.FromMinutes(1); // Unrealistic, but more interesting to watch - public Order Order { get; set; } + public Order Order { get; set; } - public string StatusText { get; set; } + public string StatusText { get; set; } - public bool IsDelivered => StatusText == "Delivered"; + public bool IsDelivered => StatusText == "Delivered"; - public List MapMarkers { get; set; } + public List MapMarkers { get; set; } - public static OrderWithStatus FromOrder(Order order) - { - // To simulate a real backend process, we fake status updates based on the amount - // of time since the order was placed - string statusText; - List mapMarkers; - var dispatchTime = order.CreatedTime.Add(PreparationDuration); + public static OrderWithStatus FromOrder(Order order) + { + // To simulate a real backend process, we fake status updates based on the amount + // of time since the order was placed + string statusText; + List mapMarkers; + var dispatchTime = order.CreatedTime.Add(PreparationDuration); - if (DateTime.Now < dispatchTime) - { - statusText = "Preparing"; - mapMarkers = new List - { - ToMapMarker("You", order.DeliveryLocation, showPopup: true) - }; - } - else if (DateTime.Now < dispatchTime + DeliveryDuration) - { - statusText = "Out for delivery"; + if (DateTime.Now < dispatchTime) + { + statusText = "Preparing"; + mapMarkers = new List + { + ToMapMarker("You", order.DeliveryLocation, showPopup: true) + }; + } + else if (DateTime.Now < dispatchTime + DeliveryDuration) + { + statusText = "Out for delivery"; - var startPosition = ComputeStartPosition(order); - var proportionOfDeliveryCompleted = Math.Min(1, (DateTime.Now - dispatchTime).TotalMilliseconds / DeliveryDuration.TotalMilliseconds); - var driverPosition = LatLong.Interpolate(startPosition, order.DeliveryLocation, proportionOfDeliveryCompleted); - mapMarkers = new List - { - ToMapMarker("You", order.DeliveryLocation), - ToMapMarker("Driver", driverPosition, showPopup: true), - }; - } - else - { - statusText = "Delivered"; - mapMarkers = new List - { - ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), - }; - } + var startPosition = ComputeStartPosition(order); + var proportionOfDeliveryCompleted = Math.Min(1, (DateTime.Now - dispatchTime).TotalMilliseconds / DeliveryDuration.TotalMilliseconds); + var driverPosition = LatLong.Interpolate(startPosition, order.DeliveryLocation, proportionOfDeliveryCompleted); + mapMarkers = new List + { + ToMapMarker("You", order.DeliveryLocation), + ToMapMarker("Driver", driverPosition, showPopup: true), + }; + } + else + { + statusText = "Delivered"; + mapMarkers = new List + { + ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), + }; + } - return new OrderWithStatus - { - Order = order, - StatusText = statusText, - MapMarkers = mapMarkers, - }; - } + return new OrderWithStatus + { + Order = order, + StatusText = statusText, + MapMarkers = mapMarkers, + }; + } - private static LatLong ComputeStartPosition(Order order) - { - // Random but deterministic based on order ID - var rng = new Random(order.OrderId); - var distance = 0.01 + rng.NextDouble() * 0.02; - var angle = rng.NextDouble() * Math.PI * 2; - var offset = (distance * Math.Cos(angle), distance * Math.Sin(angle)); - return new LatLong(order.DeliveryLocation.Latitude + offset.Item1, order.DeliveryLocation.Longitude + offset.Item2); - } + private static LatLong ComputeStartPosition(Order order) + { + // Random but deterministic based on order ID + var rng = new Random(order.OrderId); + var distance = 0.01 + rng.NextDouble() * 0.02; + var angle = rng.NextDouble() * Math.PI * 2; + var offset = (distance * Math.Cos(angle), distance * Math.Sin(angle)); + return new LatLong(order.DeliveryLocation.Latitude + offset.Item1, order.DeliveryLocation.Longitude + offset.Item2); + } - static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) - => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; - } -} + static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) + => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; +} \ No newline at end of file diff --git a/save-points/09-progressive-web-app/BlazingPizza.Shared/Pizza.cs b/save-points/09-progressive-web-app/BlazingPizza.Shared/Pizza.cs index ec1108a9..459298f4 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Shared/Pizza.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Shared/Pizza.cs @@ -1,42 +1,44 @@ -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// /// Represents a customized pizza as part of an order +/// +public class Pizza { - /// - /// Represents a customized pizza as part of an order - /// - public class Pizza - { - public const int DefaultSize = 12; - public const int MinimumSize = 9; - public const int MaximumSize = 17; + public const int DefaultSize = 12; + public const int MinimumSize = 9; + public const int MaximumSize = 17; - public int Id { get; set; } + public int Id { get; set; } - public int OrderId { get; set; } + public int OrderId { get; set; } - public PizzaSpecial Special { get; set; } + public PizzaSpecial Special { get; set; } - public int SpecialId { get; set; } + public int SpecialId { get; set; } - public int Size { get; set; } + public int Size { get; set; } - public List Toppings { get; set; } + public List Toppings { get; set; } - public decimal GetBasePrice() - { - return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; - } + public decimal GetBasePrice() + { + return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; + } - public decimal GetTotalPrice() - { - return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); - } + public decimal GetTotalPrice() + { + return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); + } - public string GetFormattedTotalPrice() - { - return GetTotalPrice().ToString("0.00"); - } - } + public string GetFormattedTotalPrice() + { + return GetTotalPrice().ToString("0.00"); + } } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Serialization)] +[JsonSerializable(typeof(Pizza))] +public partial class PizzaContext : JsonSerializerContext {} \ No newline at end of file diff --git a/save-points/09-progressive-web-app/BlazingPizza.Shared/PizzaSpecial.cs b/save-points/09-progressive-web-app/BlazingPizza.Shared/PizzaSpecial.cs index 2f2b3383..9653300c 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Shared/PizzaSpecial.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Shared/PizzaSpecial.cs @@ -1,20 +1,19 @@ -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// Represents a pre-configured template for a pizza a user can order +/// +public class PizzaSpecial { - /// - /// Represents a pre-configured template for a pizza a user can order - /// - public class PizzaSpecial - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal BasePrice { get; set; } + public decimal BasePrice { get; set; } - public string Description { get; set; } + public string Description { get; set; } - public string ImageUrl { get; set; } + public string ImageUrl { get; set; } - public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); - } -} + public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); +} \ No newline at end of file diff --git a/save-points/09-progressive-web-app/BlazingPizza.Shared/PizzaTopping.cs b/save-points/09-progressive-web-app/BlazingPizza.Shared/PizzaTopping.cs index f5a6c1ac..0a711647 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Shared/PizzaTopping.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Shared/PizzaTopping.cs @@ -1,11 +1,11 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class PizzaTopping { - public class PizzaTopping - { - public Topping Topping { get; set; } + public Topping Topping { get; set; } + + public int ToppingId { get; set; } - public int ToppingId { get; set; } - - public int PizzaId { get; set; } - } -} + public int PizzaId { get; set; } + +} \ No newline at end of file diff --git a/save-points/09-progressive-web-app/BlazingPizza.Shared/Topping.cs b/save-points/09-progressive-web-app/BlazingPizza.Shared/Topping.cs index 61bdeb92..376c311a 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Shared/Topping.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Shared/Topping.cs @@ -1,13 +1,13 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class Topping { - public class Topping - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal Price { get; set; } + public decimal Price { get; set; } - public string GetFormattedPrice() => Price.ToString("0.00"); - } -} + public string GetFormattedPrice() => Price.ToString("0.00"); + +} \ No newline at end of file diff --git a/save-points/09-progressive-web-app/BlazingPizza.Shared/UserInfo.cs b/save-points/09-progressive-web-app/BlazingPizza.Shared/UserInfo.cs index 4996ef80..362f8f8e 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Shared/UserInfo.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Shared/UserInfo.cs @@ -1,9 +1,9 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class UserInfo { - public class UserInfo - { - public bool IsAuthenticated { get; set; } + public bool IsAuthenticated { get; set; } - public string Name { get; set; } - } -} + public string Name { get; set; } + +} \ No newline at end of file From 2ee7aab74ac250f87b3949d70efac3ccaab82389 Mon Sep 17 00:00:00 2001 From: "Jeffrey T. Fritz" Date: Wed, 16 Mar 2022 11:34:29 -0400 Subject: [PATCH 12/20] Added PageTitle feature --- save-points/00-get-started/BlazingPizza.Client/Program.cs | 2 ++ .../01-Components-and-layout/BlazingPizza.Client/Program.cs | 2 ++ .../02-customize-a-pizza/BlazingPizza.Client/Pages/Index.razor | 2 ++ save-points/02-customize-a-pizza/BlazingPizza.Client/Program.cs | 2 ++ .../03-show-order-status/BlazingPizza.Client/Pages/Index.razor | 2 ++ .../BlazingPizza.Client/Pages/MyOrders.razor | 2 ++ .../BlazingPizza.Client/Pages/OrderDetails.razor | 2 ++ save-points/03-show-order-status/BlazingPizza.Client/Program.cs | 2 ++ .../BlazingPizza.Client/Pages/Index.razor | 2 ++ .../BlazingPizza.Client/Pages/MyOrders.razor | 2 ++ .../BlazingPizza.Client/Pages/OrderDetails.razor | 2 ++ .../04-refactor-state-management/BlazingPizza.Client/Program.cs | 2 ++ .../BlazingPizza.Client/Pages/Checkout.razor | 2 ++ .../BlazingPizza.Client/Pages/Index.razor | 2 ++ .../BlazingPizza.Client/Pages/MyOrders.razor | 2 ++ .../BlazingPizza.Client/Pages/OrderDetails.razor | 2 ++ .../05-checkout-with-validation/BlazingPizza.Client/Program.cs | 2 ++ .../BlazingPizza.Client/Pages/Checkout.razor | 2 ++ .../BlazingPizza.Client/Pages/Index.razor | 2 ++ .../BlazingPizza.Client/Pages/MyOrders.razor | 2 ++ .../BlazingPizza.Client/Pages/OrderDetails.razor | 2 ++ .../BlazingPizza.Client/Program.cs | 2 ++ .../BlazingPizza.Client/Pages/Checkout.razor | 2 ++ .../07-javascript-interop/BlazingPizza.Client/Pages/Index.razor | 2 ++ .../BlazingPizza.Client/Pages/MyOrders.razor | 2 ++ .../BlazingPizza.Client/Pages/OrderDetails.razor | 2 ++ .../07-javascript-interop/BlazingPizza.Client/Program.cs | 2 ++ .../BlazingPizza.Client/Pages/Checkout.razor | 2 ++ .../BlazingPizza.Client/Pages/Index.razor | 2 ++ .../BlazingPizza.Client/Pages/MyOrders.razor | 2 ++ .../BlazingPizza.Client/Pages/OrderDetails.razor | 2 ++ .../08-templated-components/BlazingPizza.Client/Program.cs | 2 ++ .../BlazingPizza.Client/Pages/Checkout.razor | 2 ++ .../BlazingPizza.Client/Pages/Index.razor | 2 ++ .../BlazingPizza.Client/Pages/MyOrders.razor | 2 ++ .../BlazingPizza.Client/Pages/OrderDetails.razor | 2 ++ .../09-progressive-web-app/BlazingPizza.Client/Program.cs | 2 ++ src/BlazingPizza.Client/Pages/Checkout.razor | 2 ++ src/BlazingPizza.Client/Pages/Index.razor | 2 ++ src/BlazingPizza.Client/Pages/MyOrders.razor | 2 ++ src/BlazingPizza.Client/Pages/OrderDetails.razor | 2 ++ src/BlazingPizza.Client/Program.cs | 2 ++ 42 files changed, 84 insertions(+) diff --git a/save-points/00-get-started/BlazingPizza.Client/Program.cs b/save-points/00-get-started/BlazingPizza.Client/Program.cs index ab7dd4d9..c5023d76 100644 --- a/save-points/00-get-started/BlazingPizza.Client/Program.cs +++ b/save-points/00-get-started/BlazingPizza.Client/Program.cs @@ -1,8 +1,10 @@ using BlazingPizza.Client; +using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add("#app"); +builder.RootComponents.Add("head::after"); builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); diff --git a/save-points/01-Components-and-layout/BlazingPizza.Client/Program.cs b/save-points/01-Components-and-layout/BlazingPizza.Client/Program.cs index ab7dd4d9..c5023d76 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Client/Program.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Client/Program.cs @@ -1,8 +1,10 @@ using BlazingPizza.Client; +using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add("#app"); +builder.RootComponents.Add("head::after"); builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Client/Pages/Index.razor b/save-points/02-customize-a-pizza/BlazingPizza.Client/Pages/Index.razor index 808b7307..76b485f7 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Client/Pages/Index.razor +++ b/save-points/02-customize-a-pizza/BlazingPizza.Client/Pages/Index.razor @@ -1,6 +1,8 @@ @page "/" @inject HttpClient HttpClient +Blazing Pizza +