From 08ce819fc2b511a00852fc2abd847050ce32dd37 Mon Sep 17 00:00:00 2001 From: "Jeffrey T. Fritz" Date: Fri, 28 Jan 2022 14:54:02 -0500 Subject: [PATCH] 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