diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..3413bda9 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,189 @@ +# Rules in this file were initially inferred by Visual Studio IntelliCode from the C:\dev\dnp\blazor-workshop\src codebase based on best match to current usage at 3/28/2022 +# You can modify the rules from these initially generated values to suit your own policies +# You can learn more about editorconfig here: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference +[*.cs] + + +#Formatting - new line options + +#place catch statements on a new line +csharp_new_line_before_catch = true +#place else statements on a new line +csharp_new_line_before_else = true +#require members of anonymous types to be on separate lines +csharp_new_line_before_members_in_anonymous_types = true +#require members of object intializers to be on separate lines +csharp_new_line_before_members_in_object_initializers = true +#require braces to be on a new line for methods, control_blocks, types, object_collection_array_initializers, and anonymous_types (also known as "Allman" style) +csharp_new_line_before_open_brace = methods, control_blocks, types, object_collection_array_initializers, anonymous_types + +#Formatting - organize using options + +#sort System.* using directives alphabetically, and place them before other usings +dotnet_sort_system_directives_first = true + +#Formatting - spacing options + +#require NO space between a cast and the value +csharp_space_after_cast = false +#require a space before the colon for bases or interfaces in a type declaration +csharp_space_after_colon_in_inheritance_clause = true +#require a space after a keyword in a control flow statement such as a for loop +csharp_space_after_keywords_in_control_flow_statements = true +#require a space before the colon for bases or interfaces in a type declaration +csharp_space_before_colon_in_inheritance_clause = true +#remove space within empty argument list parentheses +csharp_space_between_method_call_empty_parameter_list_parentheses = false +#remove space between method call name and opening parenthesis +csharp_space_between_method_call_name_and_opening_parenthesis = false +#do not place space characters after the opening parenthesis and before the closing parenthesis of a method call +csharp_space_between_method_call_parameter_list_parentheses = false +#remove space within empty parameter list parentheses for a method declaration +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +#place a space character after the opening parenthesis and before the closing parenthesis of a method declaration parameter list. +csharp_space_between_method_declaration_parameter_list_parentheses = false + +#Formatting - wrapping options + +#leave code block on single line +csharp_preserve_single_line_blocks = true + +#Style - Code block preferences + +#prefer curly braces even for one line of code +csharp_prefer_braces = true:suggestion + +#Style - expression bodied member options + +#prefer block bodies for constructors +csharp_style_expression_bodied_constructors = false:suggestion +#prefer block bodies for methods +csharp_style_expression_bodied_methods = false:suggestion +#prefer expression-bodied members for properties +csharp_style_expression_bodied_properties = true:suggestion + +#Style - expression level options + +#prefer ItemX properties to tuple names +dotnet_style_explicit_tuple_names = false:suggestion +#prefer the language keyword for member access expressions, instead of the type name, for types that have a keyword to represent them +dotnet_style_predefined_type_for_member_access = true:suggestion + +#Style - Expression-level preferences + +#prefer objects to be initialized using object initializers when possible +dotnet_style_object_initializer = true:suggestion +#prefer inferred anonymous type member names +dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion +#prefer inferred tuple element names +dotnet_style_prefer_inferred_tuple_names = true:suggestion + +#Style - implicit and explicit types + +#prefer var over explicit type in all cases, unless overridden by another code style rule +csharp_style_var_elsewhere = true:suggestion +#prefer var is used to declare variables with built-in system types such as int +csharp_style_var_for_built_in_types = true:suggestion +#prefer var when the type is already mentioned on the right-hand side of a declaration expression +csharp_style_var_when_type_is_apparent = true:suggestion + +#Style - language keyword and framework type options + +#prefer the language keyword for local variables, method parameters, and class members, instead of the type name, for types that have a keyword to represent them +dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion + +#Style - modifier options + +#prefer accessibility modifiers to be declared except for public interface members. This will currently not differ from always and will act as future proofing for if C# adds default interface methods. +dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion + +#Style - Modifier preferences + +#when this rule is set to a list of modifiers, prefer the specified ordering. +csharp_preferred_modifier_order = public,private,protected,static,async,readonly,override:suggestion + +#Style - qualification options + +#prefer fields not to be prefaced with this. or Me. in Visual Basic +dotnet_style_qualification_for_field = false:suggestion +#prefer methods not to be prefaced with this. or Me. in Visual Basic +dotnet_style_qualification_for_method = false:suggestion +#prefer properties not to be prefaced with this. or Me. in Visual Basic +dotnet_style_qualification_for_property = false:suggestion +csharp_using_directive_placement = outside_namespace:silent +csharp_prefer_simple_using_statement = true:suggestion +csharp_style_namespace_declarations = block_scoped:silent +csharp_style_prefer_method_group_conversion = true:silent +csharp_style_expression_bodied_operators = false:silent +csharp_style_expression_bodied_indexers = true:silent +csharp_style_expression_bodied_accessors = true:silent +csharp_style_expression_bodied_lambdas = true:silent +csharp_style_expression_bodied_local_functions = false:silent +csharp_indent_labels = one_less_than_current + +[*.{cs,vb}] +#### Naming styles #### + +# Naming rules + +dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion +dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface +dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i + +dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.types_should_be_pascal_case.symbols = types +dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case + +dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members +dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case + +# Symbol specifications + +dotnet_naming_symbols.interface.applicable_kinds = interface +dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.interface.required_modifiers = + +dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum +dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.types.required_modifiers = + +dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method +dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.non_field_members.required_modifiers = + +# Naming styles + +dotnet_naming_style.begins_with_i.required_prefix = I +dotnet_naming_style.begins_with_i.required_suffix = +dotnet_naming_style.begins_with_i.word_separator = +dotnet_naming_style.begins_with_i.capitalization = pascal_case + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case +dotnet_style_coalesce_expression = true:suggestion +dotnet_style_null_propagation = true:suggestion +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion +dotnet_style_prefer_auto_properties = true:silent +dotnet_style_object_initializer = true:suggestion +dotnet_style_collection_initializer = true:suggestion +dotnet_style_prefer_simplified_boolean_expressions = true:suggestion +dotnet_style_prefer_conditional_expression_over_assignment = true:silent +dotnet_style_prefer_conditional_expression_over_return = true:silent +dotnet_style_explicit_tuple_names = false:suggestion +dotnet_style_prefer_inferred_tuple_names = true:suggestion +dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion +dotnet_style_prefer_compound_assignment = true:suggestion +dotnet_style_operator_placement_when_wrapping = beginning_of_line +indent_style = space +tab_width = 4 +indent_size = 4 +end_of_line = crlf +dotnet_style_prefer_simplified_interpolation = true:suggestion diff --git a/Directory.Build.props b/Directory.Build.props index bb2df7b9..8a52c1ed 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,8 +1,9 @@ - 5.0.0 - 5.0.0 - 5.0.0 - 5.0.0 + 6.0.0 + 6.0.0 + 6.0.0 + net6.0 + 6.0.0 diff --git a/docs/03-show-order-status.md b/docs/03-show-order-status.md index f67d7b9f..df81d10d 100644 --- a/docs/03-show-order-status.md +++ b/docs/03-show-order-status.md @@ -56,6 +56,26 @@ Now when you run the app, you'll be able to visit this page: Also notice that this time, no full-page load occurs when you navigate, because the URL is matched entirely within the client-side SPA. As such, navigation is instantaneous. +## Adding a page title + +In your browser, the title of the new page is listed as **Blazing Pizza** and it would be nice to update the title to reflect that this is the 'My Orders' page. We can use the new `PageTitle` component to update the title from the `MyOrders.razor` page: + +```html +@page "/myorders" + +Blazing Pizza - My Orders + +
+ My orders will go here +
+``` + +This works because inside the `Program.cs` file is an entry that adds a `HeadOutlet` component to the HTML presenting the BlazingPizza application. Blazor uses this `HeadOutlet` to write content into the header of the HTML page. + +```csharp +builder.RootComponents.Add("head::after"); +``` + ## Highlighting navigation position Look closely at the top bar. Notice that when you're on "My orders", the link *isn't* highlighted in yellow. How can we highlight links when the user is on them? By using a `NavLink` component instead of a plain `` tag. The only special thing a `NavLink` component does is toggle its own `active` CSS class depending on whether its `href` matches the current navigation state. diff --git a/docs/05-checkout-with-validation.md b/docs/05-checkout-with-validation.md index a593698e..3a48f848 100644 --- a/docs/05-checkout-with-validation.md +++ b/docs/05-checkout-with-validation.md @@ -9,6 +9,8 @@ It's time to fix this by adding a "checkout" screen that requires customers to e Start by adding a new page component, `Checkout.razor`, with a `@page` directive matching the URL `/checkout`. For the initial markup, let's display the details of the order using your `OrderReview` component: ```razor +Blazing Pizza - Checkout +
diff --git a/docs/06-authentication-and-authorization.md b/docs/06-authentication-and-authorization.md index 3bea9069..a3e2f238 100644 --- a/docs/06-authentication-and-authorization.md +++ b/docs/06-authentication-and-authorization.md @@ -263,6 +263,48 @@ builder.Services.AddHttpClient(client => client.BaseAddress = new .AddHttpMessageHandler(); ``` +### Optional: Optimize JSON interactions with .NET 6 JSON CodeGeneration + +Starting with .NET 6, the System.Text.Json.JsonSerializer supports working with optimized code generated for serializing and deserializing JSON payloads. Code is generated at build time, resulting in a significant performance improvement for the serialization and deserialization of JSON data. This is configured by taking the following steps: + +1. Create a partial Context class that inherits from `System.Text.Json.Serialization.JsonSerializerContext` +2. Decorate the class with the `System.Text.Json.JsonSourceGenerationOptions` attribute +3. Add `JsonSerializable` attributes to the class definition for each type that you would like to have code generated + +We have already written this context for you and it is located in the `BlazingPizza.Shared.Order.cs" file + +```csharp +[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 {} +``` + +You can now optimize the calls to the HttpClient in the `OrdersClient` class by passing an `OrderContext.Default` parameter pointing to the type sought as the second parameter. Updating the methods in the `OrdersClient` class should look like the following: + +```csharp +public async Task> GetOrders() => + await httpClient.GetFromJsonAsync("orders", OrderContext.Default.ListOrderWithStatus); + +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, OrderContext.Default.Order); + response.EnsureSuccessStatusCode(); + var orderId = await response.Content.ReadFromJsonAsync(); + return orderId; +} +``` + +### Deploy OrdersClient to pages + Update each page where an `HttpClient` is used to manage orders to use the new typed `OrdersClient`. Inject an `OrdersClient` instead of an `HttpClient` and use the new client to make the API call. Wrap each call in a `try-catch` that handles exceptions of type `AccessTokenNotAvailableException` by calling the provided `Redirect()` method. *Checkout.razor* diff --git a/src/nuget.config b/nuget.config similarity index 84% rename from src/nuget.config rename to nuget.config index c128a804..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 04df2ddd..08e409ff 100644 --- a/save-points/00-get-started/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/save-points/00-get-started/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -1,7 +1,8 @@  - net5.0 + $(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..c5023d76 100644 --- a/save-points/00-get-started/BlazingPizza.Client/Program.cs +++ b/save-points/00-get-started/BlazingPizza.Client/Program.cs @@ -1,21 +1,11 @@ -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.Web; +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.RootComponents.Add("head::after"); - 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 5f51ee3c..b50155b9 100644 --- a/save-points/00-get-started/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/save-points/00-get-started/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -1,7 +1,8 @@  - net5.0 + $(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..25567243 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.ComponentsLibrary/Map/Marker.cs b/save-points/00-get-started/BlazingPizza.ComponentsLibrary/Map/Marker.cs index 63006067..cae70a4e 100644 --- a/save-points/00-get-started/BlazingPizza.ComponentsLibrary/Map/Marker.cs +++ b/save-points/00-get-started/BlazingPizza.ComponentsLibrary/Map/Marker.cs @@ -1,13 +1,12 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Marker { - public class Marker - { - public string Description { get; set; } + public string Description { get; set; } - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } + public double Y { get; set; } - public bool ShowPopup { get; set; } - } -} + public bool ShowPopup { get; set; } +} \ No newline at end of file diff --git a/save-points/00-get-started/BlazingPizza.ComponentsLibrary/Map/Point.cs b/save-points/00-get-started/BlazingPizza.ComponentsLibrary/Map/Point.cs index 03841826..34194163 100644 --- a/save-points/00-get-started/BlazingPizza.ComponentsLibrary/Map/Point.cs +++ b/save-points/00-get-started/BlazingPizza.ComponentsLibrary/Map/Point.cs @@ -1,9 +1,8 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Point { - public class Point - { - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } - } -} + public double Y { get; set; } +} \ No newline at end of file diff --git a/save-points/00-get-started/BlazingPizza.Server/BlazingPizza.Server.csproj b/save-points/00-get-started/BlazingPizza.Server/BlazingPizza.Server.csproj index fd7e3c51..227890e1 100644 --- a/save-points/00-get-started/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/save-points/00-get-started/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -1,7 +1,8 @@  - net5.0 + $(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..3d385048 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) { - public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) - { - ClientRequestParametersProvider = 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..37e37cc5 100644 --- a/save-points/00-get-started/BlazingPizza.Server/OrdersController.cs +++ b/save-points/00-get-started/BlazingPizza.Server/OrdersController.cs @@ -1,29 +1,25 @@ -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; + private readonly PizzaStoreContext _db; - public OrdersController(PizzaStoreContext db) - { - _db = db; - } + public OrdersController(PizzaStoreContext db) + { + _db = db; + } - [HttpGet] - public async Task>> GetOrders() - { - var orders = await _db.Orders + [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) @@ -31,13 +27,13 @@ public async Task>> GetOrders() .OrderByDescending(o => o.CreatedTime) .ToListAsync(); - return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); - } + return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); + } - [HttpGet("{orderId}")] - public async Task> GetOrderWithStatus(int orderId) - { - var order = await _db.Orders + [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) @@ -45,70 +41,69 @@ public async Task> GetOrderWithStatus(int orderId) .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) .SingleOrDefaultAsync(); - if (order == null) - { - return NotFound(); - } - - return OrderWithStatus.FromOrder(order); + if (order == null) + { + return NotFound(); } - [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; - } - } + return OrderWithStatus.FromOrder(order); + } - _db.Orders.Attach(order); - await _db.SaveChangesAsync(); + [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; - // In the background, send push notifications if possible - var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); - if (subscription != null) + foreach (var topping in pizza.Toppings) { - _ = TrackAndSendNotificationsAsync(order, subscription); + topping.ToppingId = topping.Topping.Id; + topping.Topping = null; } - - return order.OrderId; } - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } + _db.Orders.Attach(order); + await _db.SaveChangesAsync(); - private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription subscription) + // In the background, send push notifications if possible + var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); + if (subscription != null) { - // 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!"); + _ = TrackAndSendNotificationsAsync(order, subscription); } - private static Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) - { - // This will be implemented later - return Task.CompletedTask; - } + 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..524ca759 --- /dev/null +++ b/save-points/00-get-started/BlazingPizza.Server/PizzaApiExtensions.cs @@ -0,0 +1,57 @@ +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 f79c1c66..1505c7af 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 IdentityServer4.EntityFramework.Options; +using Duende.IdentityServer.EntityFramework.Options; using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class PizzaStoreContext : ApiAuthorizationDbContext { - public class PizzaStoreContext : ApiAuthorizationDbContext - { - public PizzaStoreContext( + 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..e185db50 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 BlazingPizza.Server; +using Microsoft.AspNetCore.Authentication; +using Microsoft.EntityFrameworkCore; -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()) { - public class Program + var db = scope.ServiceProvider.GetRequiredService(); + if (db.Database.EnsureCreated()) { - 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(); - }); + SeedData.Initialize(db); } } + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + 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.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..f02e2b77 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) { - public static void Initialize(PizzaStoreContext db) + var toppings = new Topping[] { - var toppings = new Topping[] + new Topping() { - new Topping() - { Name = "Extra cheese", Price = 2.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "American bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "British bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Canadian bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Tea and crumpets", Price = 5.00m - }, - new Topping() - { + }, + new Topping() + { Name = "Fresh-baked scones", Price = 4.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Bell peppers", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Onions", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Mushrooms", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Pepperoni", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Duck sausage", Price = 3.20m, - }, - new Topping() - { + }, + new Topping() + { Name = "Venison meatballs", Price = 2.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Served on a silver platter", Price = 250.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Lobster on top", Price = 64.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Sturgeon caviar", Price = 101.75m, - }, - new Topping() - { + }, + new Topping() + { Name = "Artichoke hearts", Price = 3.40m, - }, - new Topping() - { + }, + new Topping() + { Name = "Fresh tomatoes", Price = 1.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Basil", Price = 1.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Steak (medium-rare)", Price = 8.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Blazing hot peppers", Price = 4.20m, - }, - new Topping() - { + }, + new Topping() + { Name = "Buffalo chicken", Price = 5.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Blue cheese", Price = 2.50m, - }, - }; + }, + }; - var specials = new PizzaSpecial[] + var specials = new PizzaSpecial[] + { + 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() - { + }, + new PizzaSpecial() + { Id = 2, Name = "The Baconatorizor", Description = "It has EVERY kind of bacon", BasePrice = 11.99m, ImageUrl = "img/pizzas/bacon.jpg", - }, - new PizzaSpecial() - { + }, + 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() - { + }, + 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() - { + }, + 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() - { + }, + new PizzaSpecial() + { Id = 6, Name = "The Brit", Description = "When in London...", BasePrice = 10.25m, ImageUrl = "img/pizzas/brit.jpg", - }, - new PizzaSpecial() - { + }, + 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() - { + }, + 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/save-points/00-get-started/BlazingPizza.Shared/Address.cs b/save-points/00-get-started/BlazingPizza.Shared/Address.cs index e5c0ef0d..a671359a 100644 --- a/save-points/00-get-started/BlazingPizza.Shared/Address.cs +++ b/save-points/00-get-started/BlazingPizza.Shared/Address.cs @@ -1,21 +1,24 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class Address { - public class Address - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + [Required, MaxLength(100)] + public string Name { get; set; } - public string Line1 { get; set; } + [Required, MaxLength(100)] + public string Line1 { get; set; } - public string Line2 { get; set; } + [MaxLength(100)] + public string Line2 { get; set; } - public string City { get; set; } + [Required, MaxLength(50)] + public string City { get; set; } - public string Region { get; set; } + [Required, MaxLength(20)] + public string Region { get; set; } - public string PostalCode { get; set; } - } + [Required, MaxLength(20)] + public string PostalCode { get; set; } } diff --git a/save-points/00-get-started/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/save-points/00-get-started/BlazingPizza.Shared/BlazingPizza.Shared.csproj index 911c57c5..fb17e53b 100644 --- a/save-points/00-get-started/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/save-points/00-get-started/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -1,10 +1,15 @@  - net5.0 + $(TargetFrameworkVersion) BlazingPizza + true + + + + diff --git a/save-points/00-get-started/BlazingPizza.Shared/LatLong.cs b/save-points/00-get-started/BlazingPizza.Shared/LatLong.cs index 9b8c3811..a65971f8 100644 --- a/save-points/00-get-started/BlazingPizza.Shared/LatLong.cs +++ b/save-points/00-get-started/BlazingPizza.Shared/LatLong.cs @@ -1,27 +1,26 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class LatLong { - public class LatLong + public LatLong() { - public LatLong() - { - } + } - public LatLong(double latitude, double longitude) : this() - { - Latitude = latitude; - Longitude = longitude; - } + public LatLong(double latitude, double longitude) : this() + { + Latitude = latitude; + Longitude = longitude; + } - public double Latitude { get; set; } + public double Latitude { get; set; } - public double Longitude { get; set; } + public double Longitude { get; set; } - public static LatLong Interpolate(LatLong start, LatLong end, double proportion) - { - // The Earth is flat, right? So no need for spherical interpolation. - return new LatLong( + public static LatLong Interpolate(LatLong start, LatLong end, double proportion) + { + // The Earth is flat, right? So no need for spherical interpolation. + return new LatLong( start.Latitude + (end.Latitude - start.Latitude) * proportion, start.Longitude + (end.Longitude - start.Longitude) * proportion); - } } -} +} \ No newline at end of file diff --git a/save-points/00-get-started/BlazingPizza.Shared/NotificationSubscription.cs b/save-points/00-get-started/BlazingPizza.Shared/NotificationSubscription.cs index 04259c2f..5c99e3f4 100644 --- a/save-points/00-get-started/BlazingPizza.Shared/NotificationSubscription.cs +++ b/save-points/00-get-started/BlazingPizza.Shared/NotificationSubscription.cs @@ -1,17 +1,14 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class NotificationSubscription { - public class NotificationSubscription - { - public int NotificationSubscriptionId { get; set; } + public int NotificationSubscriptionId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public string Url { get; set; } + public string Url { get; set; } - public string P256dh { get; set; } + public string P256dh { get; set; } - public string Auth { get; set; } - } + public string Auth { get; set; } } diff --git a/save-points/00-get-started/BlazingPizza.Shared/Order.cs b/save-points/00-get-started/BlazingPizza.Shared/Order.cs index fb003bd6..b47efad0 100644 --- a/save-points/00-get-started/BlazingPizza.Shared/Order.cs +++ b/save-points/00-get-started/BlazingPizza.Shared/Order.cs @@ -1,25 +1,32 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +public class Order { - public class Order - { - public int OrderId { get; set; } + public int OrderId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public DateTime CreatedTime { get; set; } + public DateTime CreatedTime { get; set; } - public Address DeliveryAddress { get; set; } = new Address(); + public Address DeliveryAddress { get; set; } = new Address(); - public LatLong DeliveryLocation { get; set; } + public LatLong DeliveryLocation { get; set; } - public List Pizzas { get; set; } = new List(); + public List Pizzas { get; set; } = new List(); - public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); + public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); - public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); - } + public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Default, PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] +[JsonSerializable(typeof(Order))] +[JsonSerializable(typeof(OrderWithStatus))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Pizza))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Topping))] +public partial class OrderContext : JsonSerializerContext { } \ No newline at end of file diff --git a/save-points/00-get-started/BlazingPizza.Shared/OrderWithStatus.cs b/save-points/00-get-started/BlazingPizza.Shared/OrderWithStatus.cs index 021de78c..fbfac7af 100644 --- a/save-points/00-get-started/BlazingPizza.Shared/OrderWithStatus.cs +++ b/save-points/00-get-started/BlazingPizza.Shared/OrderWithStatus.cs @@ -1,79 +1,78 @@ -using BlazingPizza.ComponentsLibrary.Map; -using System; -using System.Collections.Generic; +using System.Text.Json.Serialization; +using BlazingPizza.ComponentsLibrary.Map; -namespace BlazingPizza -{ - 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 Order Order { get; set; } +namespace BlazingPizza; - public string StatusText { get; set; } +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 bool IsDelivered => StatusText == "Delivered"; + public Order Order { get; set; } - public List MapMarkers { get; set; } + public string StatusText { 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 bool IsDelivered => StatusText == "Delivered"; - 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"; + public List MapMarkers { get; set; } - 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), - }; - } + 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); - return new OrderWithStatus - { - Order = order, - StatusText = statusText, - MapMarkers = mapMarkers, - }; + 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"; - private static LatLong ComputeStartPosition(Order order) + 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 { - // 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); + statusText = "Delivered"; + mapMarkers = new List + { + ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), + }; } - static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) - => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; + 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); + } + + static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) + => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; +} \ No newline at end of file diff --git a/save-points/00-get-started/BlazingPizza.Shared/Pizza.cs b/save-points/00-get-started/BlazingPizza.Shared/Pizza.cs index ec1108a9..2a7a1c29 100644 --- a/save-points/00-get-started/BlazingPizza.Shared/Pizza.cs +++ b/save-points/00-get-started/BlazingPizza.Shared/Pizza.cs @@ -1,42 +1,44 @@ -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// /// Represents a customized pizza as part of an order +/// +public class Pizza { - /// - /// Represents a customized pizza as part of an order - /// - public class Pizza - { - public const int DefaultSize = 12; - public const int MinimumSize = 9; - public const int MaximumSize = 17; + public const int DefaultSize = 12; + public const int MinimumSize = 9; + public const int MaximumSize = 17; - public int Id { get; set; } + public int Id { get; set; } - public int OrderId { get; set; } + public int OrderId { get; set; } - public PizzaSpecial Special { get; set; } + public PizzaSpecial Special { get; set; } - public int SpecialId { get; set; } + public int SpecialId { get; set; } - public int Size { get; set; } + public int Size { get; set; } - public List Toppings { get; set; } + public List Toppings { get; set; } - public decimal GetBasePrice() - { - return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; - } + public decimal GetBasePrice() + { + return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; + } - public decimal GetTotalPrice() - { - return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); - } + public decimal GetTotalPrice() + { + return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); + } - public string GetFormattedTotalPrice() - { - return GetTotalPrice().ToString("0.00"); - } + public string GetFormattedTotalPrice() + { + return GetTotalPrice().ToString("0.00"); } } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Serialization)] +[JsonSerializable(typeof(Pizza))] +public partial class PizzaContext : JsonSerializerContext { } \ No newline at end of file diff --git a/save-points/00-get-started/BlazingPizza.Shared/PizzaSpecial.cs b/save-points/00-get-started/BlazingPizza.Shared/PizzaSpecial.cs index 2f2b3383..1fd9006a 100644 --- a/save-points/00-get-started/BlazingPizza.Shared/PizzaSpecial.cs +++ b/save-points/00-get-started/BlazingPizza.Shared/PizzaSpecial.cs @@ -1,20 +1,19 @@ -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// Represents a pre-configured template for a pizza a user can order +/// +public class PizzaSpecial { - /// - /// Represents a pre-configured template for a pizza a user can order - /// - public class PizzaSpecial - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal BasePrice { get; set; } + public decimal BasePrice { get; set; } - public string Description { get; set; } + public string Description { get; set; } - public string ImageUrl { get; set; } + public string ImageUrl { get; set; } - public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); - } -} + public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); +} \ No newline at end of file diff --git a/save-points/00-get-started/BlazingPizza.Shared/PizzaTopping.cs b/save-points/00-get-started/BlazingPizza.Shared/PizzaTopping.cs index f5a6c1ac..1c062732 100644 --- a/save-points/00-get-started/BlazingPizza.Shared/PizzaTopping.cs +++ b/save-points/00-get-started/BlazingPizza.Shared/PizzaTopping.cs @@ -1,11 +1,11 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class PizzaTopping { - public class PizzaTopping - { - public Topping Topping { get; set; } - - public int ToppingId { get; set; } - - public int PizzaId { get; set; } - } -} + public Topping Topping { get; set; } + + public int ToppingId { get; set; } + + public int PizzaId { get; set; } + +} \ No newline at end of file diff --git a/save-points/00-get-started/BlazingPizza.Shared/Topping.cs b/save-points/00-get-started/BlazingPizza.Shared/Topping.cs index 61bdeb92..4eb67ae9 100644 --- a/save-points/00-get-started/BlazingPizza.Shared/Topping.cs +++ b/save-points/00-get-started/BlazingPizza.Shared/Topping.cs @@ -1,13 +1,13 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class Topping { - public class Topping - { - public int Id { get; set; } + public int Id { get; set; } + + public string Name { get; set; } - public string Name { get; set; } + public decimal Price { get; set; } - public decimal Price { get; set; } + public string GetFormattedPrice() => Price.ToString("0.00"); - public string GetFormattedPrice() => Price.ToString("0.00"); - } -} +} \ No newline at end of file diff --git a/save-points/00-get-started/BlazingPizza.Shared/UserInfo.cs b/save-points/00-get-started/BlazingPizza.Shared/UserInfo.cs index 4996ef80..babb4315 100644 --- a/save-points/00-get-started/BlazingPizza.Shared/UserInfo.cs +++ b/save-points/00-get-started/BlazingPizza.Shared/UserInfo.cs @@ -1,9 +1,9 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class UserInfo { - public class UserInfo - { - public bool IsAuthenticated { get; set; } + public bool IsAuthenticated { get; set; } + + public string Name { get; set; } - public string Name { get; set; } - } -} +} \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Client/BlazingPizza.Client.csproj b/save-points/01-Components-and-layout/BlazingPizza.Client/BlazingPizza.Client.csproj index a833c6be..f9ebe283 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/save-points/01-Components-and-layout/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -1,7 +1,8 @@  - net5.0 + $(TargetFrameworkVersion) + true diff --git a/save-points/01-Components-and-layout/BlazingPizza.Client/Pages/Index.razor b/save-points/01-Components-and-layout/BlazingPizza.Client/Pages/Index.razor index 68649ba9..03d6e160 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Client/Pages/Index.razor +++ b/save-points/01-Components-and-layout/BlazingPizza.Client/Pages/Index.razor @@ -24,6 +24,6 @@ protected override async Task OnInitializedAsync() { - specials = await HttpClient.GetFromJsonAsync>("specials"); + specials = await HttpClient.GetFromJsonAsync("specials", BlazingPizza.OrderContext.Default.ListPizzaSpecial); } } diff --git a/save-points/01-Components-and-layout/BlazingPizza.Client/Program.cs b/save-points/01-Components-and-layout/BlazingPizza.Client/Program.cs index 48147d6f..c5023d76 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Client/Program.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Client/Program.cs @@ -1,21 +1,11 @@ -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.Web; +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.RootComponents.Add("head::after"); - builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); +builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); - await builder.Build().RunAsync(); - } - } -} +await builder.Build().RunAsync(); diff --git a/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 5f51ee3c..cb996b1b 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -1,7 +1,8 @@  - net5.0 + $(TargetFrameworkVersion) + true diff --git a/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/LocalStorage.cs b/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/LocalStorage.cs index f36b098e..be8226ec 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/LocalStorage.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/LocalStorage.cs @@ -1,17 +1,15 @@ using Microsoft.JSInterop; -using System.Threading.Tasks; -namespace BlazingPizza.ComponentsLibrary +namespace BlazingPizza.ComponentsLibrary; + +public static class LocalStorage { - public static class LocalStorage - { - public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) + public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); - public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object 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) + public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key) => jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key); - } -} +} \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/Map/Marker.cs b/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/Map/Marker.cs index 63006067..4761dcd6 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/Map/Marker.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/Map/Marker.cs @@ -1,13 +1,11 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; +public class Marker { - public class Marker - { - public string Description { get; set; } + public string Description { get; set; } - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } + public double Y { get; set; } - public bool ShowPopup { get; set; } - } -} + public bool ShowPopup { get; set; } +} \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/Map/Point.cs b/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/Map/Point.cs index 03841826..054e56ec 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/Map/Point.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.ComponentsLibrary/Map/Point.cs @@ -1,9 +1,9 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Point { - public class Point - { - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } - } + public double Y { get; set; } } +// Compare this snippet from save-points\01-Components-and-layout\BlazingPizza.ComponentsLibrary\Map\Marker.cs: \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/BlazingPizza.Server.csproj b/save-points/01-Components-and-layout/BlazingPizza.Server/BlazingPizza.Server.csproj index fd7e3c51..227890e1 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -1,7 +1,8 @@  - net5.0 + $(TargetFrameworkVersion) + true diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/AddressEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/AddressEntityType.cs new file mode 100644 index 00000000..82db81b6 --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/AddressEntityType.cs @@ -0,0 +1,92 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class AddressEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Address", + typeof(Address), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Address).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var city = runtimeEntityType.AddProperty( + "City", + typeof(string), + propertyInfo: typeof(Address).GetProperty("City", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var line1 = runtimeEntityType.AddProperty( + "Line1", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line1", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var line2 = runtimeEntityType.AddProperty( + "Line2", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line2", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var postalCode = runtimeEntityType.AddProperty( + "PostalCode", + typeof(string), + propertyInfo: typeof(Address).GetProperty("PostalCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var region = runtimeEntityType.AddProperty( + "Region", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Region", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Address"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs new file mode 100644 index 00000000..1dd4563b --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs @@ -0,0 +1,114 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class DeviceFlowCodesEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.DeviceFlowCodes", + typeof(DeviceFlowCodes), + baseEntityType); + + var userCode = runtimeEntityType.AddProperty( + "UserCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("UserCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var deviceCode = runtimeEntityType.AddProperty( + "DeviceCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("DeviceCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var key = runtimeEntityType.AddKey( + new[] { userCode }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deviceCode }, + unique: true); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "DeviceCodes"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs new file mode 100644 index 00000000..8946b261 --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRoleClaim", + typeof(IdentityRoleClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoleClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityRoleEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityRoleEntityType.cs new file mode 100644 index 00000000..2f1fec2b --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityRoleEntityType.cs @@ -0,0 +1,78 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRole", + typeof(IdentityRole), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedName = runtimeEntityType.AddProperty( + "NormalizedName", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("NormalizedName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedName }, + unique: true); + index.AddAnnotation("Relational:Name", "RoleNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs new file mode 100644 index 00000000..55418a1e --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserClaim", + typeof(IdentityUserClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityUserClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs new file mode 100644 index 00000000..3ca029bd --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserLoginstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserLogin", + typeof(IdentityUserLogin), + baseEntityType); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerKey = runtimeEntityType.AddProperty( + "ProviderKey", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderKey", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerDisplayName = runtimeEntityType.AddProperty( + "ProviderDisplayName", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderDisplayName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { loginProvider, providerKey }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserLogins"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs new file mode 100644 index 00000000..70078d7a --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs @@ -0,0 +1,82 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserRolestringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserRole", + typeof(IdentityUserRole), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { userId, roleId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs new file mode 100644 index 00000000..93ba6d31 --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs @@ -0,0 +1,84 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserTokenstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserToken", + typeof(IdentityUserToken), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var value = runtimeEntityType.AddProperty( + "Value", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Value", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { userId, loginProvider, name }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserTokens"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/KeyEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/KeyEntityType.cs new file mode 100644 index 00000000..f6c6b4c7 --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/KeyEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class KeyEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.Key", + typeof(Key), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var algorithm = runtimeEntityType.AddProperty( + "Algorithm", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Algorithm", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var created = runtimeEntityType.AddProperty( + "Created", + typeof(DateTime), + propertyInfo: typeof(Key).GetProperty("Created", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var dataProtected = runtimeEntityType.AddProperty( + "DataProtected", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("DataProtected", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var isX509Certificate = runtimeEntityType.AddProperty( + "IsX509Certificate", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("IsX509Certificate", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var use = runtimeEntityType.AddProperty( + "Use", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Use", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var version = runtimeEntityType.AddProperty( + "Version", + typeof(int), + propertyInfo: typeof(Key).GetProperty("Version", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { use }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Keys"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/LatLongEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/LatLongEntityType.cs new file mode 100644 index 00000000..3fd254bd --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/LatLongEntityType.cs @@ -0,0 +1,80 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class LatLongEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.LatLong", + typeof(LatLong), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var latitude = runtimeEntityType.AddProperty( + "Latitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Latitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var longitude = runtimeEntityType.AddProperty( + "Longitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Longitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + unique: true, + required: true, + ownership: true); + + var deliveryLocation = principalEntityType.AddNavigation("DeliveryLocation", + runtimeForeignKey, + onDependent: false, + typeof(LatLong), + propertyInfo: typeof(Order).GetProperty("DeliveryLocation", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + eagerLoaded: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs new file mode 100644 index 00000000..db236e4c --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs @@ -0,0 +1,77 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class NotificationSubscriptionEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.NotificationSubscription", + typeof(NotificationSubscription), + baseEntityType); + + var notificationSubscriptionId = runtimeEntityType.AddProperty( + "NotificationSubscriptionId", + typeof(int), + propertyInfo: typeof(NotificationSubscription).GetProperty("NotificationSubscriptionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var auth = runtimeEntityType.AddProperty( + "Auth", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Auth", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var p256dh = runtimeEntityType.AddProperty( + "P256dh", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("P256dh", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var url = runtimeEntityType.AddProperty( + "Url", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Url", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { notificationSubscriptionId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "NotificationSubscriptions"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/OrderEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/OrderEntityType.cs new file mode 100644 index 00000000..9d9ec6fd --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/OrderEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class OrderEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Order", + typeof(Order), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Order).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var createdTime = runtimeEntityType.AddProperty( + "CreatedTime", + typeof(DateTime), + propertyInfo: typeof(Order).GetProperty("CreatedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var deliveryAddressId = runtimeEntityType.AddProperty( + "DeliveryAddressId", + typeof(int?), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(Order).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deliveryAddressId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("DeliveryAddressId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType); + + var deliveryAddress = declaringEntityType.AddNavigation("DeliveryAddress", + runtimeForeignKey, + onDependent: true, + typeof(Address), + propertyInfo: typeof(Order).GetProperty("DeliveryAddress", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PersistedGrantEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PersistedGrantEntityType.cs new file mode 100644 index 00000000..842d53a5 --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PersistedGrantEntityType.cs @@ -0,0 +1,127 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PersistedGrantEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.PersistedGrant", + typeof(PersistedGrant), + baseEntityType); + + var key = runtimeEntityType.AddProperty( + "Key", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Key", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var consumedTime = runtimeEntityType.AddProperty( + "ConsumedTime", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("ConsumedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(PersistedGrant).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var type = runtimeEntityType.AddProperty( + "Type", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Type", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var key0 = runtimeEntityType.AddKey( + new[] { key }); + runtimeEntityType.SetPrimaryKey(key0); + + var index = runtimeEntityType.AddIndex( + new[] { consumedTime }); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + var index1 = runtimeEntityType.AddIndex( + new[] { subjectId, clientId, type }); + + var index2 = runtimeEntityType.AddIndex( + new[] { subjectId, sessionId, type }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PersistedGrants"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaEntityType.cs new file mode 100644 index 00000000..3a124e63 --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaEntityType.cs @@ -0,0 +1,111 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Pizza", + typeof(Pizza), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var size = runtimeEntityType.AddProperty( + "Size", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Size", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var specialId = runtimeEntityType.AddProperty( + "SpecialId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("SpecialId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { orderId }); + + var index0 = runtimeEntityType.AddIndex( + new[] { specialId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var pizzas = principalEntityType.AddNavigation("Pizzas", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Order).GetProperty("Pizzas", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("SpecialId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var special = declaringEntityType.AddNavigation("Special", + runtimeForeignKey, + onDependent: true, + typeof(PizzaSpecial), + propertyInfo: typeof(Pizza).GetProperty("Special", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Pizzas"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs new file mode 100644 index 00000000..e86b0f50 --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs @@ -0,0 +1,76 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaSpecialEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaSpecial", + typeof(PizzaSpecial), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(PizzaSpecial).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var basePrice = runtimeEntityType.AddProperty( + "BasePrice", + typeof(decimal), + propertyInfo: typeof(PizzaSpecial).GetProperty("BasePrice", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var imageUrl = runtimeEntityType.AddProperty( + "ImageUrl", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("ImageUrl", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Specials"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaStoreContextModel.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaStoreContextModel.cs new file mode 100644 index 00000000..8b516a68 --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaStoreContextModel.cs @@ -0,0 +1,28 @@ +// +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + [DbContext(typeof(PizzaStoreContext))] + public partial class PizzaStoreContextModel : RuntimeModel + { + static PizzaStoreContextModel() + { + var model = new PizzaStoreContextModel(); + model.Initialize(); + model.Customize(); + _instance = model; + } + + private static PizzaStoreContextModel _instance; + public static IModel Instance => _instance; + + partial void Initialize(); + + partial void Customize(); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs new file mode 100644 index 00000000..d46f50f4 --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs @@ -0,0 +1,69 @@ +// +using System; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + public partial class PizzaStoreContextModel + { + partial void Initialize() + { + var address = AddressEntityType.Create(this); + var latLong = LatLongEntityType.Create(this); + var notificationSubscription = NotificationSubscriptionEntityType.Create(this); + var order = OrderEntityType.Create(this); + var pizza = PizzaEntityType.Create(this); + var pizzaSpecial = PizzaSpecialEntityType.Create(this); + var pizzaTopping = PizzaToppingEntityType.Create(this); + var pizzaStoreUser = PizzaStoreUserEntityType.Create(this); + var topping = ToppingEntityType.Create(this); + var deviceFlowCodes = DeviceFlowCodesEntityType.Create(this); + var key = KeyEntityType.Create(this); + var persistedGrant = PersistedGrantEntityType.Create(this); + var identityRole = IdentityRoleEntityType.Create(this); + var identityRoleClaimstring = IdentityRoleClaimstringEntityType.Create(this); + var identityUserClaimstring = IdentityUserClaimstringEntityType.Create(this); + var identityUserLoginstring = IdentityUserLoginstringEntityType.Create(this); + var identityUserRolestring = IdentityUserRolestringEntityType.Create(this); + var identityUserTokenstring = IdentityUserTokenstringEntityType.Create(this); + + LatLongEntityType.CreateForeignKey1(latLong, order); + OrderEntityType.CreateForeignKey1(order, address); + PizzaEntityType.CreateForeignKey1(pizza, order); + PizzaEntityType.CreateForeignKey2(pizza, pizzaSpecial); + PizzaToppingEntityType.CreateForeignKey1(pizzaTopping, pizza); + PizzaToppingEntityType.CreateForeignKey2(pizzaTopping, topping); + IdentityRoleClaimstringEntityType.CreateForeignKey1(identityRoleClaimstring, identityRole); + IdentityUserClaimstringEntityType.CreateForeignKey1(identityUserClaimstring, pizzaStoreUser); + IdentityUserLoginstringEntityType.CreateForeignKey1(identityUserLoginstring, pizzaStoreUser); + IdentityUserRolestringEntityType.CreateForeignKey1(identityUserRolestring, identityRole); + IdentityUserRolestringEntityType.CreateForeignKey2(identityUserRolestring, pizzaStoreUser); + IdentityUserTokenstringEntityType.CreateForeignKey1(identityUserTokenstring, pizzaStoreUser); + + AddressEntityType.CreateAnnotations(address); + LatLongEntityType.CreateAnnotations(latLong); + NotificationSubscriptionEntityType.CreateAnnotations(notificationSubscription); + OrderEntityType.CreateAnnotations(order); + PizzaEntityType.CreateAnnotations(pizza); + PizzaSpecialEntityType.CreateAnnotations(pizzaSpecial); + PizzaToppingEntityType.CreateAnnotations(pizzaTopping); + PizzaStoreUserEntityType.CreateAnnotations(pizzaStoreUser); + ToppingEntityType.CreateAnnotations(topping); + DeviceFlowCodesEntityType.CreateAnnotations(deviceFlowCodes); + KeyEntityType.CreateAnnotations(key); + PersistedGrantEntityType.CreateAnnotations(persistedGrant); + IdentityRoleEntityType.CreateAnnotations(identityRole); + IdentityRoleClaimstringEntityType.CreateAnnotations(identityRoleClaimstring); + IdentityUserClaimstringEntityType.CreateAnnotations(identityUserClaimstring); + IdentityUserLoginstringEntityType.CreateAnnotations(identityUserLoginstring); + IdentityUserRolestringEntityType.CreateAnnotations(identityUserRolestring); + IdentityUserTokenstringEntityType.CreateAnnotations(identityUserTokenstring); + + AddAnnotation("ProductVersion", "6.0.0"); + } + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs new file mode 100644 index 00000000..18b2d96d --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs @@ -0,0 +1,156 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaStoreUserEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Server.PizzaStoreUser", + typeof(PizzaStoreUser), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var accessFailedCount = runtimeEntityType.AddProperty( + "AccessFailedCount", + typeof(int), + propertyInfo: typeof(IdentityUser).GetProperty("AccessFailedCount", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var email = runtimeEntityType.AddProperty( + "Email", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Email", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var emailConfirmed = runtimeEntityType.AddProperty( + "EmailConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("EmailConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnabled = runtimeEntityType.AddProperty( + "LockoutEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnd = runtimeEntityType.AddProperty( + "LockoutEnd", + typeof(DateTimeOffset?), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnd", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var normalizedEmail = runtimeEntityType.AddProperty( + "NormalizedEmail", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedEmail", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedUserName = runtimeEntityType.AddProperty( + "NormalizedUserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedUserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var passwordHash = runtimeEntityType.AddProperty( + "PasswordHash", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PasswordHash", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumber = runtimeEntityType.AddProperty( + "PhoneNumber", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumber", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumberConfirmed = runtimeEntityType.AddProperty( + "PhoneNumberConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumberConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var securityStamp = runtimeEntityType.AddProperty( + "SecurityStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("SecurityStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var twoFactorEnabled = runtimeEntityType.AddProperty( + "TwoFactorEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("TwoFactorEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var userName = runtimeEntityType.AddProperty( + "UserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("UserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedEmail }); + index.AddAnnotation("Relational:Name", "EmailIndex"); + + var index0 = runtimeEntityType.AddIndex( + new[] { normalizedUserName }, + unique: true); + index0.AddAnnotation("Relational:Name", "UserNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUsers"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaToppingEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaToppingEntityType.cs new file mode 100644 index 00000000..b97d2a24 --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/PizzaToppingEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaTopping", + typeof(PizzaTopping), + baseEntityType); + + var pizzaId = runtimeEntityType.AddProperty( + "PizzaId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("PizzaId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var toppingId = runtimeEntityType.AddProperty( + "ToppingId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("ToppingId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { pizzaId, toppingId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { toppingId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("PizzaId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var toppings = principalEntityType.AddNavigation("Toppings", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Pizza).GetProperty("Toppings", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("ToppingId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var topping = declaringEntityType.AddNavigation("Topping", + runtimeForeignKey, + onDependent: true, + typeof(Topping), + propertyInfo: typeof(PizzaTopping).GetProperty("Topping", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PizzaTopping"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Models/ToppingEntityType.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/ToppingEntityType.cs new file mode 100644 index 00000000..9295f9bf --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Models/ToppingEntityType.cs @@ -0,0 +1,62 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class ToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Topping", + typeof(Topping), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Topping).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Topping).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var price = runtimeEntityType.AddProperty( + "Price", + typeof(decimal), + propertyInfo: typeof(Topping).GetProperty("Price", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Toppings"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/NotificationsController.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/NotificationsController.cs deleted file mode 100644 index bb3b96ff..00000000 --- a/save-points/01-Components-and-layout/BlazingPizza.Server/NotificationsController.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("notifications")] - [ApiController] - [Authorize] - public class NotificationsController : Controller - { - private readonly PizzaStoreContext _db; - - public NotificationsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpPut("subscribe")] - public async Task Subscribe(NotificationSubscription subscription) - { - // We're storing at most one subscription per user, so delete old ones. - // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. - var userId = GetUserId(); - var oldSubscriptions = _db.NotificationSubscriptions.Where(e => e.UserId == userId); - _db.NotificationSubscriptions.RemoveRange(oldSubscriptions); - - // Store new subscription - subscription.UserId = userId; - _db.NotificationSubscriptions.Attach(subscription); - - await _db.SaveChangesAsync(); - return subscription; - } - - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } - } -} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/OidcConfigurationController.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/OidcConfigurationController.cs index c074debf..3d385048 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Server/OidcConfigurationController.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/OidcConfigurationController.cs @@ -1,26 +1,21 @@ using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class OidcConfigurationController : Controller { - public class OidcConfigurationController : Controller + public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) { - public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) - { - ClientRequestParametersProvider = clientRequestParametersProvider; - } + ClientRequestParametersProvider = clientRequestParametersProvider; + } - public IClientRequestParametersProvider ClientRequestParametersProvider { get; } + public IClientRequestParametersProvider ClientRequestParametersProvider { get; } - [HttpGet("_configuration/{clientId}")] - public IActionResult GetClientRequestParameters([FromRoute]string clientId) - { - var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); - return Ok(parameters); - } + [HttpGet("_configuration/{clientId}")] + public IActionResult GetClientRequestParameters([FromRoute] string clientId) + { + var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); + return Ok(parameters); } -} +} \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/OrdersController.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/OrdersController.cs index 2b8bc99b..37e37cc5 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Server/OrdersController.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/OrdersController.cs @@ -1,29 +1,25 @@ -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; + private readonly PizzaStoreContext _db; - public OrdersController(PizzaStoreContext db) - { - _db = db; - } + public OrdersController(PizzaStoreContext db) + { + _db = db; + } - [HttpGet] - public async Task>> GetOrders() - { - var orders = await _db.Orders + [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) @@ -31,13 +27,13 @@ public async Task>> GetOrders() .OrderByDescending(o => o.CreatedTime) .ToListAsync(); - return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); - } + return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); + } - [HttpGet("{orderId}")] - public async Task> GetOrderWithStatus(int orderId) - { - var order = await _db.Orders + [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) @@ -45,70 +41,69 @@ public async Task> GetOrderWithStatus(int orderId) .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) .SingleOrDefaultAsync(); - if (order == null) - { - return NotFound(); - } - - return OrderWithStatus.FromOrder(order); + if (order == null) + { + return NotFound(); } - [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; - } - } + return OrderWithStatus.FromOrder(order); + } - _db.Orders.Attach(order); - await _db.SaveChangesAsync(); + [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; - // In the background, send push notifications if possible - var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); - if (subscription != null) + foreach (var topping in pizza.Toppings) { - _ = TrackAndSendNotificationsAsync(order, subscription); + topping.ToppingId = topping.Topping.Id; + topping.Topping = null; } - - return order.OrderId; } - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } + _db.Orders.Attach(order); + await _db.SaveChangesAsync(); - private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription subscription) + // In the background, send push notifications if possible + var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); + if (subscription != null) { - // 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!"); + _ = TrackAndSendNotificationsAsync(order, subscription); } - private static Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) - { - // This will be implemented later - return Task.CompletedTask; - } + return order.OrderId; + } + + private string GetUserId() + { + return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); + } + + private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription subscription) + { + // In a realistic case, some other backend process would track + // order delivery progress and send us notifications when it + // changes. Since we don't have any such process here, fake it. + await Task.Delay(OrderWithStatus.PreparationDuration); + await SendNotificationAsync(order, subscription, "Your order has been dispatched!"); + + await Task.Delay(OrderWithStatus.DeliveryDuration); + await SendNotificationAsync(order, subscription, "Your order is now delivered. Enjoy!"); + } + + private static Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) + { + // This will be implemented later + return Task.CompletedTask; } -} +} \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/PizzaApiExtensions.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/PizzaApiExtensions.cs new file mode 100644 index 00000000..524ca759 --- /dev/null +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/PizzaApiExtensions.cs @@ -0,0 +1,57 @@ +using System.Security.Claims; +using Microsoft.AspNetCore.Authorization; +using Microsoft.EntityFrameworkCore; + +namespace BlazingPizza.Server; + +public static class PizzaApiExtensions +{ + + public static WebApplication MapPizzaApi(this WebApplication app) + { + + // Subscribe to notifications + app.MapPut("/notifications/subscribe", [Authorize] async ( + HttpContext context, + PizzaStoreContext db, + NotificationSubscription subscription) => { + + // We're storing at most one subscription per user, so delete old ones. + // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. + var userId = GetUserId(context); + var oldSubscriptions = db.NotificationSubscriptions.Where(e => e.UserId == userId); + db.NotificationSubscriptions.RemoveRange(oldSubscriptions); + + // Store new subscription + subscription.UserId = userId; + db.NotificationSubscriptions.Attach(subscription); + + await db.SaveChangesAsync(); + return Results.Ok(subscription); + + }); + + // Specials + app.MapGet("/specials", async (PizzaStoreContext db) => { + + var specials = await db.Specials.ToListAsync(); + return Results.Ok(specials); + + }); + + // Toppings + app.MapGet("/toppings", async (PizzaStoreContext db) => { + var toppings = await db.Toppings.OrderBy(t => t.Name).ToListAsync(); + return Results.Ok(toppings); + }); + + return app; + + } + + private static string GetUserId(HttpContext context) + { + return context.User.FindFirstValue(ClaimTypes.NameIdentifier); + } + +} \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/PizzaStoreContext.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/PizzaStoreContext.cs index f79c1c66..50ac87e4 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Server/PizzaStoreContext.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/PizzaStoreContext.cs @@ -1,39 +1,38 @@ -using IdentityServer4.EntityFramework.Options; +using Duende.IdentityServer.EntityFramework.Options; using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class PizzaStoreContext : ApiAuthorizationDbContext { - public class PizzaStoreContext : ApiAuthorizationDbContext - { - public PizzaStoreContext( + 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/01-Components-and-layout/BlazingPizza.Server/PizzaStoreUser.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/PizzaStoreUser.cs index 171ce83d..d446a679 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Server/PizzaStoreUser.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/PizzaStoreUser.cs @@ -1,8 +1,6 @@ using Microsoft.AspNetCore.Identity; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; +public class PizzaStoreUser : IdentityUser { - public class PizzaStoreUser : IdentityUser - { - } } \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/PizzasController.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/PizzasController.cs deleted file mode 100644 index c082552c..00000000 --- a/save-points/01-Components-and-layout/BlazingPizza.Server/PizzasController.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("pizzas")] - [ApiController] - public class PizzasController : Controller - { - private readonly PizzaStoreContext _db; - - public PizzasController(PizzaStoreContext db) - { - _db = db; - } - } -} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Program.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Program.cs index 40a47641..b83debb4 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Server/Program.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/Program.cs @@ -1,33 +1,67 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; +using BlazingPizza.Server; +using Microsoft.AspNetCore.Authentication; +using Microsoft.EntityFrameworkCore; -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()) { - public class Program + var db = scope.ServiceProvider.GetRequiredService(); + if (db.Database.EnsureCreated()) { - 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(); - }); + SeedData.Initialize(db); } } + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + 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.MapPizzaApi(); + +app.MapRazorPages(); +app.MapControllers(); +app.MapFallbackToFile("index.html"); + +app.Run(); \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/SeedData.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/SeedData.cs index 7c86a5b2..f02e2b77 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Server/SeedData.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Server/SeedData.cs @@ -1,193 +1,192 @@ -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public static class SeedData { - public static class SeedData + public static void Initialize(PizzaStoreContext db) { - public static void Initialize(PizzaStoreContext db) + var toppings = new Topping[] { - var toppings = new Topping[] + new Topping() { - new Topping() - { Name = "Extra cheese", Price = 2.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "American bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "British bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Canadian bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Tea and crumpets", Price = 5.00m - }, - new Topping() - { + }, + new Topping() + { Name = "Fresh-baked scones", Price = 4.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Bell peppers", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Onions", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Mushrooms", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Pepperoni", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Duck sausage", Price = 3.20m, - }, - new Topping() - { + }, + new Topping() + { Name = "Venison meatballs", Price = 2.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Served on a silver platter", Price = 250.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Lobster on top", Price = 64.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Sturgeon caviar", Price = 101.75m, - }, - new Topping() - { + }, + new Topping() + { Name = "Artichoke hearts", Price = 3.40m, - }, - new Topping() - { + }, + new Topping() + { Name = "Fresh tomatoes", Price = 1.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Basil", Price = 1.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Steak (medium-rare)", Price = 8.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Blazing hot peppers", Price = 4.20m, - }, - new Topping() - { + }, + new Topping() + { Name = "Buffalo chicken", Price = 5.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Blue cheese", Price = 2.50m, - }, - }; + }, + }; - var specials = new PizzaSpecial[] + var specials = new PizzaSpecial[] + { + 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() - { + }, + new PizzaSpecial() + { Id = 2, Name = "The Baconatorizor", Description = "It has EVERY kind of bacon", BasePrice = 11.99m, ImageUrl = "img/pizzas/bacon.jpg", - }, - new PizzaSpecial() - { + }, + 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() - { + }, + 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() - { + }, + 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() - { + }, + new PizzaSpecial() + { Id = 6, Name = "The Brit", Description = "When in London...", BasePrice = 10.25m, ImageUrl = "img/pizzas/brit.jpg", - }, - new PizzaSpecial() - { + }, + 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() - { + }, + new PizzaSpecial() + { Id = 8, Name = "Margherita", Description = "Traditional Italian pizza with tomatoes and basil", BasePrice = 9.99m, ImageUrl = "img/pizzas/margherita.jpg", - }, - }; + }, + }; - db.Toppings.AddRange(toppings); - db.Specials.AddRange(specials); - db.SaveChanges(); - } + db.Toppings.AddRange(toppings); + db.Specials.AddRange(specials); + db.SaveChanges(); } -} +} \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/SpecialsController.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/SpecialsController.cs deleted file mode 100644 index a176844c..00000000 --- a/save-points/01-Components-and-layout/BlazingPizza.Server/SpecialsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("specials")] - [ApiController] - public class SpecialsController : Controller - { - private readonly PizzaStoreContext _db; - - public SpecialsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetSpecials() - { - return (await _db.Specials.ToListAsync()).OrderByDescending(s => s.BasePrice).ToList(); - } - } -} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/Startup.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/Startup.cs deleted file mode 100644 index 7c4656a7..00000000 --- a/save-points/01-Components-and-layout/BlazingPizza.Server/Startup.cs +++ /dev/null @@ -1,71 +0,0 @@ -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace BlazingPizza.Server -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - public void ConfigureServices(IServiceCollection services) - { - services.AddControllersWithViews(); - services.AddRazorPages(); - - - services.AddDbContext(options => - options.UseSqlite("Data Source=pizza.db")); - - services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) - .AddEntityFrameworkStores(); - - services.AddIdentityServer() - .AddApiAuthorization(); - - services.AddAuthentication() - .AddIdentityServerJwt(); - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - app.UseWebAssemblyDebugging(); - } - else - { - app.UseExceptionHandler("/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); - } - - app.UseHttpsRedirection(); - app.UseBlazorFrameworkFiles(); - app.UseStaticFiles(); - - app.UseRouting(); - - app.UseAuthentication(); - app.UseIdentityServer(); - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - endpoints.MapRazorPages(); - endpoints.MapFallbackToFile("index.html"); - }); - } - } -} \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Server/ToppingsController.cs b/save-points/01-Components-and-layout/BlazingPizza.Server/ToppingsController.cs deleted file mode 100644 index 6a677639..00000000 --- a/save-points/01-Components-and-layout/BlazingPizza.Server/ToppingsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("toppings")] - [ApiController] - public class ToppingsController : Controller - { - private readonly PizzaStoreContext _db; - - public ToppingsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetToppings() - { - return await _db.Toppings.OrderBy(t => t.Name).ToListAsync(); - } - } -} diff --git a/save-points/01-Components-and-layout/BlazingPizza.Shared/Address.cs b/save-points/01-Components-and-layout/BlazingPizza.Shared/Address.cs index e5c0ef0d..a671359a 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Shared/Address.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Shared/Address.cs @@ -1,21 +1,24 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class Address { - public class Address - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + [Required, MaxLength(100)] + public string Name { get; set; } - public string Line1 { get; set; } + [Required, MaxLength(100)] + public string Line1 { get; set; } - public string Line2 { get; set; } + [MaxLength(100)] + public string Line2 { get; set; } - public string City { get; set; } + [Required, MaxLength(50)] + public string City { get; set; } - public string Region { get; set; } + [Required, MaxLength(20)] + public string Region { get; set; } - public string PostalCode { get; set; } - } + [Required, MaxLength(20)] + public string PostalCode { get; set; } } diff --git a/save-points/01-Components-and-layout/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/save-points/01-Components-and-layout/BlazingPizza.Shared/BlazingPizza.Shared.csproj index 911c57c5..fb17e53b 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/save-points/01-Components-and-layout/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -1,10 +1,15 @@  - net5.0 + $(TargetFrameworkVersion) BlazingPizza + true + + + + diff --git a/save-points/01-Components-and-layout/BlazingPizza.Shared/LatLong.cs b/save-points/01-Components-and-layout/BlazingPizza.Shared/LatLong.cs index 9b8c3811..a65971f8 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Shared/LatLong.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Shared/LatLong.cs @@ -1,27 +1,26 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class LatLong { - public class LatLong + public LatLong() { - public LatLong() - { - } + } - public LatLong(double latitude, double longitude) : this() - { - Latitude = latitude; - Longitude = longitude; - } + public LatLong(double latitude, double longitude) : this() + { + Latitude = latitude; + Longitude = longitude; + } - public double Latitude { get; set; } + public double Latitude { get; set; } - public double Longitude { get; set; } + public double Longitude { get; set; } - public static LatLong Interpolate(LatLong start, LatLong end, double proportion) - { - // The Earth is flat, right? So no need for spherical interpolation. - return new LatLong( + public static LatLong Interpolate(LatLong start, LatLong end, double proportion) + { + // The Earth is flat, right? So no need for spherical interpolation. + return new LatLong( start.Latitude + (end.Latitude - start.Latitude) * proportion, start.Longitude + (end.Longitude - start.Longitude) * proportion); - } } -} +} \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Shared/NotificationSubscription.cs b/save-points/01-Components-and-layout/BlazingPizza.Shared/NotificationSubscription.cs index 04259c2f..5c99e3f4 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Shared/NotificationSubscription.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Shared/NotificationSubscription.cs @@ -1,17 +1,14 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class NotificationSubscription { - public class NotificationSubscription - { - public int NotificationSubscriptionId { get; set; } + public int NotificationSubscriptionId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public string Url { get; set; } + public string Url { get; set; } - public string P256dh { get; set; } + public string P256dh { get; set; } - public string Auth { get; set; } - } + public string Auth { get; set; } } diff --git a/save-points/01-Components-and-layout/BlazingPizza.Shared/Order.cs b/save-points/01-Components-and-layout/BlazingPizza.Shared/Order.cs index fb003bd6..b47efad0 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Shared/Order.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Shared/Order.cs @@ -1,25 +1,32 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +public class Order { - public class Order - { - public int OrderId { get; set; } + public int OrderId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public DateTime CreatedTime { get; set; } + public DateTime CreatedTime { get; set; } - public Address DeliveryAddress { get; set; } = new Address(); + public Address DeliveryAddress { get; set; } = new Address(); - public LatLong DeliveryLocation { get; set; } + public LatLong DeliveryLocation { get; set; } - public List Pizzas { get; set; } = new List(); + public List Pizzas { get; set; } = new List(); - public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); + public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); - public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); - } + public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Default, PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] +[JsonSerializable(typeof(Order))] +[JsonSerializable(typeof(OrderWithStatus))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Pizza))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Topping))] +public partial class OrderContext : JsonSerializerContext { } \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Shared/OrderWithStatus.cs b/save-points/01-Components-and-layout/BlazingPizza.Shared/OrderWithStatus.cs index 021de78c..fbfac7af 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Shared/OrderWithStatus.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Shared/OrderWithStatus.cs @@ -1,79 +1,78 @@ -using BlazingPizza.ComponentsLibrary.Map; -using System; -using System.Collections.Generic; +using System.Text.Json.Serialization; +using BlazingPizza.ComponentsLibrary.Map; -namespace BlazingPizza -{ - 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 Order Order { get; set; } +namespace BlazingPizza; - public string StatusText { get; set; } +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 bool IsDelivered => StatusText == "Delivered"; + public Order Order { get; set; } - public List MapMarkers { get; set; } + public string StatusText { 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 bool IsDelivered => StatusText == "Delivered"; - 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"; + public List MapMarkers { get; set; } - 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), - }; - } + 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); - return new OrderWithStatus - { - Order = order, - StatusText = statusText, - MapMarkers = mapMarkers, - }; + 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"; - private static LatLong ComputeStartPosition(Order order) + 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 { - // 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); + statusText = "Delivered"; + mapMarkers = new List + { + ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), + }; } - static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) - => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; + 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); + } + + static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) + => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; +} \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Shared/Pizza.cs b/save-points/01-Components-and-layout/BlazingPizza.Shared/Pizza.cs index ec1108a9..2a7a1c29 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Shared/Pizza.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Shared/Pizza.cs @@ -1,42 +1,44 @@ -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// /// Represents a customized pizza as part of an order +/// +public class Pizza { - /// - /// Represents a customized pizza as part of an order - /// - public class Pizza - { - public const int DefaultSize = 12; - public const int MinimumSize = 9; - public const int MaximumSize = 17; + public const int DefaultSize = 12; + public const int MinimumSize = 9; + public const int MaximumSize = 17; - public int Id { get; set; } + public int Id { get; set; } - public int OrderId { get; set; } + public int OrderId { get; set; } - public PizzaSpecial Special { get; set; } + public PizzaSpecial Special { get; set; } - public int SpecialId { get; set; } + public int SpecialId { get; set; } - public int Size { get; set; } + public int Size { get; set; } - public List Toppings { get; set; } + public List Toppings { get; set; } - public decimal GetBasePrice() - { - return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; - } + public decimal GetBasePrice() + { + return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; + } - public decimal GetTotalPrice() - { - return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); - } + public decimal GetTotalPrice() + { + return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); + } - public string GetFormattedTotalPrice() - { - return GetTotalPrice().ToString("0.00"); - } + public string GetFormattedTotalPrice() + { + return GetTotalPrice().ToString("0.00"); } } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Serialization)] +[JsonSerializable(typeof(Pizza))] +public partial class PizzaContext : JsonSerializerContext { } \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Shared/PizzaSpecial.cs b/save-points/01-Components-and-layout/BlazingPizza.Shared/PizzaSpecial.cs index 2f2b3383..1fd9006a 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Shared/PizzaSpecial.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Shared/PizzaSpecial.cs @@ -1,20 +1,19 @@ -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// Represents a pre-configured template for a pizza a user can order +/// +public class PizzaSpecial { - /// - /// Represents a pre-configured template for a pizza a user can order - /// - public class PizzaSpecial - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal BasePrice { get; set; } + public decimal BasePrice { get; set; } - public string Description { get; set; } + public string Description { get; set; } - public string ImageUrl { get; set; } + public string ImageUrl { get; set; } - public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); - } -} + public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); +} \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Shared/PizzaTopping.cs b/save-points/01-Components-and-layout/BlazingPizza.Shared/PizzaTopping.cs index f5a6c1ac..1c062732 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Shared/PizzaTopping.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Shared/PizzaTopping.cs @@ -1,11 +1,11 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class PizzaTopping { - public class PizzaTopping - { - public Topping Topping { get; set; } - - public int ToppingId { get; set; } - - public int PizzaId { get; set; } - } -} + public Topping Topping { get; set; } + + public int ToppingId { get; set; } + + public int PizzaId { get; set; } + +} \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Shared/Topping.cs b/save-points/01-Components-and-layout/BlazingPizza.Shared/Topping.cs index 61bdeb92..4eb67ae9 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Shared/Topping.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Shared/Topping.cs @@ -1,13 +1,13 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class Topping { - public class Topping - { - public int Id { get; set; } + public int Id { get; set; } + + public string Name { get; set; } - public string Name { get; set; } + public decimal Price { get; set; } - public decimal Price { get; set; } + public string GetFormattedPrice() => Price.ToString("0.00"); - public string GetFormattedPrice() => Price.ToString("0.00"); - } -} +} \ No newline at end of file diff --git a/save-points/01-Components-and-layout/BlazingPizza.Shared/UserInfo.cs b/save-points/01-Components-and-layout/BlazingPizza.Shared/UserInfo.cs index 4996ef80..babb4315 100644 --- a/save-points/01-Components-and-layout/BlazingPizza.Shared/UserInfo.cs +++ b/save-points/01-Components-and-layout/BlazingPizza.Shared/UserInfo.cs @@ -1,9 +1,9 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class UserInfo { - public class UserInfo - { - public bool IsAuthenticated { get; set; } + public bool IsAuthenticated { get; set; } + + public string Name { get; set; } - public string Name { get; set; } - } -} +} \ No newline at end of file diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Client/BlazingPizza.Client.csproj b/save-points/02-customize-a-pizza/BlazingPizza.Client/BlazingPizza.Client.csproj index c50ce7e0..8f007b31 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/save-points/02-customize-a-pizza/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -1,7 +1,8 @@  - net5.0 + $(TargetFrameworkVersion) + true diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Client/Program.cs b/save-points/02-customize-a-pizza/BlazingPizza.Client/Program.cs index 48147d6f..c5023d76 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Client/Program.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Client/Program.cs @@ -1,21 +1,11 @@ -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.Web; +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.RootComponents.Add("head::after"); - builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); +builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); - await builder.Build().RunAsync(); - } - } -} +await builder.Build().RunAsync(); diff --git a/save-points/02-customize-a-pizza/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/save-points/02-customize-a-pizza/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 5f51ee3c..cb996b1b 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/save-points/02-customize-a-pizza/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -1,7 +1,8 @@  - net5.0 + $(TargetFrameworkVersion) + true diff --git a/save-points/02-customize-a-pizza/BlazingPizza.ComponentsLibrary/LocalStorage.cs b/save-points/02-customize-a-pizza/BlazingPizza.ComponentsLibrary/LocalStorage.cs index f36b098e..8995307f 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.ComponentsLibrary/LocalStorage.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.ComponentsLibrary/LocalStorage.cs @@ -1,17 +1,17 @@ using Microsoft.JSInterop; -using System.Threading.Tasks; -namespace BlazingPizza.ComponentsLibrary +namespace BlazingPizza.ComponentsLibrary; + +public static class LocalStorage { - public static class LocalStorage - { - public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) + + public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); - public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object 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) + public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key) => jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key); - } -} + +} \ No newline at end of file diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/BlazingPizza.Server.csproj b/save-points/02-customize-a-pizza/BlazingPizza.Server/BlazingPizza.Server.csproj index fd7e3c51..227890e1 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -1,7 +1,8 @@  - net5.0 + $(TargetFrameworkVersion) + true diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/AddressEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/AddressEntityType.cs new file mode 100644 index 00000000..82db81b6 --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/AddressEntityType.cs @@ -0,0 +1,92 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class AddressEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Address", + typeof(Address), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Address).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var city = runtimeEntityType.AddProperty( + "City", + typeof(string), + propertyInfo: typeof(Address).GetProperty("City", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var line1 = runtimeEntityType.AddProperty( + "Line1", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line1", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var line2 = runtimeEntityType.AddProperty( + "Line2", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line2", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var postalCode = runtimeEntityType.AddProperty( + "PostalCode", + typeof(string), + propertyInfo: typeof(Address).GetProperty("PostalCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var region = runtimeEntityType.AddProperty( + "Region", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Region", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Address"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs new file mode 100644 index 00000000..1dd4563b --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs @@ -0,0 +1,114 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class DeviceFlowCodesEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.DeviceFlowCodes", + typeof(DeviceFlowCodes), + baseEntityType); + + var userCode = runtimeEntityType.AddProperty( + "UserCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("UserCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var deviceCode = runtimeEntityType.AddProperty( + "DeviceCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("DeviceCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var key = runtimeEntityType.AddKey( + new[] { userCode }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deviceCode }, + unique: true); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "DeviceCodes"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs new file mode 100644 index 00000000..8946b261 --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRoleClaim", + typeof(IdentityRoleClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoleClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityRoleEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityRoleEntityType.cs new file mode 100644 index 00000000..2f1fec2b --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityRoleEntityType.cs @@ -0,0 +1,78 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRole", + typeof(IdentityRole), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedName = runtimeEntityType.AddProperty( + "NormalizedName", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("NormalizedName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedName }, + unique: true); + index.AddAnnotation("Relational:Name", "RoleNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs new file mode 100644 index 00000000..55418a1e --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserClaim", + typeof(IdentityUserClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityUserClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs new file mode 100644 index 00000000..3ca029bd --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserLoginstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserLogin", + typeof(IdentityUserLogin), + baseEntityType); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerKey = runtimeEntityType.AddProperty( + "ProviderKey", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderKey", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerDisplayName = runtimeEntityType.AddProperty( + "ProviderDisplayName", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderDisplayName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { loginProvider, providerKey }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserLogins"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs new file mode 100644 index 00000000..70078d7a --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs @@ -0,0 +1,82 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserRolestringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserRole", + typeof(IdentityUserRole), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { userId, roleId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs new file mode 100644 index 00000000..93ba6d31 --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs @@ -0,0 +1,84 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserTokenstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserToken", + typeof(IdentityUserToken), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var value = runtimeEntityType.AddProperty( + "Value", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Value", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { userId, loginProvider, name }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserTokens"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/KeyEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/KeyEntityType.cs new file mode 100644 index 00000000..f6c6b4c7 --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/KeyEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class KeyEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.Key", + typeof(Key), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var algorithm = runtimeEntityType.AddProperty( + "Algorithm", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Algorithm", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var created = runtimeEntityType.AddProperty( + "Created", + typeof(DateTime), + propertyInfo: typeof(Key).GetProperty("Created", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var dataProtected = runtimeEntityType.AddProperty( + "DataProtected", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("DataProtected", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var isX509Certificate = runtimeEntityType.AddProperty( + "IsX509Certificate", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("IsX509Certificate", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var use = runtimeEntityType.AddProperty( + "Use", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Use", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var version = runtimeEntityType.AddProperty( + "Version", + typeof(int), + propertyInfo: typeof(Key).GetProperty("Version", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { use }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Keys"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/LatLongEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/LatLongEntityType.cs new file mode 100644 index 00000000..3fd254bd --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/LatLongEntityType.cs @@ -0,0 +1,80 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class LatLongEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.LatLong", + typeof(LatLong), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var latitude = runtimeEntityType.AddProperty( + "Latitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Latitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var longitude = runtimeEntityType.AddProperty( + "Longitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Longitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + unique: true, + required: true, + ownership: true); + + var deliveryLocation = principalEntityType.AddNavigation("DeliveryLocation", + runtimeForeignKey, + onDependent: false, + typeof(LatLong), + propertyInfo: typeof(Order).GetProperty("DeliveryLocation", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + eagerLoaded: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs new file mode 100644 index 00000000..db236e4c --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs @@ -0,0 +1,77 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class NotificationSubscriptionEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.NotificationSubscription", + typeof(NotificationSubscription), + baseEntityType); + + var notificationSubscriptionId = runtimeEntityType.AddProperty( + "NotificationSubscriptionId", + typeof(int), + propertyInfo: typeof(NotificationSubscription).GetProperty("NotificationSubscriptionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var auth = runtimeEntityType.AddProperty( + "Auth", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Auth", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var p256dh = runtimeEntityType.AddProperty( + "P256dh", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("P256dh", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var url = runtimeEntityType.AddProperty( + "Url", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Url", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { notificationSubscriptionId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "NotificationSubscriptions"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/OrderEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/OrderEntityType.cs new file mode 100644 index 00000000..9d9ec6fd --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/OrderEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class OrderEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Order", + typeof(Order), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Order).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var createdTime = runtimeEntityType.AddProperty( + "CreatedTime", + typeof(DateTime), + propertyInfo: typeof(Order).GetProperty("CreatedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var deliveryAddressId = runtimeEntityType.AddProperty( + "DeliveryAddressId", + typeof(int?), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(Order).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deliveryAddressId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("DeliveryAddressId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType); + + var deliveryAddress = declaringEntityType.AddNavigation("DeliveryAddress", + runtimeForeignKey, + onDependent: true, + typeof(Address), + propertyInfo: typeof(Order).GetProperty("DeliveryAddress", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PersistedGrantEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PersistedGrantEntityType.cs new file mode 100644 index 00000000..842d53a5 --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PersistedGrantEntityType.cs @@ -0,0 +1,127 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PersistedGrantEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.PersistedGrant", + typeof(PersistedGrant), + baseEntityType); + + var key = runtimeEntityType.AddProperty( + "Key", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Key", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var consumedTime = runtimeEntityType.AddProperty( + "ConsumedTime", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("ConsumedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(PersistedGrant).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var type = runtimeEntityType.AddProperty( + "Type", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Type", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var key0 = runtimeEntityType.AddKey( + new[] { key }); + runtimeEntityType.SetPrimaryKey(key0); + + var index = runtimeEntityType.AddIndex( + new[] { consumedTime }); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + var index1 = runtimeEntityType.AddIndex( + new[] { subjectId, clientId, type }); + + var index2 = runtimeEntityType.AddIndex( + new[] { subjectId, sessionId, type }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PersistedGrants"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaEntityType.cs new file mode 100644 index 00000000..3a124e63 --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaEntityType.cs @@ -0,0 +1,111 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Pizza", + typeof(Pizza), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var size = runtimeEntityType.AddProperty( + "Size", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Size", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var specialId = runtimeEntityType.AddProperty( + "SpecialId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("SpecialId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { orderId }); + + var index0 = runtimeEntityType.AddIndex( + new[] { specialId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var pizzas = principalEntityType.AddNavigation("Pizzas", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Order).GetProperty("Pizzas", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("SpecialId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var special = declaringEntityType.AddNavigation("Special", + runtimeForeignKey, + onDependent: true, + typeof(PizzaSpecial), + propertyInfo: typeof(Pizza).GetProperty("Special", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Pizzas"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs new file mode 100644 index 00000000..e86b0f50 --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs @@ -0,0 +1,76 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaSpecialEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaSpecial", + typeof(PizzaSpecial), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(PizzaSpecial).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var basePrice = runtimeEntityType.AddProperty( + "BasePrice", + typeof(decimal), + propertyInfo: typeof(PizzaSpecial).GetProperty("BasePrice", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var imageUrl = runtimeEntityType.AddProperty( + "ImageUrl", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("ImageUrl", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Specials"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaStoreContextModel.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaStoreContextModel.cs new file mode 100644 index 00000000..8b516a68 --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaStoreContextModel.cs @@ -0,0 +1,28 @@ +// +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + [DbContext(typeof(PizzaStoreContext))] + public partial class PizzaStoreContextModel : RuntimeModel + { + static PizzaStoreContextModel() + { + var model = new PizzaStoreContextModel(); + model.Initialize(); + model.Customize(); + _instance = model; + } + + private static PizzaStoreContextModel _instance; + public static IModel Instance => _instance; + + partial void Initialize(); + + partial void Customize(); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs new file mode 100644 index 00000000..d46f50f4 --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs @@ -0,0 +1,69 @@ +// +using System; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + public partial class PizzaStoreContextModel + { + partial void Initialize() + { + var address = AddressEntityType.Create(this); + var latLong = LatLongEntityType.Create(this); + var notificationSubscription = NotificationSubscriptionEntityType.Create(this); + var order = OrderEntityType.Create(this); + var pizza = PizzaEntityType.Create(this); + var pizzaSpecial = PizzaSpecialEntityType.Create(this); + var pizzaTopping = PizzaToppingEntityType.Create(this); + var pizzaStoreUser = PizzaStoreUserEntityType.Create(this); + var topping = ToppingEntityType.Create(this); + var deviceFlowCodes = DeviceFlowCodesEntityType.Create(this); + var key = KeyEntityType.Create(this); + var persistedGrant = PersistedGrantEntityType.Create(this); + var identityRole = IdentityRoleEntityType.Create(this); + var identityRoleClaimstring = IdentityRoleClaimstringEntityType.Create(this); + var identityUserClaimstring = IdentityUserClaimstringEntityType.Create(this); + var identityUserLoginstring = IdentityUserLoginstringEntityType.Create(this); + var identityUserRolestring = IdentityUserRolestringEntityType.Create(this); + var identityUserTokenstring = IdentityUserTokenstringEntityType.Create(this); + + LatLongEntityType.CreateForeignKey1(latLong, order); + OrderEntityType.CreateForeignKey1(order, address); + PizzaEntityType.CreateForeignKey1(pizza, order); + PizzaEntityType.CreateForeignKey2(pizza, pizzaSpecial); + PizzaToppingEntityType.CreateForeignKey1(pizzaTopping, pizza); + PizzaToppingEntityType.CreateForeignKey2(pizzaTopping, topping); + IdentityRoleClaimstringEntityType.CreateForeignKey1(identityRoleClaimstring, identityRole); + IdentityUserClaimstringEntityType.CreateForeignKey1(identityUserClaimstring, pizzaStoreUser); + IdentityUserLoginstringEntityType.CreateForeignKey1(identityUserLoginstring, pizzaStoreUser); + IdentityUserRolestringEntityType.CreateForeignKey1(identityUserRolestring, identityRole); + IdentityUserRolestringEntityType.CreateForeignKey2(identityUserRolestring, pizzaStoreUser); + IdentityUserTokenstringEntityType.CreateForeignKey1(identityUserTokenstring, pizzaStoreUser); + + AddressEntityType.CreateAnnotations(address); + LatLongEntityType.CreateAnnotations(latLong); + NotificationSubscriptionEntityType.CreateAnnotations(notificationSubscription); + OrderEntityType.CreateAnnotations(order); + PizzaEntityType.CreateAnnotations(pizza); + PizzaSpecialEntityType.CreateAnnotations(pizzaSpecial); + PizzaToppingEntityType.CreateAnnotations(pizzaTopping); + PizzaStoreUserEntityType.CreateAnnotations(pizzaStoreUser); + ToppingEntityType.CreateAnnotations(topping); + DeviceFlowCodesEntityType.CreateAnnotations(deviceFlowCodes); + KeyEntityType.CreateAnnotations(key); + PersistedGrantEntityType.CreateAnnotations(persistedGrant); + IdentityRoleEntityType.CreateAnnotations(identityRole); + IdentityRoleClaimstringEntityType.CreateAnnotations(identityRoleClaimstring); + IdentityUserClaimstringEntityType.CreateAnnotations(identityUserClaimstring); + IdentityUserLoginstringEntityType.CreateAnnotations(identityUserLoginstring); + IdentityUserRolestringEntityType.CreateAnnotations(identityUserRolestring); + IdentityUserTokenstringEntityType.CreateAnnotations(identityUserTokenstring); + + AddAnnotation("ProductVersion", "6.0.0"); + } + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs new file mode 100644 index 00000000..18b2d96d --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs @@ -0,0 +1,156 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaStoreUserEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Server.PizzaStoreUser", + typeof(PizzaStoreUser), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var accessFailedCount = runtimeEntityType.AddProperty( + "AccessFailedCount", + typeof(int), + propertyInfo: typeof(IdentityUser).GetProperty("AccessFailedCount", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var email = runtimeEntityType.AddProperty( + "Email", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Email", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var emailConfirmed = runtimeEntityType.AddProperty( + "EmailConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("EmailConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnabled = runtimeEntityType.AddProperty( + "LockoutEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnd = runtimeEntityType.AddProperty( + "LockoutEnd", + typeof(DateTimeOffset?), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnd", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var normalizedEmail = runtimeEntityType.AddProperty( + "NormalizedEmail", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedEmail", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedUserName = runtimeEntityType.AddProperty( + "NormalizedUserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedUserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var passwordHash = runtimeEntityType.AddProperty( + "PasswordHash", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PasswordHash", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumber = runtimeEntityType.AddProperty( + "PhoneNumber", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumber", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumberConfirmed = runtimeEntityType.AddProperty( + "PhoneNumberConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumberConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var securityStamp = runtimeEntityType.AddProperty( + "SecurityStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("SecurityStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var twoFactorEnabled = runtimeEntityType.AddProperty( + "TwoFactorEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("TwoFactorEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var userName = runtimeEntityType.AddProperty( + "UserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("UserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedEmail }); + index.AddAnnotation("Relational:Name", "EmailIndex"); + + var index0 = runtimeEntityType.AddIndex( + new[] { normalizedUserName }, + unique: true); + index0.AddAnnotation("Relational:Name", "UserNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUsers"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaToppingEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaToppingEntityType.cs new file mode 100644 index 00000000..b97d2a24 --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/PizzaToppingEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaTopping", + typeof(PizzaTopping), + baseEntityType); + + var pizzaId = runtimeEntityType.AddProperty( + "PizzaId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("PizzaId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var toppingId = runtimeEntityType.AddProperty( + "ToppingId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("ToppingId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { pizzaId, toppingId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { toppingId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("PizzaId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var toppings = principalEntityType.AddNavigation("Toppings", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Pizza).GetProperty("Toppings", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("ToppingId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var topping = declaringEntityType.AddNavigation("Topping", + runtimeForeignKey, + onDependent: true, + typeof(Topping), + propertyInfo: typeof(PizzaTopping).GetProperty("Topping", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PizzaTopping"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/ToppingEntityType.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/ToppingEntityType.cs new file mode 100644 index 00000000..9295f9bf --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Models/ToppingEntityType.cs @@ -0,0 +1,62 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class ToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Topping", + typeof(Topping), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Topping).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Topping).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var price = runtimeEntityType.AddProperty( + "Price", + typeof(decimal), + propertyInfo: typeof(Topping).GetProperty("Price", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Toppings"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/NotificationsController.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/NotificationsController.cs deleted file mode 100644 index bb3b96ff..00000000 --- a/save-points/02-customize-a-pizza/BlazingPizza.Server/NotificationsController.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("notifications")] - [ApiController] - [Authorize] - public class NotificationsController : Controller - { - private readonly PizzaStoreContext _db; - - public NotificationsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpPut("subscribe")] - public async Task Subscribe(NotificationSubscription subscription) - { - // We're storing at most one subscription per user, so delete old ones. - // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. - var userId = GetUserId(); - var oldSubscriptions = _db.NotificationSubscriptions.Where(e => e.UserId == userId); - _db.NotificationSubscriptions.RemoveRange(oldSubscriptions); - - // Store new subscription - subscription.UserId = userId; - _db.NotificationSubscriptions.Attach(subscription); - - await _db.SaveChangesAsync(); - return subscription; - } - - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } - } -} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/OidcConfigurationController.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/OidcConfigurationController.cs index c074debf..3d385048 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Server/OidcConfigurationController.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/OidcConfigurationController.cs @@ -1,26 +1,21 @@ using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class OidcConfigurationController : Controller { - public class OidcConfigurationController : Controller + public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) { - public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) - { - ClientRequestParametersProvider = clientRequestParametersProvider; - } + ClientRequestParametersProvider = clientRequestParametersProvider; + } - public IClientRequestParametersProvider ClientRequestParametersProvider { get; } + public IClientRequestParametersProvider ClientRequestParametersProvider { get; } - [HttpGet("_configuration/{clientId}")] - public IActionResult GetClientRequestParameters([FromRoute]string clientId) - { - var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); - return Ok(parameters); - } + [HttpGet("_configuration/{clientId}")] + public IActionResult GetClientRequestParameters([FromRoute] string clientId) + { + var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); + return Ok(parameters); } -} +} \ No newline at end of file diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/OrdersController.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/OrdersController.cs index 2b8bc99b..37e37cc5 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Server/OrdersController.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/OrdersController.cs @@ -1,29 +1,25 @@ -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; + private readonly PizzaStoreContext _db; - public OrdersController(PizzaStoreContext db) - { - _db = db; - } + public OrdersController(PizzaStoreContext db) + { + _db = db; + } - [HttpGet] - public async Task>> GetOrders() - { - var orders = await _db.Orders + [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) @@ -31,13 +27,13 @@ public async Task>> GetOrders() .OrderByDescending(o => o.CreatedTime) .ToListAsync(); - return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); - } + return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); + } - [HttpGet("{orderId}")] - public async Task> GetOrderWithStatus(int orderId) - { - var order = await _db.Orders + [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) @@ -45,70 +41,69 @@ public async Task> GetOrderWithStatus(int orderId) .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) .SingleOrDefaultAsync(); - if (order == null) - { - return NotFound(); - } - - return OrderWithStatus.FromOrder(order); + if (order == null) + { + return NotFound(); } - [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; - } - } + return OrderWithStatus.FromOrder(order); + } - _db.Orders.Attach(order); - await _db.SaveChangesAsync(); + [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; - // In the background, send push notifications if possible - var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); - if (subscription != null) + foreach (var topping in pizza.Toppings) { - _ = TrackAndSendNotificationsAsync(order, subscription); + topping.ToppingId = topping.Topping.Id; + topping.Topping = null; } - - return order.OrderId; } - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } + _db.Orders.Attach(order); + await _db.SaveChangesAsync(); - private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription subscription) + // In the background, send push notifications if possible + var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); + if (subscription != null) { - // 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!"); + _ = TrackAndSendNotificationsAsync(order, subscription); } - private static Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) - { - // This will be implemented later - return Task.CompletedTask; - } + return order.OrderId; + } + + private string GetUserId() + { + return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); + } + + private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription subscription) + { + // In a realistic case, some other backend process would track + // order delivery progress and send us notifications when it + // changes. Since we don't have any such process here, fake it. + await Task.Delay(OrderWithStatus.PreparationDuration); + await SendNotificationAsync(order, subscription, "Your order has been dispatched!"); + + await Task.Delay(OrderWithStatus.DeliveryDuration); + await SendNotificationAsync(order, subscription, "Your order is now delivered. Enjoy!"); + } + + private static Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) + { + // This will be implemented later + return Task.CompletedTask; } -} +} \ No newline at end of file diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/PizzaApiExtensions.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/PizzaApiExtensions.cs new file mode 100644 index 00000000..524ca759 --- /dev/null +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/PizzaApiExtensions.cs @@ -0,0 +1,57 @@ +using System.Security.Claims; +using Microsoft.AspNetCore.Authorization; +using Microsoft.EntityFrameworkCore; + +namespace BlazingPizza.Server; + +public static class PizzaApiExtensions +{ + + public static WebApplication MapPizzaApi(this WebApplication app) + { + + // Subscribe to notifications + app.MapPut("/notifications/subscribe", [Authorize] async ( + HttpContext context, + PizzaStoreContext db, + NotificationSubscription subscription) => { + + // We're storing at most one subscription per user, so delete old ones. + // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. + var userId = GetUserId(context); + var oldSubscriptions = db.NotificationSubscriptions.Where(e => e.UserId == userId); + db.NotificationSubscriptions.RemoveRange(oldSubscriptions); + + // Store new subscription + subscription.UserId = userId; + db.NotificationSubscriptions.Attach(subscription); + + await db.SaveChangesAsync(); + return Results.Ok(subscription); + + }); + + // Specials + app.MapGet("/specials", async (PizzaStoreContext db) => { + + var specials = await db.Specials.ToListAsync(); + return Results.Ok(specials); + + }); + + // Toppings + app.MapGet("/toppings", async (PizzaStoreContext db) => { + var toppings = await db.Toppings.OrderBy(t => t.Name).ToListAsync(); + return Results.Ok(toppings); + }); + + return app; + + } + + private static string GetUserId(HttpContext context) + { + return context.User.FindFirstValue(ClaimTypes.NameIdentifier); + } + +} \ No newline at end of file diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/PizzaStoreContext.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/PizzaStoreContext.cs index f79c1c66..50ac87e4 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Server/PizzaStoreContext.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/PizzaStoreContext.cs @@ -1,39 +1,38 @@ -using IdentityServer4.EntityFramework.Options; +using Duende.IdentityServer.EntityFramework.Options; using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class PizzaStoreContext : ApiAuthorizationDbContext { - public class PizzaStoreContext : ApiAuthorizationDbContext - { - public PizzaStoreContext( + 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/02-customize-a-pizza/BlazingPizza.Server/PizzaStoreUser.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/PizzaStoreUser.cs index 171ce83d..d446a679 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Server/PizzaStoreUser.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/PizzaStoreUser.cs @@ -1,8 +1,6 @@ using Microsoft.AspNetCore.Identity; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; +public class PizzaStoreUser : IdentityUser { - public class PizzaStoreUser : IdentityUser - { - } } \ No newline at end of file diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/PizzasController.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/PizzasController.cs deleted file mode 100644 index c082552c..00000000 --- a/save-points/02-customize-a-pizza/BlazingPizza.Server/PizzasController.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("pizzas")] - [ApiController] - public class PizzasController : Controller - { - private readonly PizzaStoreContext _db; - - public PizzasController(PizzaStoreContext db) - { - _db = db; - } - } -} diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Program.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Program.cs index 40a47641..b83debb4 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Server/Program.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Program.cs @@ -1,33 +1,67 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; +using BlazingPizza.Server; +using Microsoft.AspNetCore.Authentication; +using Microsoft.EntityFrameworkCore; -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()) { - public class Program + var db = scope.ServiceProvider.GetRequiredService(); + if (db.Database.EnsureCreated()) { - 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(); - }); + SeedData.Initialize(db); } } + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + 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.MapPizzaApi(); + +app.MapRazorPages(); +app.MapControllers(); +app.MapFallbackToFile("index.html"); + +app.Run(); \ No newline at end of file diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/SeedData.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/SeedData.cs index 7c86a5b2..f02e2b77 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Server/SeedData.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/SeedData.cs @@ -1,193 +1,192 @@ -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public static class SeedData { - public static class SeedData + public static void Initialize(PizzaStoreContext db) { - public static void Initialize(PizzaStoreContext db) + var toppings = new Topping[] { - var toppings = new Topping[] + new Topping() { - new Topping() - { Name = "Extra cheese", Price = 2.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "American bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "British bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Canadian bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Tea and crumpets", Price = 5.00m - }, - new Topping() - { + }, + new Topping() + { Name = "Fresh-baked scones", Price = 4.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Bell peppers", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Onions", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Mushrooms", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Pepperoni", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Duck sausage", Price = 3.20m, - }, - new Topping() - { + }, + new Topping() + { Name = "Venison meatballs", Price = 2.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Served on a silver platter", Price = 250.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Lobster on top", Price = 64.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Sturgeon caviar", Price = 101.75m, - }, - new Topping() - { + }, + new Topping() + { Name = "Artichoke hearts", Price = 3.40m, - }, - new Topping() - { + }, + new Topping() + { Name = "Fresh tomatoes", Price = 1.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Basil", Price = 1.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Steak (medium-rare)", Price = 8.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Blazing hot peppers", Price = 4.20m, - }, - new Topping() - { + }, + new Topping() + { Name = "Buffalo chicken", Price = 5.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Blue cheese", Price = 2.50m, - }, - }; + }, + }; - var specials = new PizzaSpecial[] + var specials = new PizzaSpecial[] + { + 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() - { + }, + new PizzaSpecial() + { Id = 2, Name = "The Baconatorizor", Description = "It has EVERY kind of bacon", BasePrice = 11.99m, ImageUrl = "img/pizzas/bacon.jpg", - }, - new PizzaSpecial() - { + }, + 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() - { + }, + 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() - { + }, + 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() - { + }, + new PizzaSpecial() + { Id = 6, Name = "The Brit", Description = "When in London...", BasePrice = 10.25m, ImageUrl = "img/pizzas/brit.jpg", - }, - new PizzaSpecial() - { + }, + 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() - { + }, + new PizzaSpecial() + { Id = 8, Name = "Margherita", Description = "Traditional Italian pizza with tomatoes and basil", BasePrice = 9.99m, ImageUrl = "img/pizzas/margherita.jpg", - }, - }; + }, + }; - db.Toppings.AddRange(toppings); - db.Specials.AddRange(specials); - db.SaveChanges(); - } + db.Toppings.AddRange(toppings); + db.Specials.AddRange(specials); + db.SaveChanges(); } -} +} \ No newline at end of file diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Server/Startup.cs b/save-points/02-customize-a-pizza/BlazingPizza.Server/Startup.cs index ed3fca06..4a35b695 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Server/Startup.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Server/Startup.cs @@ -22,7 +22,7 @@ public void ConfigureServices(IServiceCollection services) services.AddControllersWithViews(); services.AddRazorPages(); - services.AddDbContext(options => + services.AddDbContext(options => options.UseSqlite("Data Source=pizza.db")); services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) @@ -59,8 +59,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) app.UseIdentityServer(); app.UseAuthorization(); - app.UseEndpoints(endpoints => - { + app.UseEndpoints(endpoints => { endpoints.MapControllers(); endpoints.MapRazorPages(); endpoints.MapFallbackToFile("index.html"); diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Shared/Address.cs b/save-points/02-customize-a-pizza/BlazingPizza.Shared/Address.cs index e5c0ef0d..309438b7 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Shared/Address.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Shared/Address.cs @@ -1,21 +1,26 @@ using System.ComponentModel.DataAnnotations; -namespace BlazingPizza +namespace BlazingPizza; + +public class Address { - public class Address - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + [Required, MaxLength(100)] + public string Name { get; set; } - public string Line1 { get; set; } + [Required, MaxLength(100)] + public string Line1 { get; set; } - public string Line2 { get; set; } + [MaxLength(100)] + public string Line2 { get; set; } - public string City { get; set; } + [Required, MaxLength(50)] + public string City { get; set; } - public string Region { get; set; } + [Required, MaxLength(20)] + public string Region { get; set; } - public string PostalCode { get; set; } - } + [Required, MaxLength(20)] + public string PostalCode { get; set; } } diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/save-points/02-customize-a-pizza/BlazingPizza.Shared/BlazingPizza.Shared.csproj index 911c57c5..075ddd60 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/save-points/02-customize-a-pizza/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -1,8 +1,9 @@  - net5.0 + $(TargetFrameworkVersion) BlazingPizza + true diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Shared/LatLong.cs b/save-points/02-customize-a-pizza/BlazingPizza.Shared/LatLong.cs index 9b8c3811..a65971f8 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Shared/LatLong.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Shared/LatLong.cs @@ -1,27 +1,26 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class LatLong { - public class LatLong + public LatLong() { - public LatLong() - { - } + } - public LatLong(double latitude, double longitude) : this() - { - Latitude = latitude; - Longitude = longitude; - } + public LatLong(double latitude, double longitude) : this() + { + Latitude = latitude; + Longitude = longitude; + } - public double Latitude { get; set; } + public double Latitude { get; set; } - public double Longitude { get; set; } + public double Longitude { get; set; } - public static LatLong Interpolate(LatLong start, LatLong end, double proportion) - { - // The Earth is flat, right? So no need for spherical interpolation. - return new LatLong( + public static LatLong Interpolate(LatLong start, LatLong end, double proportion) + { + // The Earth is flat, right? So no need for spherical interpolation. + return new LatLong( start.Latitude + (end.Latitude - start.Latitude) * proportion, start.Longitude + (end.Longitude - start.Longitude) * proportion); - } } -} +} \ No newline at end of file diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Shared/NotificationSubscription.cs b/save-points/02-customize-a-pizza/BlazingPizza.Shared/NotificationSubscription.cs index 04259c2f..5c99e3f4 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Shared/NotificationSubscription.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Shared/NotificationSubscription.cs @@ -1,17 +1,14 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class NotificationSubscription { - public class NotificationSubscription - { - public int NotificationSubscriptionId { get; set; } + public int NotificationSubscriptionId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public string Url { get; set; } + public string Url { get; set; } - public string P256dh { get; set; } + public string P256dh { get; set; } - public string Auth { get; set; } - } + public string Auth { get; set; } } diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Shared/Order.cs b/save-points/02-customize-a-pizza/BlazingPizza.Shared/Order.cs index fb003bd6..b47efad0 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Shared/Order.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Shared/Order.cs @@ -1,25 +1,32 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +public class Order { - public class Order - { - public int OrderId { get; set; } + public int OrderId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public DateTime CreatedTime { get; set; } + public DateTime CreatedTime { get; set; } - public Address DeliveryAddress { get; set; } = new Address(); + public Address DeliveryAddress { get; set; } = new Address(); - public LatLong DeliveryLocation { get; set; } + public LatLong DeliveryLocation { get; set; } - public List Pizzas { get; set; } = new List(); + public List Pizzas { get; set; } = new List(); - public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); + public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); - public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); - } + public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Default, PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] +[JsonSerializable(typeof(Order))] +[JsonSerializable(typeof(OrderWithStatus))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Pizza))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Topping))] +public partial class OrderContext : JsonSerializerContext { } \ No newline at end of file diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Shared/OrderWithStatus.cs b/save-points/02-customize-a-pizza/BlazingPizza.Shared/OrderWithStatus.cs index 021de78c..fbfac7af 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Shared/OrderWithStatus.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Shared/OrderWithStatus.cs @@ -1,79 +1,78 @@ -using BlazingPizza.ComponentsLibrary.Map; -using System; -using System.Collections.Generic; +using System.Text.Json.Serialization; +using BlazingPizza.ComponentsLibrary.Map; -namespace BlazingPizza -{ - 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 Order Order { get; set; } +namespace BlazingPizza; - public string StatusText { get; set; } +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 bool IsDelivered => StatusText == "Delivered"; + public Order Order { get; set; } - public List MapMarkers { get; set; } + public string StatusText { 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 bool IsDelivered => StatusText == "Delivered"; - 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"; + public List MapMarkers { get; set; } - 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), - }; - } + 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); - return new OrderWithStatus - { - Order = order, - StatusText = statusText, - MapMarkers = mapMarkers, - }; + 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"; - private static LatLong ComputeStartPosition(Order order) + 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 { - // 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); + statusText = "Delivered"; + mapMarkers = new List + { + ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), + }; } - static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) - => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; + 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); + } + + static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) + => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; +} \ No newline at end of file diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Shared/Pizza.cs b/save-points/02-customize-a-pizza/BlazingPizza.Shared/Pizza.cs index ec1108a9..2a7a1c29 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Shared/Pizza.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Shared/Pizza.cs @@ -1,42 +1,44 @@ -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// /// Represents a customized pizza as part of an order +/// +public class Pizza { - /// - /// Represents a customized pizza as part of an order - /// - public class Pizza - { - public const int DefaultSize = 12; - public const int MinimumSize = 9; - public const int MaximumSize = 17; + public const int DefaultSize = 12; + public const int MinimumSize = 9; + public const int MaximumSize = 17; - public int Id { get; set; } + public int Id { get; set; } - public int OrderId { get; set; } + public int OrderId { get; set; } - public PizzaSpecial Special { get; set; } + public PizzaSpecial Special { get; set; } - public int SpecialId { get; set; } + public int SpecialId { get; set; } - public int Size { get; set; } + public int Size { get; set; } - public List Toppings { get; set; } + public List Toppings { get; set; } - public decimal GetBasePrice() - { - return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; - } + public decimal GetBasePrice() + { + return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; + } - public decimal GetTotalPrice() - { - return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); - } + public decimal GetTotalPrice() + { + return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); + } - public string GetFormattedTotalPrice() - { - return GetTotalPrice().ToString("0.00"); - } + public string GetFormattedTotalPrice() + { + return GetTotalPrice().ToString("0.00"); } } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Serialization)] +[JsonSerializable(typeof(Pizza))] +public partial class PizzaContext : JsonSerializerContext { } \ No newline at end of file diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Shared/PizzaSpecial.cs b/save-points/02-customize-a-pizza/BlazingPizza.Shared/PizzaSpecial.cs index 2f2b3383..1fd9006a 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Shared/PizzaSpecial.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Shared/PizzaSpecial.cs @@ -1,20 +1,19 @@ -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// Represents a pre-configured template for a pizza a user can order +/// +public class PizzaSpecial { - /// - /// Represents a pre-configured template for a pizza a user can order - /// - public class PizzaSpecial - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal BasePrice { get; set; } + public decimal BasePrice { get; set; } - public string Description { get; set; } + public string Description { get; set; } - public string ImageUrl { get; set; } + public string ImageUrl { get; set; } - public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); - } -} + public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); +} \ No newline at end of file diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Shared/PizzaTopping.cs b/save-points/02-customize-a-pizza/BlazingPizza.Shared/PizzaTopping.cs index f5a6c1ac..1c062732 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Shared/PizzaTopping.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Shared/PizzaTopping.cs @@ -1,11 +1,11 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class PizzaTopping { - public class PizzaTopping - { - public Topping Topping { get; set; } - - public int ToppingId { get; set; } - - public int PizzaId { get; set; } - } -} + public Topping Topping { get; set; } + + public int ToppingId { get; set; } + + public int PizzaId { get; set; } + +} \ No newline at end of file diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Shared/Topping.cs b/save-points/02-customize-a-pizza/BlazingPizza.Shared/Topping.cs index 61bdeb92..4eb67ae9 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Shared/Topping.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Shared/Topping.cs @@ -1,13 +1,13 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class Topping { - public class Topping - { - public int Id { get; set; } + public int Id { get; set; } + + public string Name { get; set; } - public string Name { get; set; } + public decimal Price { get; set; } - public decimal Price { get; set; } + public string GetFormattedPrice() => Price.ToString("0.00"); - public string GetFormattedPrice() => Price.ToString("0.00"); - } -} +} \ No newline at end of file diff --git a/save-points/02-customize-a-pizza/BlazingPizza.Shared/UserInfo.cs b/save-points/02-customize-a-pizza/BlazingPizza.Shared/UserInfo.cs index 4996ef80..babb4315 100644 --- a/save-points/02-customize-a-pizza/BlazingPizza.Shared/UserInfo.cs +++ b/save-points/02-customize-a-pizza/BlazingPizza.Shared/UserInfo.cs @@ -1,9 +1,9 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class UserInfo { - public class UserInfo - { - public bool IsAuthenticated { get; set; } + public bool IsAuthenticated { get; set; } + + public string Name { get; set; } - public string Name { get; set; } - } -} +} \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Client/BlazingPizza.Client.csproj b/save-points/03-show-order-status/BlazingPizza.Client/BlazingPizza.Client.csproj index a833c6be..f9ebe283 100644 --- a/save-points/03-show-order-status/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/save-points/03-show-order-status/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -1,7 +1,8 @@  - net5.0 + $(TargetFrameworkVersion) + true diff --git a/save-points/03-show-order-status/BlazingPizza.Client/Pages/MyOrders.razor b/save-points/03-show-order-status/BlazingPizza.Client/Pages/MyOrders.razor index a4d5f14c..36d3902e 100644 --- a/save-points/03-show-order-status/BlazingPizza.Client/Pages/MyOrders.razor +++ b/save-points/03-show-order-status/BlazingPizza.Client/Pages/MyOrders.razor @@ -1,6 +1,8 @@ @page "/myorders" @inject HttpClient HttpClient +Blazing Pizza - My Orders +
@if (ordersWithStatus == null) { diff --git a/save-points/03-show-order-status/BlazingPizza.Client/Pages/OrderDetails.razor b/save-points/03-show-order-status/BlazingPizza.Client/Pages/OrderDetails.razor index 05d96c1e..25e06141 100644 --- a/save-points/03-show-order-status/BlazingPizza.Client/Pages/OrderDetails.razor +++ b/save-points/03-show-order-status/BlazingPizza.Client/Pages/OrderDetails.razor @@ -3,6 +3,8 @@ @inject HttpClient HttpClient @implements IDisposable +Blazing Pizza - Order Details +
@if (invalidOrder) { diff --git a/save-points/03-show-order-status/BlazingPizza.Client/Program.cs b/save-points/03-show-order-status/BlazingPizza.Client/Program.cs index 48147d6f..c5023d76 100644 --- a/save-points/03-show-order-status/BlazingPizza.Client/Program.cs +++ b/save-points/03-show-order-status/BlazingPizza.Client/Program.cs @@ -1,21 +1,11 @@ -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.Web; +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.RootComponents.Add("head::after"); - builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); +builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); - await builder.Build().RunAsync(); - } - } -} +await builder.Build().RunAsync(); diff --git a/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 5f51ee3c..cb996b1b 100644 --- a/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -1,7 +1,8 @@  - net5.0 + $(TargetFrameworkVersion) + true diff --git a/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/LocalStorage.cs b/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/LocalStorage.cs index f36b098e..be8226ec 100644 --- a/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/LocalStorage.cs +++ b/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/LocalStorage.cs @@ -1,17 +1,15 @@ using Microsoft.JSInterop; -using System.Threading.Tasks; -namespace BlazingPizza.ComponentsLibrary +namespace BlazingPizza.ComponentsLibrary; + +public static class LocalStorage { - public static class LocalStorage - { - public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) + public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); - public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object 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) + public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key) => jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key); - } -} +} \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/Map/Marker.cs b/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/Map/Marker.cs index 63006067..b067719c 100644 --- a/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/Map/Marker.cs +++ b/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/Map/Marker.cs @@ -1,13 +1,12 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Marker { - public class Marker - { - public string Description { get; set; } + public string Description { get; set; } - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } + public double Y { get; set; } - public bool ShowPopup { get; set; } - } + public bool ShowPopup { get; set; } } diff --git a/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/Map/Point.cs b/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/Map/Point.cs index 03841826..34194163 100644 --- a/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/Map/Point.cs +++ b/save-points/03-show-order-status/BlazingPizza.ComponentsLibrary/Map/Point.cs @@ -1,9 +1,8 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Point { - public class Point - { - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } - } -} + public double Y { get; set; } +} \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Server/BlazingPizza.Server.csproj b/save-points/03-show-order-status/BlazingPizza.Server/BlazingPizza.Server.csproj index fd7e3c51..227890e1 100644 --- a/save-points/03-show-order-status/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/save-points/03-show-order-status/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -1,7 +1,8 @@  - net5.0 + $(TargetFrameworkVersion) + true diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/AddressEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/AddressEntityType.cs new file mode 100644 index 00000000..82db81b6 --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/AddressEntityType.cs @@ -0,0 +1,92 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class AddressEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Address", + typeof(Address), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Address).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var city = runtimeEntityType.AddProperty( + "City", + typeof(string), + propertyInfo: typeof(Address).GetProperty("City", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var line1 = runtimeEntityType.AddProperty( + "Line1", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line1", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var line2 = runtimeEntityType.AddProperty( + "Line2", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line2", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var postalCode = runtimeEntityType.AddProperty( + "PostalCode", + typeof(string), + propertyInfo: typeof(Address).GetProperty("PostalCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var region = runtimeEntityType.AddProperty( + "Region", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Region", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Address"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs new file mode 100644 index 00000000..1dd4563b --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs @@ -0,0 +1,114 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class DeviceFlowCodesEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.DeviceFlowCodes", + typeof(DeviceFlowCodes), + baseEntityType); + + var userCode = runtimeEntityType.AddProperty( + "UserCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("UserCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var deviceCode = runtimeEntityType.AddProperty( + "DeviceCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("DeviceCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var key = runtimeEntityType.AddKey( + new[] { userCode }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deviceCode }, + unique: true); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "DeviceCodes"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs new file mode 100644 index 00000000..8946b261 --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRoleClaim", + typeof(IdentityRoleClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoleClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityRoleEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityRoleEntityType.cs new file mode 100644 index 00000000..2f1fec2b --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityRoleEntityType.cs @@ -0,0 +1,78 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRole", + typeof(IdentityRole), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedName = runtimeEntityType.AddProperty( + "NormalizedName", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("NormalizedName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedName }, + unique: true); + index.AddAnnotation("Relational:Name", "RoleNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs new file mode 100644 index 00000000..55418a1e --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserClaim", + typeof(IdentityUserClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityUserClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs new file mode 100644 index 00000000..3ca029bd --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserLoginstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserLogin", + typeof(IdentityUserLogin), + baseEntityType); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerKey = runtimeEntityType.AddProperty( + "ProviderKey", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderKey", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerDisplayName = runtimeEntityType.AddProperty( + "ProviderDisplayName", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderDisplayName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { loginProvider, providerKey }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserLogins"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs new file mode 100644 index 00000000..70078d7a --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs @@ -0,0 +1,82 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserRolestringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserRole", + typeof(IdentityUserRole), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { userId, roleId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs new file mode 100644 index 00000000..93ba6d31 --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs @@ -0,0 +1,84 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserTokenstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserToken", + typeof(IdentityUserToken), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var value = runtimeEntityType.AddProperty( + "Value", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Value", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { userId, loginProvider, name }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserTokens"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/KeyEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/KeyEntityType.cs new file mode 100644 index 00000000..f6c6b4c7 --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/KeyEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class KeyEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.Key", + typeof(Key), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var algorithm = runtimeEntityType.AddProperty( + "Algorithm", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Algorithm", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var created = runtimeEntityType.AddProperty( + "Created", + typeof(DateTime), + propertyInfo: typeof(Key).GetProperty("Created", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var dataProtected = runtimeEntityType.AddProperty( + "DataProtected", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("DataProtected", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var isX509Certificate = runtimeEntityType.AddProperty( + "IsX509Certificate", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("IsX509Certificate", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var use = runtimeEntityType.AddProperty( + "Use", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Use", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var version = runtimeEntityType.AddProperty( + "Version", + typeof(int), + propertyInfo: typeof(Key).GetProperty("Version", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { use }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Keys"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/LatLongEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/LatLongEntityType.cs new file mode 100644 index 00000000..3fd254bd --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/LatLongEntityType.cs @@ -0,0 +1,80 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class LatLongEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.LatLong", + typeof(LatLong), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var latitude = runtimeEntityType.AddProperty( + "Latitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Latitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var longitude = runtimeEntityType.AddProperty( + "Longitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Longitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + unique: true, + required: true, + ownership: true); + + var deliveryLocation = principalEntityType.AddNavigation("DeliveryLocation", + runtimeForeignKey, + onDependent: false, + typeof(LatLong), + propertyInfo: typeof(Order).GetProperty("DeliveryLocation", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + eagerLoaded: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs new file mode 100644 index 00000000..db236e4c --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs @@ -0,0 +1,77 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class NotificationSubscriptionEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.NotificationSubscription", + typeof(NotificationSubscription), + baseEntityType); + + var notificationSubscriptionId = runtimeEntityType.AddProperty( + "NotificationSubscriptionId", + typeof(int), + propertyInfo: typeof(NotificationSubscription).GetProperty("NotificationSubscriptionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var auth = runtimeEntityType.AddProperty( + "Auth", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Auth", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var p256dh = runtimeEntityType.AddProperty( + "P256dh", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("P256dh", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var url = runtimeEntityType.AddProperty( + "Url", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Url", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { notificationSubscriptionId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "NotificationSubscriptions"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/OrderEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/OrderEntityType.cs new file mode 100644 index 00000000..9d9ec6fd --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/OrderEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class OrderEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Order", + typeof(Order), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Order).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var createdTime = runtimeEntityType.AddProperty( + "CreatedTime", + typeof(DateTime), + propertyInfo: typeof(Order).GetProperty("CreatedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var deliveryAddressId = runtimeEntityType.AddProperty( + "DeliveryAddressId", + typeof(int?), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(Order).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deliveryAddressId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("DeliveryAddressId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType); + + var deliveryAddress = declaringEntityType.AddNavigation("DeliveryAddress", + runtimeForeignKey, + onDependent: true, + typeof(Address), + propertyInfo: typeof(Order).GetProperty("DeliveryAddress", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/PersistedGrantEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/PersistedGrantEntityType.cs new file mode 100644 index 00000000..842d53a5 --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/PersistedGrantEntityType.cs @@ -0,0 +1,127 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PersistedGrantEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.PersistedGrant", + typeof(PersistedGrant), + baseEntityType); + + var key = runtimeEntityType.AddProperty( + "Key", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Key", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var consumedTime = runtimeEntityType.AddProperty( + "ConsumedTime", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("ConsumedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(PersistedGrant).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var type = runtimeEntityType.AddProperty( + "Type", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Type", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var key0 = runtimeEntityType.AddKey( + new[] { key }); + runtimeEntityType.SetPrimaryKey(key0); + + var index = runtimeEntityType.AddIndex( + new[] { consumedTime }); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + var index1 = runtimeEntityType.AddIndex( + new[] { subjectId, clientId, type }); + + var index2 = runtimeEntityType.AddIndex( + new[] { subjectId, sessionId, type }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PersistedGrants"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaEntityType.cs new file mode 100644 index 00000000..3a124e63 --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaEntityType.cs @@ -0,0 +1,111 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Pizza", + typeof(Pizza), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var size = runtimeEntityType.AddProperty( + "Size", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Size", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var specialId = runtimeEntityType.AddProperty( + "SpecialId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("SpecialId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { orderId }); + + var index0 = runtimeEntityType.AddIndex( + new[] { specialId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var pizzas = principalEntityType.AddNavigation("Pizzas", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Order).GetProperty("Pizzas", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("SpecialId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var special = declaringEntityType.AddNavigation("Special", + runtimeForeignKey, + onDependent: true, + typeof(PizzaSpecial), + propertyInfo: typeof(Pizza).GetProperty("Special", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Pizzas"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs new file mode 100644 index 00000000..e86b0f50 --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs @@ -0,0 +1,76 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaSpecialEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaSpecial", + typeof(PizzaSpecial), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(PizzaSpecial).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var basePrice = runtimeEntityType.AddProperty( + "BasePrice", + typeof(decimal), + propertyInfo: typeof(PizzaSpecial).GetProperty("BasePrice", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var imageUrl = runtimeEntityType.AddProperty( + "ImageUrl", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("ImageUrl", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Specials"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaStoreContextModel.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaStoreContextModel.cs new file mode 100644 index 00000000..8b516a68 --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaStoreContextModel.cs @@ -0,0 +1,28 @@ +// +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + [DbContext(typeof(PizzaStoreContext))] + public partial class PizzaStoreContextModel : RuntimeModel + { + static PizzaStoreContextModel() + { + var model = new PizzaStoreContextModel(); + model.Initialize(); + model.Customize(); + _instance = model; + } + + private static PizzaStoreContextModel _instance; + public static IModel Instance => _instance; + + partial void Initialize(); + + partial void Customize(); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs new file mode 100644 index 00000000..d46f50f4 --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs @@ -0,0 +1,69 @@ +// +using System; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + public partial class PizzaStoreContextModel + { + partial void Initialize() + { + var address = AddressEntityType.Create(this); + var latLong = LatLongEntityType.Create(this); + var notificationSubscription = NotificationSubscriptionEntityType.Create(this); + var order = OrderEntityType.Create(this); + var pizza = PizzaEntityType.Create(this); + var pizzaSpecial = PizzaSpecialEntityType.Create(this); + var pizzaTopping = PizzaToppingEntityType.Create(this); + var pizzaStoreUser = PizzaStoreUserEntityType.Create(this); + var topping = ToppingEntityType.Create(this); + var deviceFlowCodes = DeviceFlowCodesEntityType.Create(this); + var key = KeyEntityType.Create(this); + var persistedGrant = PersistedGrantEntityType.Create(this); + var identityRole = IdentityRoleEntityType.Create(this); + var identityRoleClaimstring = IdentityRoleClaimstringEntityType.Create(this); + var identityUserClaimstring = IdentityUserClaimstringEntityType.Create(this); + var identityUserLoginstring = IdentityUserLoginstringEntityType.Create(this); + var identityUserRolestring = IdentityUserRolestringEntityType.Create(this); + var identityUserTokenstring = IdentityUserTokenstringEntityType.Create(this); + + LatLongEntityType.CreateForeignKey1(latLong, order); + OrderEntityType.CreateForeignKey1(order, address); + PizzaEntityType.CreateForeignKey1(pizza, order); + PizzaEntityType.CreateForeignKey2(pizza, pizzaSpecial); + PizzaToppingEntityType.CreateForeignKey1(pizzaTopping, pizza); + PizzaToppingEntityType.CreateForeignKey2(pizzaTopping, topping); + IdentityRoleClaimstringEntityType.CreateForeignKey1(identityRoleClaimstring, identityRole); + IdentityUserClaimstringEntityType.CreateForeignKey1(identityUserClaimstring, pizzaStoreUser); + IdentityUserLoginstringEntityType.CreateForeignKey1(identityUserLoginstring, pizzaStoreUser); + IdentityUserRolestringEntityType.CreateForeignKey1(identityUserRolestring, identityRole); + IdentityUserRolestringEntityType.CreateForeignKey2(identityUserRolestring, pizzaStoreUser); + IdentityUserTokenstringEntityType.CreateForeignKey1(identityUserTokenstring, pizzaStoreUser); + + AddressEntityType.CreateAnnotations(address); + LatLongEntityType.CreateAnnotations(latLong); + NotificationSubscriptionEntityType.CreateAnnotations(notificationSubscription); + OrderEntityType.CreateAnnotations(order); + PizzaEntityType.CreateAnnotations(pizza); + PizzaSpecialEntityType.CreateAnnotations(pizzaSpecial); + PizzaToppingEntityType.CreateAnnotations(pizzaTopping); + PizzaStoreUserEntityType.CreateAnnotations(pizzaStoreUser); + ToppingEntityType.CreateAnnotations(topping); + DeviceFlowCodesEntityType.CreateAnnotations(deviceFlowCodes); + KeyEntityType.CreateAnnotations(key); + PersistedGrantEntityType.CreateAnnotations(persistedGrant); + IdentityRoleEntityType.CreateAnnotations(identityRole); + IdentityRoleClaimstringEntityType.CreateAnnotations(identityRoleClaimstring); + IdentityUserClaimstringEntityType.CreateAnnotations(identityUserClaimstring); + IdentityUserLoginstringEntityType.CreateAnnotations(identityUserLoginstring); + IdentityUserRolestringEntityType.CreateAnnotations(identityUserRolestring); + IdentityUserTokenstringEntityType.CreateAnnotations(identityUserTokenstring); + + AddAnnotation("ProductVersion", "6.0.0"); + } + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs new file mode 100644 index 00000000..18b2d96d --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs @@ -0,0 +1,156 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaStoreUserEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Server.PizzaStoreUser", + typeof(PizzaStoreUser), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var accessFailedCount = runtimeEntityType.AddProperty( + "AccessFailedCount", + typeof(int), + propertyInfo: typeof(IdentityUser).GetProperty("AccessFailedCount", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var email = runtimeEntityType.AddProperty( + "Email", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Email", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var emailConfirmed = runtimeEntityType.AddProperty( + "EmailConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("EmailConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnabled = runtimeEntityType.AddProperty( + "LockoutEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnd = runtimeEntityType.AddProperty( + "LockoutEnd", + typeof(DateTimeOffset?), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnd", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var normalizedEmail = runtimeEntityType.AddProperty( + "NormalizedEmail", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedEmail", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedUserName = runtimeEntityType.AddProperty( + "NormalizedUserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedUserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var passwordHash = runtimeEntityType.AddProperty( + "PasswordHash", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PasswordHash", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumber = runtimeEntityType.AddProperty( + "PhoneNumber", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumber", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumberConfirmed = runtimeEntityType.AddProperty( + "PhoneNumberConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumberConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var securityStamp = runtimeEntityType.AddProperty( + "SecurityStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("SecurityStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var twoFactorEnabled = runtimeEntityType.AddProperty( + "TwoFactorEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("TwoFactorEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var userName = runtimeEntityType.AddProperty( + "UserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("UserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedEmail }); + index.AddAnnotation("Relational:Name", "EmailIndex"); + + var index0 = runtimeEntityType.AddIndex( + new[] { normalizedUserName }, + unique: true); + index0.AddAnnotation("Relational:Name", "UserNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUsers"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaToppingEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaToppingEntityType.cs new file mode 100644 index 00000000..b97d2a24 --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/PizzaToppingEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaTopping", + typeof(PizzaTopping), + baseEntityType); + + var pizzaId = runtimeEntityType.AddProperty( + "PizzaId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("PizzaId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var toppingId = runtimeEntityType.AddProperty( + "ToppingId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("ToppingId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { pizzaId, toppingId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { toppingId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("PizzaId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var toppings = principalEntityType.AddNavigation("Toppings", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Pizza).GetProperty("Toppings", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("ToppingId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var topping = declaringEntityType.AddNavigation("Topping", + runtimeForeignKey, + onDependent: true, + typeof(Topping), + propertyInfo: typeof(PizzaTopping).GetProperty("Topping", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PizzaTopping"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Models/ToppingEntityType.cs b/save-points/03-show-order-status/BlazingPizza.Server/Models/ToppingEntityType.cs new file mode 100644 index 00000000..9295f9bf --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/Models/ToppingEntityType.cs @@ -0,0 +1,62 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class ToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Topping", + typeof(Topping), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Topping).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Topping).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var price = runtimeEntityType.AddProperty( + "Price", + typeof(decimal), + propertyInfo: typeof(Topping).GetProperty("Price", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Toppings"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/NotificationsController.cs b/save-points/03-show-order-status/BlazingPizza.Server/NotificationsController.cs deleted file mode 100644 index bb3b96ff..00000000 --- a/save-points/03-show-order-status/BlazingPizza.Server/NotificationsController.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("notifications")] - [ApiController] - [Authorize] - public class NotificationsController : Controller - { - private readonly PizzaStoreContext _db; - - public NotificationsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpPut("subscribe")] - public async Task Subscribe(NotificationSubscription subscription) - { - // We're storing at most one subscription per user, so delete old ones. - // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. - var userId = GetUserId(); - var oldSubscriptions = _db.NotificationSubscriptions.Where(e => e.UserId == userId); - _db.NotificationSubscriptions.RemoveRange(oldSubscriptions); - - // Store new subscription - subscription.UserId = userId; - _db.NotificationSubscriptions.Attach(subscription); - - await _db.SaveChangesAsync(); - return subscription; - } - - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } - } -} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/OidcConfigurationController.cs b/save-points/03-show-order-status/BlazingPizza.Server/OidcConfigurationController.cs index c074debf..3d385048 100644 --- a/save-points/03-show-order-status/BlazingPizza.Server/OidcConfigurationController.cs +++ b/save-points/03-show-order-status/BlazingPizza.Server/OidcConfigurationController.cs @@ -1,26 +1,21 @@ using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class OidcConfigurationController : Controller { - public class OidcConfigurationController : Controller + public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) { - public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) - { - ClientRequestParametersProvider = clientRequestParametersProvider; - } + ClientRequestParametersProvider = clientRequestParametersProvider; + } - public IClientRequestParametersProvider ClientRequestParametersProvider { get; } + public IClientRequestParametersProvider ClientRequestParametersProvider { get; } - [HttpGet("_configuration/{clientId}")] - public IActionResult GetClientRequestParameters([FromRoute]string clientId) - { - var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); - return Ok(parameters); - } + [HttpGet("_configuration/{clientId}")] + public IActionResult GetClientRequestParameters([FromRoute] string clientId) + { + var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); + return Ok(parameters); } -} +} \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Server/OrdersController.cs b/save-points/03-show-order-status/BlazingPizza.Server/OrdersController.cs index 2b8bc99b..37e37cc5 100644 --- a/save-points/03-show-order-status/BlazingPizza.Server/OrdersController.cs +++ b/save-points/03-show-order-status/BlazingPizza.Server/OrdersController.cs @@ -1,29 +1,25 @@ -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; + private readonly PizzaStoreContext _db; - public OrdersController(PizzaStoreContext db) - { - _db = db; - } + public OrdersController(PizzaStoreContext db) + { + _db = db; + } - [HttpGet] - public async Task>> GetOrders() - { - var orders = await _db.Orders + [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) @@ -31,13 +27,13 @@ public async Task>> GetOrders() .OrderByDescending(o => o.CreatedTime) .ToListAsync(); - return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); - } + return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); + } - [HttpGet("{orderId}")] - public async Task> GetOrderWithStatus(int orderId) - { - var order = await _db.Orders + [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) @@ -45,70 +41,69 @@ public async Task> GetOrderWithStatus(int orderId) .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) .SingleOrDefaultAsync(); - if (order == null) - { - return NotFound(); - } - - return OrderWithStatus.FromOrder(order); + if (order == null) + { + return NotFound(); } - [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; - } - } + return OrderWithStatus.FromOrder(order); + } - _db.Orders.Attach(order); - await _db.SaveChangesAsync(); + [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; - // In the background, send push notifications if possible - var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); - if (subscription != null) + foreach (var topping in pizza.Toppings) { - _ = TrackAndSendNotificationsAsync(order, subscription); + topping.ToppingId = topping.Topping.Id; + topping.Topping = null; } - - return order.OrderId; } - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } + _db.Orders.Attach(order); + await _db.SaveChangesAsync(); - private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription subscription) + // In the background, send push notifications if possible + var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); + if (subscription != null) { - // 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!"); + _ = TrackAndSendNotificationsAsync(order, subscription); } - private static Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) - { - // This will be implemented later - return Task.CompletedTask; - } + return order.OrderId; + } + + private string GetUserId() + { + return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); + } + + private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription subscription) + { + // In a realistic case, some other backend process would track + // order delivery progress and send us notifications when it + // changes. Since we don't have any such process here, fake it. + await Task.Delay(OrderWithStatus.PreparationDuration); + await SendNotificationAsync(order, subscription, "Your order has been dispatched!"); + + await Task.Delay(OrderWithStatus.DeliveryDuration); + await SendNotificationAsync(order, subscription, "Your order is now delivered. Enjoy!"); + } + + private static Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) + { + // This will be implemented later + return Task.CompletedTask; } -} +} \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Server/PizzaApiExtensions.cs b/save-points/03-show-order-status/BlazingPizza.Server/PizzaApiExtensions.cs new file mode 100644 index 00000000..524ca759 --- /dev/null +++ b/save-points/03-show-order-status/BlazingPizza.Server/PizzaApiExtensions.cs @@ -0,0 +1,57 @@ +using System.Security.Claims; +using Microsoft.AspNetCore.Authorization; +using Microsoft.EntityFrameworkCore; + +namespace BlazingPizza.Server; + +public static class PizzaApiExtensions +{ + + public static WebApplication MapPizzaApi(this WebApplication app) + { + + // Subscribe to notifications + app.MapPut("/notifications/subscribe", [Authorize] async ( + HttpContext context, + PizzaStoreContext db, + NotificationSubscription subscription) => { + + // We're storing at most one subscription per user, so delete old ones. + // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. + var userId = GetUserId(context); + var oldSubscriptions = db.NotificationSubscriptions.Where(e => e.UserId == userId); + db.NotificationSubscriptions.RemoveRange(oldSubscriptions); + + // Store new subscription + subscription.UserId = userId; + db.NotificationSubscriptions.Attach(subscription); + + await db.SaveChangesAsync(); + return Results.Ok(subscription); + + }); + + // Specials + app.MapGet("/specials", async (PizzaStoreContext db) => { + + var specials = await db.Specials.ToListAsync(); + return Results.Ok(specials); + + }); + + // Toppings + app.MapGet("/toppings", async (PizzaStoreContext db) => { + var toppings = await db.Toppings.OrderBy(t => t.Name).ToListAsync(); + return Results.Ok(toppings); + }); + + return app; + + } + + private static string GetUserId(HttpContext context) + { + return context.User.FindFirstValue(ClaimTypes.NameIdentifier); + } + +} \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Server/PizzaStoreContext.cs b/save-points/03-show-order-status/BlazingPizza.Server/PizzaStoreContext.cs index f79c1c66..50ac87e4 100644 --- a/save-points/03-show-order-status/BlazingPizza.Server/PizzaStoreContext.cs +++ b/save-points/03-show-order-status/BlazingPizza.Server/PizzaStoreContext.cs @@ -1,39 +1,38 @@ -using IdentityServer4.EntityFramework.Options; +using Duende.IdentityServer.EntityFramework.Options; using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class PizzaStoreContext : ApiAuthorizationDbContext { - public class PizzaStoreContext : ApiAuthorizationDbContext - { - public PizzaStoreContext( + 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/03-show-order-status/BlazingPizza.Server/PizzaStoreUser.cs b/save-points/03-show-order-status/BlazingPizza.Server/PizzaStoreUser.cs index 171ce83d..d446a679 100644 --- a/save-points/03-show-order-status/BlazingPizza.Server/PizzaStoreUser.cs +++ b/save-points/03-show-order-status/BlazingPizza.Server/PizzaStoreUser.cs @@ -1,8 +1,6 @@ using Microsoft.AspNetCore.Identity; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; +public class PizzaStoreUser : IdentityUser { - public class PizzaStoreUser : IdentityUser - { - } } \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Server/PizzasController.cs b/save-points/03-show-order-status/BlazingPizza.Server/PizzasController.cs deleted file mode 100644 index c082552c..00000000 --- a/save-points/03-show-order-status/BlazingPizza.Server/PizzasController.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("pizzas")] - [ApiController] - public class PizzasController : Controller - { - private readonly PizzaStoreContext _db; - - public PizzasController(PizzaStoreContext db) - { - _db = db; - } - } -} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Program.cs b/save-points/03-show-order-status/BlazingPizza.Server/Program.cs index 40a47641..b83debb4 100644 --- a/save-points/03-show-order-status/BlazingPizza.Server/Program.cs +++ b/save-points/03-show-order-status/BlazingPizza.Server/Program.cs @@ -1,33 +1,67 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; +using BlazingPizza.Server; +using Microsoft.AspNetCore.Authentication; +using Microsoft.EntityFrameworkCore; -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()) { - public class Program + var db = scope.ServiceProvider.GetRequiredService(); + if (db.Database.EnsureCreated()) { - 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(); - }); + SeedData.Initialize(db); } } + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + 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.MapPizzaApi(); + +app.MapRazorPages(); +app.MapControllers(); +app.MapFallbackToFile("index.html"); + +app.Run(); \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Server/SeedData.cs b/save-points/03-show-order-status/BlazingPizza.Server/SeedData.cs index 7c86a5b2..f02e2b77 100644 --- a/save-points/03-show-order-status/BlazingPizza.Server/SeedData.cs +++ b/save-points/03-show-order-status/BlazingPizza.Server/SeedData.cs @@ -1,193 +1,192 @@ -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public static class SeedData { - public static class SeedData + public static void Initialize(PizzaStoreContext db) { - public static void Initialize(PizzaStoreContext db) + var toppings = new Topping[] { - var toppings = new Topping[] + new Topping() { - new Topping() - { Name = "Extra cheese", Price = 2.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "American bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "British bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Canadian bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Tea and crumpets", Price = 5.00m - }, - new Topping() - { + }, + new Topping() + { Name = "Fresh-baked scones", Price = 4.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Bell peppers", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Onions", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Mushrooms", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Pepperoni", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Duck sausage", Price = 3.20m, - }, - new Topping() - { + }, + new Topping() + { Name = "Venison meatballs", Price = 2.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Served on a silver platter", Price = 250.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Lobster on top", Price = 64.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Sturgeon caviar", Price = 101.75m, - }, - new Topping() - { + }, + new Topping() + { Name = "Artichoke hearts", Price = 3.40m, - }, - new Topping() - { + }, + new Topping() + { Name = "Fresh tomatoes", Price = 1.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Basil", Price = 1.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Steak (medium-rare)", Price = 8.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Blazing hot peppers", Price = 4.20m, - }, - new Topping() - { + }, + new Topping() + { Name = "Buffalo chicken", Price = 5.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Blue cheese", Price = 2.50m, - }, - }; + }, + }; - var specials = new PizzaSpecial[] + var specials = new PizzaSpecial[] + { + 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() - { + }, + new PizzaSpecial() + { Id = 2, Name = "The Baconatorizor", Description = "It has EVERY kind of bacon", BasePrice = 11.99m, ImageUrl = "img/pizzas/bacon.jpg", - }, - new PizzaSpecial() - { + }, + 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() - { + }, + 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() - { + }, + 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() - { + }, + new PizzaSpecial() + { Id = 6, Name = "The Brit", Description = "When in London...", BasePrice = 10.25m, ImageUrl = "img/pizzas/brit.jpg", - }, - new PizzaSpecial() - { + }, + 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() - { + }, + new PizzaSpecial() + { Id = 8, Name = "Margherita", Description = "Traditional Italian pizza with tomatoes and basil", BasePrice = 9.99m, ImageUrl = "img/pizzas/margherita.jpg", - }, - }; + }, + }; - db.Toppings.AddRange(toppings); - db.Specials.AddRange(specials); - db.SaveChanges(); - } + db.Toppings.AddRange(toppings); + db.Specials.AddRange(specials); + db.SaveChanges(); } -} +} \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Server/SpecialsController.cs b/save-points/03-show-order-status/BlazingPizza.Server/SpecialsController.cs deleted file mode 100644 index a176844c..00000000 --- a/save-points/03-show-order-status/BlazingPizza.Server/SpecialsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("specials")] - [ApiController] - public class SpecialsController : Controller - { - private readonly PizzaStoreContext _db; - - public SpecialsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetSpecials() - { - return (await _db.Specials.ToListAsync()).OrderByDescending(s => s.BasePrice).ToList(); - } - } -} diff --git a/save-points/03-show-order-status/BlazingPizza.Server/Startup.cs b/save-points/03-show-order-status/BlazingPizza.Server/Startup.cs deleted file mode 100644 index ed3fca06..00000000 --- a/save-points/03-show-order-status/BlazingPizza.Server/Startup.cs +++ /dev/null @@ -1,70 +0,0 @@ -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace BlazingPizza.Server -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - public void ConfigureServices(IServiceCollection services) - { - services.AddControllersWithViews(); - services.AddRazorPages(); - - services.AddDbContext(options => - options.UseSqlite("Data Source=pizza.db")); - - services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) - .AddEntityFrameworkStores(); - - services.AddIdentityServer() - .AddApiAuthorization(); - - services.AddAuthentication() - .AddIdentityServerJwt(); - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - app.UseWebAssemblyDebugging(); - } - else - { - app.UseExceptionHandler("/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); - } - - app.UseHttpsRedirection(); - app.UseBlazorFrameworkFiles(); - app.UseStaticFiles(); - - app.UseRouting(); - - app.UseAuthentication(); - app.UseIdentityServer(); - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - endpoints.MapRazorPages(); - endpoints.MapFallbackToFile("index.html"); - }); - } - } -} \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Server/ToppingsController.cs b/save-points/03-show-order-status/BlazingPizza.Server/ToppingsController.cs deleted file mode 100644 index 6a677639..00000000 --- a/save-points/03-show-order-status/BlazingPizza.Server/ToppingsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("toppings")] - [ApiController] - public class ToppingsController : Controller - { - private readonly PizzaStoreContext _db; - - public ToppingsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetToppings() - { - return await _db.Toppings.OrderBy(t => t.Name).ToListAsync(); - } - } -} diff --git a/save-points/03-show-order-status/BlazingPizza.Shared/Address.cs b/save-points/03-show-order-status/BlazingPizza.Shared/Address.cs index e5c0ef0d..309438b7 100644 --- a/save-points/03-show-order-status/BlazingPizza.Shared/Address.cs +++ b/save-points/03-show-order-status/BlazingPizza.Shared/Address.cs @@ -1,21 +1,26 @@ using System.ComponentModel.DataAnnotations; -namespace BlazingPizza +namespace BlazingPizza; + +public class Address { - public class Address - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + [Required, MaxLength(100)] + public string Name { get; set; } - public string Line1 { get; set; } + [Required, MaxLength(100)] + public string Line1 { get; set; } - public string Line2 { get; set; } + [MaxLength(100)] + public string Line2 { get; set; } - public string City { get; set; } + [Required, MaxLength(50)] + public string City { get; set; } - public string Region { get; set; } + [Required, MaxLength(20)] + public string Region { get; set; } - public string PostalCode { get; set; } - } + [Required, MaxLength(20)] + public string PostalCode { get; set; } } diff --git a/save-points/03-show-order-status/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/save-points/03-show-order-status/BlazingPizza.Shared/BlazingPizza.Shared.csproj index 911c57c5..075ddd60 100644 --- a/save-points/03-show-order-status/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/save-points/03-show-order-status/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -1,8 +1,9 @@  - net5.0 + $(TargetFrameworkVersion) BlazingPizza + true diff --git a/save-points/03-show-order-status/BlazingPizza.Shared/LatLong.cs b/save-points/03-show-order-status/BlazingPizza.Shared/LatLong.cs index 9b8c3811..a65971f8 100644 --- a/save-points/03-show-order-status/BlazingPizza.Shared/LatLong.cs +++ b/save-points/03-show-order-status/BlazingPizza.Shared/LatLong.cs @@ -1,27 +1,26 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class LatLong { - public class LatLong + public LatLong() { - public LatLong() - { - } + } - public LatLong(double latitude, double longitude) : this() - { - Latitude = latitude; - Longitude = longitude; - } + public LatLong(double latitude, double longitude) : this() + { + Latitude = latitude; + Longitude = longitude; + } - public double Latitude { get; set; } + public double Latitude { get; set; } - public double Longitude { get; set; } + public double Longitude { get; set; } - public static LatLong Interpolate(LatLong start, LatLong end, double proportion) - { - // The Earth is flat, right? So no need for spherical interpolation. - return new LatLong( + public static LatLong Interpolate(LatLong start, LatLong end, double proportion) + { + // The Earth is flat, right? So no need for spherical interpolation. + return new LatLong( start.Latitude + (end.Latitude - start.Latitude) * proportion, start.Longitude + (end.Longitude - start.Longitude) * proportion); - } } -} +} \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Shared/NotificationSubscription.cs b/save-points/03-show-order-status/BlazingPizza.Shared/NotificationSubscription.cs index 04259c2f..5c99e3f4 100644 --- a/save-points/03-show-order-status/BlazingPizza.Shared/NotificationSubscription.cs +++ b/save-points/03-show-order-status/BlazingPizza.Shared/NotificationSubscription.cs @@ -1,17 +1,14 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class NotificationSubscription { - public class NotificationSubscription - { - public int NotificationSubscriptionId { get; set; } + public int NotificationSubscriptionId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public string Url { get; set; } + public string Url { get; set; } - public string P256dh { get; set; } + public string P256dh { get; set; } - public string Auth { get; set; } - } + public string Auth { get; set; } } diff --git a/save-points/03-show-order-status/BlazingPizza.Shared/Order.cs b/save-points/03-show-order-status/BlazingPizza.Shared/Order.cs index fb003bd6..b47efad0 100644 --- a/save-points/03-show-order-status/BlazingPizza.Shared/Order.cs +++ b/save-points/03-show-order-status/BlazingPizza.Shared/Order.cs @@ -1,25 +1,32 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +public class Order { - public class Order - { - public int OrderId { get; set; } + public int OrderId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public DateTime CreatedTime { get; set; } + public DateTime CreatedTime { get; set; } - public Address DeliveryAddress { get; set; } = new Address(); + public Address DeliveryAddress { get; set; } = new Address(); - public LatLong DeliveryLocation { get; set; } + public LatLong DeliveryLocation { get; set; } - public List Pizzas { get; set; } = new List(); + public List Pizzas { get; set; } = new List(); - public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); + public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); - public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); - } + public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Default, PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] +[JsonSerializable(typeof(Order))] +[JsonSerializable(typeof(OrderWithStatus))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Pizza))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Topping))] +public partial class OrderContext : JsonSerializerContext { } \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Shared/OrderWithStatus.cs b/save-points/03-show-order-status/BlazingPizza.Shared/OrderWithStatus.cs index 021de78c..fbfac7af 100644 --- a/save-points/03-show-order-status/BlazingPizza.Shared/OrderWithStatus.cs +++ b/save-points/03-show-order-status/BlazingPizza.Shared/OrderWithStatus.cs @@ -1,79 +1,78 @@ -using BlazingPizza.ComponentsLibrary.Map; -using System; -using System.Collections.Generic; +using System.Text.Json.Serialization; +using BlazingPizza.ComponentsLibrary.Map; -namespace BlazingPizza -{ - 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 Order Order { get; set; } +namespace BlazingPizza; - public string StatusText { get; set; } +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 bool IsDelivered => StatusText == "Delivered"; + public Order Order { get; set; } - public List MapMarkers { get; set; } + public string StatusText { 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 bool IsDelivered => StatusText == "Delivered"; - 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"; + public List MapMarkers { get; set; } - 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), - }; - } + 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); - return new OrderWithStatus - { - Order = order, - StatusText = statusText, - MapMarkers = mapMarkers, - }; + 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"; - private static LatLong ComputeStartPosition(Order order) + 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 { - // 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); + statusText = "Delivered"; + mapMarkers = new List + { + ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), + }; } - static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) - => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; + 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); + } + + static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) + => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; +} \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Shared/Pizza.cs b/save-points/03-show-order-status/BlazingPizza.Shared/Pizza.cs index ec1108a9..2a7a1c29 100644 --- a/save-points/03-show-order-status/BlazingPizza.Shared/Pizza.cs +++ b/save-points/03-show-order-status/BlazingPizza.Shared/Pizza.cs @@ -1,42 +1,44 @@ -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// /// Represents a customized pizza as part of an order +/// +public class Pizza { - /// - /// Represents a customized pizza as part of an order - /// - public class Pizza - { - public const int DefaultSize = 12; - public const int MinimumSize = 9; - public const int MaximumSize = 17; + public const int DefaultSize = 12; + public const int MinimumSize = 9; + public const int MaximumSize = 17; - public int Id { get; set; } + public int Id { get; set; } - public int OrderId { get; set; } + public int OrderId { get; set; } - public PizzaSpecial Special { get; set; } + public PizzaSpecial Special { get; set; } - public int SpecialId { get; set; } + public int SpecialId { get; set; } - public int Size { get; set; } + public int Size { get; set; } - public List Toppings { get; set; } + public List Toppings { get; set; } - public decimal GetBasePrice() - { - return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; - } + public decimal GetBasePrice() + { + return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; + } - public decimal GetTotalPrice() - { - return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); - } + public decimal GetTotalPrice() + { + return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); + } - public string GetFormattedTotalPrice() - { - return GetTotalPrice().ToString("0.00"); - } + public string GetFormattedTotalPrice() + { + return GetTotalPrice().ToString("0.00"); } } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Serialization)] +[JsonSerializable(typeof(Pizza))] +public partial class PizzaContext : JsonSerializerContext { } \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Shared/PizzaSpecial.cs b/save-points/03-show-order-status/BlazingPizza.Shared/PizzaSpecial.cs index 2f2b3383..1fd9006a 100644 --- a/save-points/03-show-order-status/BlazingPizza.Shared/PizzaSpecial.cs +++ b/save-points/03-show-order-status/BlazingPizza.Shared/PizzaSpecial.cs @@ -1,20 +1,19 @@ -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// Represents a pre-configured template for a pizza a user can order +/// +public class PizzaSpecial { - /// - /// Represents a pre-configured template for a pizza a user can order - /// - public class PizzaSpecial - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal BasePrice { get; set; } + public decimal BasePrice { get; set; } - public string Description { get; set; } + public string Description { get; set; } - public string ImageUrl { get; set; } + public string ImageUrl { get; set; } - public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); - } -} + public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); +} \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Shared/PizzaTopping.cs b/save-points/03-show-order-status/BlazingPizza.Shared/PizzaTopping.cs index f5a6c1ac..1c062732 100644 --- a/save-points/03-show-order-status/BlazingPizza.Shared/PizzaTopping.cs +++ b/save-points/03-show-order-status/BlazingPizza.Shared/PizzaTopping.cs @@ -1,11 +1,11 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class PizzaTopping { - public class PizzaTopping - { - public Topping Topping { get; set; } - - public int ToppingId { get; set; } - - public int PizzaId { get; set; } - } -} + public Topping Topping { get; set; } + + public int ToppingId { get; set; } + + public int PizzaId { get; set; } + +} \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Shared/Topping.cs b/save-points/03-show-order-status/BlazingPizza.Shared/Topping.cs index 61bdeb92..4eb67ae9 100644 --- a/save-points/03-show-order-status/BlazingPizza.Shared/Topping.cs +++ b/save-points/03-show-order-status/BlazingPizza.Shared/Topping.cs @@ -1,13 +1,13 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class Topping { - public class Topping - { - public int Id { get; set; } + public int Id { get; set; } + + public string Name { get; set; } - public string Name { get; set; } + public decimal Price { get; set; } - public decimal Price { get; set; } + public string GetFormattedPrice() => Price.ToString("0.00"); - public string GetFormattedPrice() => Price.ToString("0.00"); - } -} +} \ No newline at end of file diff --git a/save-points/03-show-order-status/BlazingPizza.Shared/UserInfo.cs b/save-points/03-show-order-status/BlazingPizza.Shared/UserInfo.cs index 4996ef80..babb4315 100644 --- a/save-points/03-show-order-status/BlazingPizza.Shared/UserInfo.cs +++ b/save-points/03-show-order-status/BlazingPizza.Shared/UserInfo.cs @@ -1,9 +1,9 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class UserInfo { - public class UserInfo - { - public bool IsAuthenticated { get; set; } + public bool IsAuthenticated { get; set; } + + public string Name { get; set; } - public string Name { get; set; } - } -} +} \ No newline at end of file diff --git a/save-points/04-refactor-state-management/BlazingPizza.Client/BlazingPizza.Client.csproj b/save-points/04-refactor-state-management/BlazingPizza.Client/BlazingPizza.Client.csproj index a833c6be..f9ebe283 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/save-points/04-refactor-state-management/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -1,7 +1,8 @@  - net5.0 + $(TargetFrameworkVersion) + true diff --git a/save-points/04-refactor-state-management/BlazingPizza.Client/OrderState.cs b/save-points/04-refactor-state-management/BlazingPizza.Client/OrderState.cs index f44ac786..ae82f76c 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Client/OrderState.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Client/OrderState.cs @@ -1,50 +1,47 @@ -using System.Collections.Generic; +namespace BlazingPizza.Client; -namespace BlazingPizza.Client +public class OrderState { - public class OrderState - { - public bool ShowingConfigureDialog { get; private set; } + public bool ShowingConfigureDialog { get; private set; } - public Pizza ConfiguringPizza { get; private set; } + public Pizza ConfiguringPizza { get; private set; } - public Order Order { get; private set; } = new Order(); + 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() + public void ShowConfigurePizzaDialog(PizzaSpecial special) + { + ConfiguringPizza = new Pizza() { - ConfiguringPizza = null; - ShowingConfigureDialog = false; - } + Special = special, + SpecialId = special.Id, + Size = Pizza.DefaultSize, + Toppings = new List(), + }; - public void ConfirmConfigurePizzaDialog() - { - Order.Pizzas.Add(ConfiguringPizza); - ConfiguringPizza = null; + ShowingConfigureDialog = true; + } - ShowingConfigureDialog = false; - } + public void CancelConfigurePizzaDialog() + { + ConfiguringPizza = null; + ShowingConfigureDialog = false; + } - public void RemoveConfiguredPizza(Pizza pizza) - { - Order.Pizzas.Remove(pizza); - } + public void ConfirmConfigurePizzaDialog() + { + Order.Pizzas.Add(ConfiguringPizza); + ConfiguringPizza = null; - public void ResetOrder() - { - Order = new Order(); - } + ShowingConfigureDialog = false; + } + + public void RemoveConfiguredPizza(Pizza pizza) + { + Order.Pizzas.Remove(pizza); + } + + public void ResetOrder() + { + Order = new Order(); } } diff --git a/save-points/04-refactor-state-management/BlazingPizza.Client/Pages/MyOrders.razor b/save-points/04-refactor-state-management/BlazingPizza.Client/Pages/MyOrders.razor index a4d5f14c..36d3902e 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Client/Pages/MyOrders.razor +++ b/save-points/04-refactor-state-management/BlazingPizza.Client/Pages/MyOrders.razor @@ -1,6 +1,8 @@ @page "/myorders" @inject HttpClient HttpClient +Blazing Pizza - My Orders +
@if (ordersWithStatus == null) { diff --git a/save-points/04-refactor-state-management/BlazingPizza.Client/Pages/OrderDetails.razor b/save-points/04-refactor-state-management/BlazingPizza.Client/Pages/OrderDetails.razor index 05d96c1e..25e06141 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Client/Pages/OrderDetails.razor +++ b/save-points/04-refactor-state-management/BlazingPizza.Client/Pages/OrderDetails.razor @@ -3,6 +3,8 @@ @inject HttpClient HttpClient @implements IDisposable +Blazing Pizza - Order Details +
@if (invalidOrder) { diff --git a/save-points/04-refactor-state-management/BlazingPizza.Client/Program.cs b/save-points/04-refactor-state-management/BlazingPizza.Client/Program.cs index e0c88943..97ace491 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Client/Program.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Client/Program.cs @@ -1,22 +1,12 @@ -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.Web; +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.RootComponents.Add("head::after"); - builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); - builder.Services.AddScoped(); +builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); +builder.Services.AddScoped(); - await builder.Build().RunAsync(); - } - } -} +await builder.Build().RunAsync(); diff --git a/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 5f51ee3c..cb996b1b 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -1,7 +1,8 @@  - net5.0 + $(TargetFrameworkVersion) + true diff --git a/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/LocalStorage.cs b/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/LocalStorage.cs index f36b098e..be8226ec 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/LocalStorage.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/LocalStorage.cs @@ -1,17 +1,15 @@ using Microsoft.JSInterop; -using System.Threading.Tasks; -namespace BlazingPizza.ComponentsLibrary +namespace BlazingPizza.ComponentsLibrary; + +public static class LocalStorage { - public static class LocalStorage - { - public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) + public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); - public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object 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) + public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key) => jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key); - } -} +} \ No newline at end of file diff --git a/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/Map/Marker.cs b/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/Map/Marker.cs index 63006067..b067719c 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/Map/Marker.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/Map/Marker.cs @@ -1,13 +1,12 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Marker { - public class Marker - { - public string Description { get; set; } + public string Description { get; set; } - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } + public double Y { get; set; } - public bool ShowPopup { get; set; } - } + public bool ShowPopup { get; set; } } diff --git a/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/Map/Point.cs b/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/Map/Point.cs index 03841826..34194163 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/Map/Point.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.ComponentsLibrary/Map/Point.cs @@ -1,9 +1,8 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Point { - public class Point - { - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } - } -} + public double Y { get; set; } +} \ No newline at end of file diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/BlazingPizza.Server.csproj b/save-points/04-refactor-state-management/BlazingPizza.Server/BlazingPizza.Server.csproj index fd7e3c51..ddfe5f60 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -1,7 +1,8 @@  - net5.0 + $(TargetFrameworkVersion) + enable @@ -13,6 +14,7 @@ + diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/AddressEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/AddressEntityType.cs new file mode 100644 index 00000000..82db81b6 --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/AddressEntityType.cs @@ -0,0 +1,92 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class AddressEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Address", + typeof(Address), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Address).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var city = runtimeEntityType.AddProperty( + "City", + typeof(string), + propertyInfo: typeof(Address).GetProperty("City", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var line1 = runtimeEntityType.AddProperty( + "Line1", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line1", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var line2 = runtimeEntityType.AddProperty( + "Line2", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line2", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var postalCode = runtimeEntityType.AddProperty( + "PostalCode", + typeof(string), + propertyInfo: typeof(Address).GetProperty("PostalCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var region = runtimeEntityType.AddProperty( + "Region", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Region", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Address"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs new file mode 100644 index 00000000..1dd4563b --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs @@ -0,0 +1,114 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class DeviceFlowCodesEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.DeviceFlowCodes", + typeof(DeviceFlowCodes), + baseEntityType); + + var userCode = runtimeEntityType.AddProperty( + "UserCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("UserCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var deviceCode = runtimeEntityType.AddProperty( + "DeviceCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("DeviceCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var key = runtimeEntityType.AddKey( + new[] { userCode }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deviceCode }, + unique: true); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "DeviceCodes"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs new file mode 100644 index 00000000..8946b261 --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRoleClaim", + typeof(IdentityRoleClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoleClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityRoleEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityRoleEntityType.cs new file mode 100644 index 00000000..2f1fec2b --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityRoleEntityType.cs @@ -0,0 +1,78 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRole", + typeof(IdentityRole), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedName = runtimeEntityType.AddProperty( + "NormalizedName", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("NormalizedName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedName }, + unique: true); + index.AddAnnotation("Relational:Name", "RoleNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs new file mode 100644 index 00000000..55418a1e --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserClaim", + typeof(IdentityUserClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityUserClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs new file mode 100644 index 00000000..3ca029bd --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserLoginstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserLogin", + typeof(IdentityUserLogin), + baseEntityType); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerKey = runtimeEntityType.AddProperty( + "ProviderKey", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderKey", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerDisplayName = runtimeEntityType.AddProperty( + "ProviderDisplayName", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderDisplayName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { loginProvider, providerKey }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserLogins"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs new file mode 100644 index 00000000..70078d7a --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs @@ -0,0 +1,82 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserRolestringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserRole", + typeof(IdentityUserRole), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { userId, roleId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs new file mode 100644 index 00000000..93ba6d31 --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs @@ -0,0 +1,84 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserTokenstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserToken", + typeof(IdentityUserToken), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var value = runtimeEntityType.AddProperty( + "Value", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Value", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { userId, loginProvider, name }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserTokens"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/KeyEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/KeyEntityType.cs new file mode 100644 index 00000000..f6c6b4c7 --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/KeyEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class KeyEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.Key", + typeof(Key), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var algorithm = runtimeEntityType.AddProperty( + "Algorithm", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Algorithm", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var created = runtimeEntityType.AddProperty( + "Created", + typeof(DateTime), + propertyInfo: typeof(Key).GetProperty("Created", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var dataProtected = runtimeEntityType.AddProperty( + "DataProtected", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("DataProtected", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var isX509Certificate = runtimeEntityType.AddProperty( + "IsX509Certificate", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("IsX509Certificate", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var use = runtimeEntityType.AddProperty( + "Use", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Use", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var version = runtimeEntityType.AddProperty( + "Version", + typeof(int), + propertyInfo: typeof(Key).GetProperty("Version", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { use }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Keys"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/LatLongEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/LatLongEntityType.cs new file mode 100644 index 00000000..3fd254bd --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/LatLongEntityType.cs @@ -0,0 +1,80 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class LatLongEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.LatLong", + typeof(LatLong), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var latitude = runtimeEntityType.AddProperty( + "Latitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Latitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var longitude = runtimeEntityType.AddProperty( + "Longitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Longitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + unique: true, + required: true, + ownership: true); + + var deliveryLocation = principalEntityType.AddNavigation("DeliveryLocation", + runtimeForeignKey, + onDependent: false, + typeof(LatLong), + propertyInfo: typeof(Order).GetProperty("DeliveryLocation", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + eagerLoaded: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs new file mode 100644 index 00000000..db236e4c --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs @@ -0,0 +1,77 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class NotificationSubscriptionEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.NotificationSubscription", + typeof(NotificationSubscription), + baseEntityType); + + var notificationSubscriptionId = runtimeEntityType.AddProperty( + "NotificationSubscriptionId", + typeof(int), + propertyInfo: typeof(NotificationSubscription).GetProperty("NotificationSubscriptionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var auth = runtimeEntityType.AddProperty( + "Auth", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Auth", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var p256dh = runtimeEntityType.AddProperty( + "P256dh", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("P256dh", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var url = runtimeEntityType.AddProperty( + "Url", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Url", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { notificationSubscriptionId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "NotificationSubscriptions"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/OrderEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/OrderEntityType.cs new file mode 100644 index 00000000..9d9ec6fd --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/OrderEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class OrderEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Order", + typeof(Order), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Order).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var createdTime = runtimeEntityType.AddProperty( + "CreatedTime", + typeof(DateTime), + propertyInfo: typeof(Order).GetProperty("CreatedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var deliveryAddressId = runtimeEntityType.AddProperty( + "DeliveryAddressId", + typeof(int?), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(Order).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deliveryAddressId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("DeliveryAddressId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType); + + var deliveryAddress = declaringEntityType.AddNavigation("DeliveryAddress", + runtimeForeignKey, + onDependent: true, + typeof(Address), + propertyInfo: typeof(Order).GetProperty("DeliveryAddress", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PersistedGrantEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PersistedGrantEntityType.cs new file mode 100644 index 00000000..842d53a5 --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PersistedGrantEntityType.cs @@ -0,0 +1,127 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PersistedGrantEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.PersistedGrant", + typeof(PersistedGrant), + baseEntityType); + + var key = runtimeEntityType.AddProperty( + "Key", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Key", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var consumedTime = runtimeEntityType.AddProperty( + "ConsumedTime", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("ConsumedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(PersistedGrant).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var type = runtimeEntityType.AddProperty( + "Type", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Type", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var key0 = runtimeEntityType.AddKey( + new[] { key }); + runtimeEntityType.SetPrimaryKey(key0); + + var index = runtimeEntityType.AddIndex( + new[] { consumedTime }); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + var index1 = runtimeEntityType.AddIndex( + new[] { subjectId, clientId, type }); + + var index2 = runtimeEntityType.AddIndex( + new[] { subjectId, sessionId, type }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PersistedGrants"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaEntityType.cs new file mode 100644 index 00000000..3a124e63 --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaEntityType.cs @@ -0,0 +1,111 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Pizza", + typeof(Pizza), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var size = runtimeEntityType.AddProperty( + "Size", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Size", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var specialId = runtimeEntityType.AddProperty( + "SpecialId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("SpecialId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { orderId }); + + var index0 = runtimeEntityType.AddIndex( + new[] { specialId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var pizzas = principalEntityType.AddNavigation("Pizzas", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Order).GetProperty("Pizzas", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("SpecialId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var special = declaringEntityType.AddNavigation("Special", + runtimeForeignKey, + onDependent: true, + typeof(PizzaSpecial), + propertyInfo: typeof(Pizza).GetProperty("Special", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Pizzas"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs new file mode 100644 index 00000000..e86b0f50 --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs @@ -0,0 +1,76 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaSpecialEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaSpecial", + typeof(PizzaSpecial), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(PizzaSpecial).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var basePrice = runtimeEntityType.AddProperty( + "BasePrice", + typeof(decimal), + propertyInfo: typeof(PizzaSpecial).GetProperty("BasePrice", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var imageUrl = runtimeEntityType.AddProperty( + "ImageUrl", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("ImageUrl", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Specials"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaStoreContextModel.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaStoreContextModel.cs new file mode 100644 index 00000000..8b516a68 --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaStoreContextModel.cs @@ -0,0 +1,28 @@ +// +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + [DbContext(typeof(PizzaStoreContext))] + public partial class PizzaStoreContextModel : RuntimeModel + { + static PizzaStoreContextModel() + { + var model = new PizzaStoreContextModel(); + model.Initialize(); + model.Customize(); + _instance = model; + } + + private static PizzaStoreContextModel _instance; + public static IModel Instance => _instance; + + partial void Initialize(); + + partial void Customize(); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs new file mode 100644 index 00000000..d46f50f4 --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs @@ -0,0 +1,69 @@ +// +using System; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + public partial class PizzaStoreContextModel + { + partial void Initialize() + { + var address = AddressEntityType.Create(this); + var latLong = LatLongEntityType.Create(this); + var notificationSubscription = NotificationSubscriptionEntityType.Create(this); + var order = OrderEntityType.Create(this); + var pizza = PizzaEntityType.Create(this); + var pizzaSpecial = PizzaSpecialEntityType.Create(this); + var pizzaTopping = PizzaToppingEntityType.Create(this); + var pizzaStoreUser = PizzaStoreUserEntityType.Create(this); + var topping = ToppingEntityType.Create(this); + var deviceFlowCodes = DeviceFlowCodesEntityType.Create(this); + var key = KeyEntityType.Create(this); + var persistedGrant = PersistedGrantEntityType.Create(this); + var identityRole = IdentityRoleEntityType.Create(this); + var identityRoleClaimstring = IdentityRoleClaimstringEntityType.Create(this); + var identityUserClaimstring = IdentityUserClaimstringEntityType.Create(this); + var identityUserLoginstring = IdentityUserLoginstringEntityType.Create(this); + var identityUserRolestring = IdentityUserRolestringEntityType.Create(this); + var identityUserTokenstring = IdentityUserTokenstringEntityType.Create(this); + + LatLongEntityType.CreateForeignKey1(latLong, order); + OrderEntityType.CreateForeignKey1(order, address); + PizzaEntityType.CreateForeignKey1(pizza, order); + PizzaEntityType.CreateForeignKey2(pizza, pizzaSpecial); + PizzaToppingEntityType.CreateForeignKey1(pizzaTopping, pizza); + PizzaToppingEntityType.CreateForeignKey2(pizzaTopping, topping); + IdentityRoleClaimstringEntityType.CreateForeignKey1(identityRoleClaimstring, identityRole); + IdentityUserClaimstringEntityType.CreateForeignKey1(identityUserClaimstring, pizzaStoreUser); + IdentityUserLoginstringEntityType.CreateForeignKey1(identityUserLoginstring, pizzaStoreUser); + IdentityUserRolestringEntityType.CreateForeignKey1(identityUserRolestring, identityRole); + IdentityUserRolestringEntityType.CreateForeignKey2(identityUserRolestring, pizzaStoreUser); + IdentityUserTokenstringEntityType.CreateForeignKey1(identityUserTokenstring, pizzaStoreUser); + + AddressEntityType.CreateAnnotations(address); + LatLongEntityType.CreateAnnotations(latLong); + NotificationSubscriptionEntityType.CreateAnnotations(notificationSubscription); + OrderEntityType.CreateAnnotations(order); + PizzaEntityType.CreateAnnotations(pizza); + PizzaSpecialEntityType.CreateAnnotations(pizzaSpecial); + PizzaToppingEntityType.CreateAnnotations(pizzaTopping); + PizzaStoreUserEntityType.CreateAnnotations(pizzaStoreUser); + ToppingEntityType.CreateAnnotations(topping); + DeviceFlowCodesEntityType.CreateAnnotations(deviceFlowCodes); + KeyEntityType.CreateAnnotations(key); + PersistedGrantEntityType.CreateAnnotations(persistedGrant); + IdentityRoleEntityType.CreateAnnotations(identityRole); + IdentityRoleClaimstringEntityType.CreateAnnotations(identityRoleClaimstring); + IdentityUserClaimstringEntityType.CreateAnnotations(identityUserClaimstring); + IdentityUserLoginstringEntityType.CreateAnnotations(identityUserLoginstring); + IdentityUserRolestringEntityType.CreateAnnotations(identityUserRolestring); + IdentityUserTokenstringEntityType.CreateAnnotations(identityUserTokenstring); + + AddAnnotation("ProductVersion", "6.0.0"); + } + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs new file mode 100644 index 00000000..18b2d96d --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs @@ -0,0 +1,156 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaStoreUserEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Server.PizzaStoreUser", + typeof(PizzaStoreUser), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var accessFailedCount = runtimeEntityType.AddProperty( + "AccessFailedCount", + typeof(int), + propertyInfo: typeof(IdentityUser).GetProperty("AccessFailedCount", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var email = runtimeEntityType.AddProperty( + "Email", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Email", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var emailConfirmed = runtimeEntityType.AddProperty( + "EmailConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("EmailConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnabled = runtimeEntityType.AddProperty( + "LockoutEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnd = runtimeEntityType.AddProperty( + "LockoutEnd", + typeof(DateTimeOffset?), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnd", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var normalizedEmail = runtimeEntityType.AddProperty( + "NormalizedEmail", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedEmail", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedUserName = runtimeEntityType.AddProperty( + "NormalizedUserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedUserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var passwordHash = runtimeEntityType.AddProperty( + "PasswordHash", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PasswordHash", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumber = runtimeEntityType.AddProperty( + "PhoneNumber", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumber", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumberConfirmed = runtimeEntityType.AddProperty( + "PhoneNumberConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumberConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var securityStamp = runtimeEntityType.AddProperty( + "SecurityStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("SecurityStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var twoFactorEnabled = runtimeEntityType.AddProperty( + "TwoFactorEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("TwoFactorEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var userName = runtimeEntityType.AddProperty( + "UserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("UserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedEmail }); + index.AddAnnotation("Relational:Name", "EmailIndex"); + + var index0 = runtimeEntityType.AddIndex( + new[] { normalizedUserName }, + unique: true); + index0.AddAnnotation("Relational:Name", "UserNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUsers"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaToppingEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaToppingEntityType.cs new file mode 100644 index 00000000..b97d2a24 --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/PizzaToppingEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaTopping", + typeof(PizzaTopping), + baseEntityType); + + var pizzaId = runtimeEntityType.AddProperty( + "PizzaId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("PizzaId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var toppingId = runtimeEntityType.AddProperty( + "ToppingId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("ToppingId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { pizzaId, toppingId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { toppingId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("PizzaId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var toppings = principalEntityType.AddNavigation("Toppings", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Pizza).GetProperty("Toppings", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("ToppingId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var topping = declaringEntityType.AddNavigation("Topping", + runtimeForeignKey, + onDependent: true, + typeof(Topping), + propertyInfo: typeof(PizzaTopping).GetProperty("Topping", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PizzaTopping"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Models/ToppingEntityType.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/ToppingEntityType.cs new file mode 100644 index 00000000..9295f9bf --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Models/ToppingEntityType.cs @@ -0,0 +1,62 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class ToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Topping", + typeof(Topping), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Topping).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Topping).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var price = runtimeEntityType.AddProperty( + "Price", + typeof(decimal), + propertyInfo: typeof(Topping).GetProperty("Price", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Toppings"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/NotificationsController.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/NotificationsController.cs deleted file mode 100644 index bb3b96ff..00000000 --- a/save-points/04-refactor-state-management/BlazingPizza.Server/NotificationsController.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("notifications")] - [ApiController] - [Authorize] - public class NotificationsController : Controller - { - private readonly PizzaStoreContext _db; - - public NotificationsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpPut("subscribe")] - public async Task Subscribe(NotificationSubscription subscription) - { - // We're storing at most one subscription per user, so delete old ones. - // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. - var userId = GetUserId(); - var oldSubscriptions = _db.NotificationSubscriptions.Where(e => e.UserId == userId); - _db.NotificationSubscriptions.RemoveRange(oldSubscriptions); - - // Store new subscription - subscription.UserId = userId; - _db.NotificationSubscriptions.Attach(subscription); - - await _db.SaveChangesAsync(); - return subscription; - } - - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } - } -} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/OidcConfigurationController.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/OidcConfigurationController.cs index c074debf..1431697e 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Server/OidcConfigurationController.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/OidcConfigurationController.cs @@ -1,26 +1,21 @@ using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class OidcConfigurationController : Controller { - public class OidcConfigurationController : Controller + public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) { - public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) - { - ClientRequestParametersProvider = clientRequestParametersProvider; - } + ClientRequestParametersProvider = clientRequestParametersProvider; + } - public IClientRequestParametersProvider ClientRequestParametersProvider { get; } + public IClientRequestParametersProvider ClientRequestParametersProvider { get; } - [HttpGet("_configuration/{clientId}")] - public IActionResult GetClientRequestParameters([FromRoute]string clientId) - { - var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); - return Ok(parameters); - } + [HttpGet("_configuration/{clientId}")] + public IActionResult GetClientRequestParameters([FromRoute] string clientId) + { + var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); + return Ok(parameters); } } diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/OrdersController.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/OrdersController.cs index 2b8bc99b..308f3f64 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Server/OrdersController.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/OrdersController.cs @@ -1,114 +1,130 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; +using System.Security.Claims; +using System.Text.Json; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using WebPush; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +[Route("orders")] +[ApiController] +// [Authorize] +public class OrdersController : Controller { - [Route("orders")] - [ApiController] - // [Authorize] - public class OrdersController : Controller - { - private readonly PizzaStoreContext _db; + private readonly PizzaStoreContext _db; - public OrdersController(PizzaStoreContext db) - { - _db = db; - } + public OrdersController(PizzaStoreContext db) + { + _db = db; + } - [HttpGet] - public async Task>> GetOrders() - { - var orders = await _db.Orders - // .Where(o => o.UserId == GetUserId()) + [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(); - } + return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); + } - [HttpGet("{orderId}")] - public async Task> GetOrderWithStatus(int orderId) - { - var order = await _db.Orders + [HttpGet("{orderId}")] + public async Task> GetOrderWithStatus(int orderId) + { + var order = await _db.Orders .Where(o => o.OrderId == orderId) - // .Where(o => o.UserId == GetUserId()) + .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); + if (order == null) + { + return NotFound(); } - [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; - } - } + return OrderWithStatus.FromOrder(order); + } - _db.Orders.Attach(order); - await _db.SaveChangesAsync(); + [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; - // In the background, send push notifications if possible - var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); - if (subscription != null) + foreach (var topping in pizza.Toppings) { - _ = TrackAndSendNotificationsAsync(order, subscription); + topping.ToppingId = topping.Topping.Id; + topping.Topping = null; } - - return order.OrderId; } - private string GetUserId() + _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) { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); + _ = TrackAndSendNotificationsAsync(order, subscription); } - private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription 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 { - // 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!"); + var payload = JsonSerializer.Serialize(new + { + message, + url = $"myorders/{order.OrderId}", + }); + await webPushClient.SendNotificationAsync(pushSubscription, payload, vapidDetails); } - - private static Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) + catch (Exception ex) { - // This will be implemented later - return Task.CompletedTask; + Console.Error.WriteLine("Error sending push notification: " + ex.Message); } } } diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/PizzaApiExtensions.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/PizzaApiExtensions.cs new file mode 100644 index 00000000..524ca759 --- /dev/null +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/PizzaApiExtensions.cs @@ -0,0 +1,57 @@ +using System.Security.Claims; +using Microsoft.AspNetCore.Authorization; +using Microsoft.EntityFrameworkCore; + +namespace BlazingPizza.Server; + +public static class PizzaApiExtensions +{ + + public static WebApplication MapPizzaApi(this WebApplication app) + { + + // Subscribe to notifications + app.MapPut("/notifications/subscribe", [Authorize] async ( + HttpContext context, + PizzaStoreContext db, + NotificationSubscription subscription) => { + + // We're storing at most one subscription per user, so delete old ones. + // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. + var userId = GetUserId(context); + var oldSubscriptions = db.NotificationSubscriptions.Where(e => e.UserId == userId); + db.NotificationSubscriptions.RemoveRange(oldSubscriptions); + + // Store new subscription + subscription.UserId = userId; + db.NotificationSubscriptions.Attach(subscription); + + await db.SaveChangesAsync(); + return Results.Ok(subscription); + + }); + + // Specials + app.MapGet("/specials", async (PizzaStoreContext db) => { + + var specials = await db.Specials.ToListAsync(); + return Results.Ok(specials); + + }); + + // Toppings + app.MapGet("/toppings", async (PizzaStoreContext db) => { + var toppings = await db.Toppings.OrderBy(t => t.Name).ToListAsync(); + return Results.Ok(toppings); + }); + + return app; + + } + + private static string GetUserId(HttpContext context) + { + return context.User.FindFirstValue(ClaimTypes.NameIdentifier); + } + +} \ No newline at end of file diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/PizzaStoreContext.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/PizzaStoreContext.cs index f79c1c66..50ac87e4 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Server/PizzaStoreContext.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/PizzaStoreContext.cs @@ -1,39 +1,38 @@ -using IdentityServer4.EntityFramework.Options; +using Duende.IdentityServer.EntityFramework.Options; using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class PizzaStoreContext : ApiAuthorizationDbContext { - public class PizzaStoreContext : ApiAuthorizationDbContext - { - public PizzaStoreContext( + 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/04-refactor-state-management/BlazingPizza.Server/PizzaStoreUser.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/PizzaStoreUser.cs index 171ce83d..7ab40235 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Server/PizzaStoreUser.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/PizzaStoreUser.cs @@ -1,8 +1,5 @@ using Microsoft.AspNetCore.Identity; -namespace BlazingPizza.Server -{ - public class PizzaStoreUser : IdentityUser - { - } -} \ No newline at end of file +namespace BlazingPizza.Server; + +public class PizzaStoreUser : IdentityUser { } \ No newline at end of file diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/PizzasController.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/PizzasController.cs deleted file mode 100644 index c082552c..00000000 --- a/save-points/04-refactor-state-management/BlazingPizza.Server/PizzasController.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("pizzas")] - [ApiController] - public class PizzasController : Controller - { - private readonly PizzaStoreContext _db; - - public PizzasController(PizzaStoreContext db) - { - _db = db; - } - } -} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Program.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Program.cs index 40a47641..b83debb4 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Server/Program.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/Program.cs @@ -1,33 +1,67 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; +using BlazingPizza.Server; +using Microsoft.AspNetCore.Authentication; +using Microsoft.EntityFrameworkCore; -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()) { - public class Program + var db = scope.ServiceProvider.GetRequiredService(); + if (db.Database.EnsureCreated()) { - 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(); - }); + SeedData.Initialize(db); } } + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + 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.MapPizzaApi(); + +app.MapRazorPages(); +app.MapControllers(); +app.MapFallbackToFile("index.html"); + +app.Run(); \ No newline at end of file diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/SeedData.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/SeedData.cs index 7c86a5b2..f02e2b77 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Server/SeedData.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Server/SeedData.cs @@ -1,193 +1,192 @@ -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public static class SeedData { - public static class SeedData + public static void Initialize(PizzaStoreContext db) { - public static void Initialize(PizzaStoreContext db) + var toppings = new Topping[] { - var toppings = new Topping[] + new Topping() { - new Topping() - { Name = "Extra cheese", Price = 2.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "American bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "British bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Canadian bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Tea and crumpets", Price = 5.00m - }, - new Topping() - { + }, + new Topping() + { Name = "Fresh-baked scones", Price = 4.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Bell peppers", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Onions", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Mushrooms", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Pepperoni", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Duck sausage", Price = 3.20m, - }, - new Topping() - { + }, + new Topping() + { Name = "Venison meatballs", Price = 2.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Served on a silver platter", Price = 250.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Lobster on top", Price = 64.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Sturgeon caviar", Price = 101.75m, - }, - new Topping() - { + }, + new Topping() + { Name = "Artichoke hearts", Price = 3.40m, - }, - new Topping() - { + }, + new Topping() + { Name = "Fresh tomatoes", Price = 1.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Basil", Price = 1.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Steak (medium-rare)", Price = 8.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Blazing hot peppers", Price = 4.20m, - }, - new Topping() - { + }, + new Topping() + { Name = "Buffalo chicken", Price = 5.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Blue cheese", Price = 2.50m, - }, - }; + }, + }; - var specials = new PizzaSpecial[] + var specials = new PizzaSpecial[] + { + 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() - { + }, + new PizzaSpecial() + { Id = 2, Name = "The Baconatorizor", Description = "It has EVERY kind of bacon", BasePrice = 11.99m, ImageUrl = "img/pizzas/bacon.jpg", - }, - new PizzaSpecial() - { + }, + 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() - { + }, + 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() - { + }, + 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() - { + }, + new PizzaSpecial() + { Id = 6, Name = "The Brit", Description = "When in London...", BasePrice = 10.25m, ImageUrl = "img/pizzas/brit.jpg", - }, - new PizzaSpecial() - { + }, + 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() - { + }, + new PizzaSpecial() + { Id = 8, Name = "Margherita", Description = "Traditional Italian pizza with tomatoes and basil", BasePrice = 9.99m, ImageUrl = "img/pizzas/margherita.jpg", - }, - }; + }, + }; - db.Toppings.AddRange(toppings); - db.Specials.AddRange(specials); - db.SaveChanges(); - } + db.Toppings.AddRange(toppings); + db.Specials.AddRange(specials); + db.SaveChanges(); } -} +} \ No newline at end of file diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/SpecialsController.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/SpecialsController.cs deleted file mode 100644 index a176844c..00000000 --- a/save-points/04-refactor-state-management/BlazingPizza.Server/SpecialsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("specials")] - [ApiController] - public class SpecialsController : Controller - { - private readonly PizzaStoreContext _db; - - public SpecialsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetSpecials() - { - return (await _db.Specials.ToListAsync()).OrderByDescending(s => s.BasePrice).ToList(); - } - } -} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/Startup.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/Startup.cs deleted file mode 100644 index ed3fca06..00000000 --- a/save-points/04-refactor-state-management/BlazingPizza.Server/Startup.cs +++ /dev/null @@ -1,70 +0,0 @@ -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace BlazingPizza.Server -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - public void ConfigureServices(IServiceCollection services) - { - services.AddControllersWithViews(); - services.AddRazorPages(); - - services.AddDbContext(options => - options.UseSqlite("Data Source=pizza.db")); - - services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) - .AddEntityFrameworkStores(); - - services.AddIdentityServer() - .AddApiAuthorization(); - - services.AddAuthentication() - .AddIdentityServerJwt(); - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - app.UseWebAssemblyDebugging(); - } - else - { - app.UseExceptionHandler("/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); - } - - app.UseHttpsRedirection(); - app.UseBlazorFrameworkFiles(); - app.UseStaticFiles(); - - app.UseRouting(); - - app.UseAuthentication(); - app.UseIdentityServer(); - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - endpoints.MapRazorPages(); - endpoints.MapFallbackToFile("index.html"); - }); - } - } -} \ No newline at end of file diff --git a/save-points/04-refactor-state-management/BlazingPizza.Server/ToppingsController.cs b/save-points/04-refactor-state-management/BlazingPizza.Server/ToppingsController.cs deleted file mode 100644 index 6a677639..00000000 --- a/save-points/04-refactor-state-management/BlazingPizza.Server/ToppingsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("toppings")] - [ApiController] - public class ToppingsController : Controller - { - private readonly PizzaStoreContext _db; - - public ToppingsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetToppings() - { - return await _db.Toppings.OrderBy(t => t.Name).ToListAsync(); - } - } -} diff --git a/save-points/04-refactor-state-management/BlazingPizza.Shared/Address.cs b/save-points/04-refactor-state-management/BlazingPizza.Shared/Address.cs index e5c0ef0d..309438b7 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Shared/Address.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Shared/Address.cs @@ -1,21 +1,26 @@ using System.ComponentModel.DataAnnotations; -namespace BlazingPizza +namespace BlazingPizza; + +public class Address { - public class Address - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + [Required, MaxLength(100)] + public string Name { get; set; } - public string Line1 { get; set; } + [Required, MaxLength(100)] + public string Line1 { get; set; } - public string Line2 { get; set; } + [MaxLength(100)] + public string Line2 { get; set; } - public string City { get; set; } + [Required, MaxLength(50)] + public string City { get; set; } - public string Region { get; set; } + [Required, MaxLength(20)] + public string Region { get; set; } - public string PostalCode { get; set; } - } + [Required, MaxLength(20)] + public string PostalCode { get; set; } } diff --git a/save-points/04-refactor-state-management/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/save-points/04-refactor-state-management/BlazingPizza.Shared/BlazingPizza.Shared.csproj index 911c57c5..075ddd60 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/save-points/04-refactor-state-management/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -1,8 +1,9 @@  - net5.0 + $(TargetFrameworkVersion) BlazingPizza + true diff --git a/save-points/04-refactor-state-management/BlazingPizza.Shared/LatLong.cs b/save-points/04-refactor-state-management/BlazingPizza.Shared/LatLong.cs index 9b8c3811..a65971f8 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Shared/LatLong.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Shared/LatLong.cs @@ -1,27 +1,26 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class LatLong { - public class LatLong + public LatLong() { - public LatLong() - { - } + } - public LatLong(double latitude, double longitude) : this() - { - Latitude = latitude; - Longitude = longitude; - } + public LatLong(double latitude, double longitude) : this() + { + Latitude = latitude; + Longitude = longitude; + } - public double Latitude { get; set; } + public double Latitude { get; set; } - public double Longitude { get; set; } + public double Longitude { get; set; } - public static LatLong Interpolate(LatLong start, LatLong end, double proportion) - { - // The Earth is flat, right? So no need for spherical interpolation. - return new LatLong( + public static LatLong Interpolate(LatLong start, LatLong end, double proportion) + { + // The Earth is flat, right? So no need for spherical interpolation. + return new LatLong( start.Latitude + (end.Latitude - start.Latitude) * proportion, start.Longitude + (end.Longitude - start.Longitude) * proportion); - } } -} +} \ No newline at end of file diff --git a/save-points/04-refactor-state-management/BlazingPizza.Shared/NotificationSubscription.cs b/save-points/04-refactor-state-management/BlazingPizza.Shared/NotificationSubscription.cs index 04259c2f..5c99e3f4 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Shared/NotificationSubscription.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Shared/NotificationSubscription.cs @@ -1,17 +1,14 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class NotificationSubscription { - public class NotificationSubscription - { - public int NotificationSubscriptionId { get; set; } + public int NotificationSubscriptionId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public string Url { get; set; } + public string Url { get; set; } - public string P256dh { get; set; } + public string P256dh { get; set; } - public string Auth { get; set; } - } + public string Auth { get; set; } } diff --git a/save-points/04-refactor-state-management/BlazingPizza.Shared/Order.cs b/save-points/04-refactor-state-management/BlazingPizza.Shared/Order.cs index fb003bd6..b47efad0 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Shared/Order.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Shared/Order.cs @@ -1,25 +1,32 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +public class Order { - public class Order - { - public int OrderId { get; set; } + public int OrderId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public DateTime CreatedTime { get; set; } + public DateTime CreatedTime { get; set; } - public Address DeliveryAddress { get; set; } = new Address(); + public Address DeliveryAddress { get; set; } = new Address(); - public LatLong DeliveryLocation { get; set; } + public LatLong DeliveryLocation { get; set; } - public List Pizzas { get; set; } = new List(); + public List Pizzas { get; set; } = new List(); - public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); + public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); - public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); - } + public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Default, PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] +[JsonSerializable(typeof(Order))] +[JsonSerializable(typeof(OrderWithStatus))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Pizza))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Topping))] +public partial class OrderContext : JsonSerializerContext { } \ No newline at end of file diff --git a/save-points/04-refactor-state-management/BlazingPizza.Shared/OrderWithStatus.cs b/save-points/04-refactor-state-management/BlazingPizza.Shared/OrderWithStatus.cs index 021de78c..fbfac7af 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Shared/OrderWithStatus.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Shared/OrderWithStatus.cs @@ -1,79 +1,78 @@ -using BlazingPizza.ComponentsLibrary.Map; -using System; -using System.Collections.Generic; +using System.Text.Json.Serialization; +using BlazingPizza.ComponentsLibrary.Map; -namespace BlazingPizza -{ - 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 Order Order { get; set; } +namespace BlazingPizza; - public string StatusText { get; set; } +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 bool IsDelivered => StatusText == "Delivered"; + public Order Order { get; set; } - public List MapMarkers { get; set; } + public string StatusText { 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 bool IsDelivered => StatusText == "Delivered"; - 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"; + public List MapMarkers { get; set; } - 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), - }; - } + 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); - return new OrderWithStatus - { - Order = order, - StatusText = statusText, - MapMarkers = mapMarkers, - }; + 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"; - private static LatLong ComputeStartPosition(Order order) + 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 { - // 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); + statusText = "Delivered"; + mapMarkers = new List + { + ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), + }; } - static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) - => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; + 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); + } + + static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) + => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; +} \ No newline at end of file diff --git a/save-points/04-refactor-state-management/BlazingPizza.Shared/Pizza.cs b/save-points/04-refactor-state-management/BlazingPizza.Shared/Pizza.cs index ec1108a9..2a7a1c29 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Shared/Pizza.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Shared/Pizza.cs @@ -1,42 +1,44 @@ -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// /// Represents a customized pizza as part of an order +/// +public class Pizza { - /// - /// Represents a customized pizza as part of an order - /// - public class Pizza - { - public const int DefaultSize = 12; - public const int MinimumSize = 9; - public const int MaximumSize = 17; + public const int DefaultSize = 12; + public const int MinimumSize = 9; + public const int MaximumSize = 17; - public int Id { get; set; } + public int Id { get; set; } - public int OrderId { get; set; } + public int OrderId { get; set; } - public PizzaSpecial Special { get; set; } + public PizzaSpecial Special { get; set; } - public int SpecialId { get; set; } + public int SpecialId { get; set; } - public int Size { get; set; } + public int Size { get; set; } - public List Toppings { get; set; } + public List Toppings { get; set; } - public decimal GetBasePrice() - { - return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; - } + public decimal GetBasePrice() + { + return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; + } - public decimal GetTotalPrice() - { - return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); - } + public decimal GetTotalPrice() + { + return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); + } - public string GetFormattedTotalPrice() - { - return GetTotalPrice().ToString("0.00"); - } + public string GetFormattedTotalPrice() + { + return GetTotalPrice().ToString("0.00"); } } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Serialization)] +[JsonSerializable(typeof(Pizza))] +public partial class PizzaContext : JsonSerializerContext { } \ No newline at end of file diff --git a/save-points/04-refactor-state-management/BlazingPizza.Shared/PizzaSpecial.cs b/save-points/04-refactor-state-management/BlazingPizza.Shared/PizzaSpecial.cs index 2f2b3383..1fd9006a 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Shared/PizzaSpecial.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Shared/PizzaSpecial.cs @@ -1,20 +1,19 @@ -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// Represents a pre-configured template for a pizza a user can order +/// +public class PizzaSpecial { - /// - /// Represents a pre-configured template for a pizza a user can order - /// - public class PizzaSpecial - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal BasePrice { get; set; } + public decimal BasePrice { get; set; } - public string Description { get; set; } + public string Description { get; set; } - public string ImageUrl { get; set; } + public string ImageUrl { get; set; } - public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); - } -} + public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); +} \ No newline at end of file diff --git a/save-points/04-refactor-state-management/BlazingPizza.Shared/PizzaTopping.cs b/save-points/04-refactor-state-management/BlazingPizza.Shared/PizzaTopping.cs index f5a6c1ac..1c062732 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Shared/PizzaTopping.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Shared/PizzaTopping.cs @@ -1,11 +1,11 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class PizzaTopping { - public class PizzaTopping - { - public Topping Topping { get; set; } - - public int ToppingId { get; set; } - - public int PizzaId { get; set; } - } -} + public Topping Topping { get; set; } + + public int ToppingId { get; set; } + + public int PizzaId { get; set; } + +} \ No newline at end of file diff --git a/save-points/04-refactor-state-management/BlazingPizza.Shared/Topping.cs b/save-points/04-refactor-state-management/BlazingPizza.Shared/Topping.cs index 61bdeb92..4eb67ae9 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Shared/Topping.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Shared/Topping.cs @@ -1,13 +1,13 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class Topping { - public class Topping - { - public int Id { get; set; } + public int Id { get; set; } + + public string Name { get; set; } - public string Name { get; set; } + public decimal Price { get; set; } - public decimal Price { get; set; } + public string GetFormattedPrice() => Price.ToString("0.00"); - public string GetFormattedPrice() => Price.ToString("0.00"); - } -} +} \ No newline at end of file diff --git a/save-points/04-refactor-state-management/BlazingPizza.Shared/UserInfo.cs b/save-points/04-refactor-state-management/BlazingPizza.Shared/UserInfo.cs index 4996ef80..babb4315 100644 --- a/save-points/04-refactor-state-management/BlazingPizza.Shared/UserInfo.cs +++ b/save-points/04-refactor-state-management/BlazingPizza.Shared/UserInfo.cs @@ -1,9 +1,9 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class UserInfo { - public class UserInfo - { - public bool IsAuthenticated { get; set; } + public bool IsAuthenticated { get; set; } + + public string Name { get; set; } - public string Name { get; set; } - } -} +} \ No newline at end of file diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Client/BlazingPizza.Client.csproj b/save-points/05-checkout-with-validation/BlazingPizza.Client/BlazingPizza.Client.csproj index a833c6be..1847e754 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/save-points/05-checkout-with-validation/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -1,13 +1,15 @@  - net5.0 + $(TargetFrameworkVersion) + true + - + diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Client/OrderState.cs b/save-points/05-checkout-with-validation/BlazingPizza.Client/OrderState.cs index f44ac786..00dd3627 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Client/OrderState.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Client/OrderState.cs @@ -1,50 +1,52 @@ -using System.Collections.Generic; +namespace BlazingPizza.Client; -namespace BlazingPizza.Client +public class OrderState { - public class OrderState - { - public bool ShowingConfigureDialog { get; private set; } + public bool ShowingConfigureDialog { get; private set; } - public Pizza ConfiguringPizza { get; private set; } + public Pizza ConfiguringPizza { get; private set; } - public Order Order { get; private set; } = new Order(); + 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() + public void ShowConfigurePizzaDialog(PizzaSpecial special) + { + ConfiguringPizza = new Pizza() { - ConfiguringPizza = null; - ShowingConfigureDialog = false; - } + Special = special, + SpecialId = special.Id, + Size = Pizza.DefaultSize, + Toppings = new List(), + }; - public void ConfirmConfigurePizzaDialog() - { - Order.Pizzas.Add(ConfiguringPizza); - ConfiguringPizza = null; + ShowingConfigureDialog = true; + } - ShowingConfigureDialog = false; - } + public void CancelConfigurePizzaDialog() + { + ConfiguringPizza = null; + ShowingConfigureDialog = false; + } - public void RemoveConfiguredPizza(Pizza pizza) - { - Order.Pizzas.Remove(pizza); - } + public void ConfirmConfigurePizzaDialog() + { + Order.Pizzas.Add(ConfiguringPizza); + ConfiguringPizza = null; - public void ResetOrder() - { - Order = new Order(); - } + ShowingConfigureDialog = false; + } + + public void RemoveConfiguredPizza(Pizza pizza) + { + Order.Pizzas.Remove(pizza); + } + + public void ResetOrder() + { + Order = new Order(); + } + + public void ReplaceOrder(Order order) + { + Order = order; } } diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Client/Pages/Checkout.razor b/save-points/05-checkout-with-validation/BlazingPizza.Client/Pages/Checkout.razor index 4306f55f..78b3d148 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Client/Pages/Checkout.razor +++ b/save-points/05-checkout-with-validation/BlazingPizza.Client/Pages/Checkout.razor @@ -3,6 +3,8 @@ @inject HttpClient HttpClient @inject NavigationManager NavigationManager +Blazing Pizza - Checkout +
diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Client/Pages/MyOrders.razor b/save-points/05-checkout-with-validation/BlazingPizza.Client/Pages/MyOrders.razor index a4d5f14c..36d3902e 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Client/Pages/MyOrders.razor +++ b/save-points/05-checkout-with-validation/BlazingPizza.Client/Pages/MyOrders.razor @@ -1,6 +1,8 @@ @page "/myorders" @inject HttpClient HttpClient +Blazing Pizza - My Orders +
@if (ordersWithStatus == null) { diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Client/Pages/OrderDetails.razor b/save-points/05-checkout-with-validation/BlazingPizza.Client/Pages/OrderDetails.razor index 05d96c1e..25e06141 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Client/Pages/OrderDetails.razor +++ b/save-points/05-checkout-with-validation/BlazingPizza.Client/Pages/OrderDetails.razor @@ -3,6 +3,8 @@ @inject HttpClient HttpClient @implements IDisposable +Blazing Pizza - Order Details +
@if (invalidOrder) { diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Client/Program.cs b/save-points/05-checkout-with-validation/BlazingPizza.Client/Program.cs index e0c88943..97ace491 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Client/Program.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Client/Program.cs @@ -1,22 +1,12 @@ -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.Web; +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.RootComponents.Add("head::after"); - builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); - builder.Services.AddScoped(); +builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); +builder.Services.AddScoped(); - await builder.Build().RunAsync(); - } - } -} +await builder.Build().RunAsync(); diff --git a/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 5f51ee3c..cb996b1b 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -1,7 +1,8 @@  - net5.0 + $(TargetFrameworkVersion) + true diff --git a/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/LocalStorage.cs b/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/LocalStorage.cs index f36b098e..be8226ec 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/LocalStorage.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/LocalStorage.cs @@ -1,17 +1,15 @@ using Microsoft.JSInterop; -using System.Threading.Tasks; -namespace BlazingPizza.ComponentsLibrary +namespace BlazingPizza.ComponentsLibrary; + +public static class LocalStorage { - public static class LocalStorage - { - public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) + public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); - public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object 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) + public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key) => jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key); - } -} +} \ No newline at end of file diff --git a/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/Map/Marker.cs b/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/Map/Marker.cs index 63006067..b067719c 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/Map/Marker.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/Map/Marker.cs @@ -1,13 +1,12 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Marker { - public class Marker - { - public string Description { get; set; } + public string Description { get; set; } - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } + public double Y { get; set; } - public bool ShowPopup { get; set; } - } + public bool ShowPopup { get; set; } } diff --git a/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/Map/Point.cs b/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/Map/Point.cs index 03841826..34194163 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/Map/Point.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.ComponentsLibrary/Map/Point.cs @@ -1,9 +1,8 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Point { - public class Point - { - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } - } -} + public double Y { get; set; } +} \ No newline at end of file diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/BlazingPizza.Server.csproj b/save-points/05-checkout-with-validation/BlazingPizza.Server/BlazingPizza.Server.csproj index fd7e3c51..abd2317b 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -1,7 +1,8 @@  - net5.0 + $(TargetFrameworkVersion) + true @@ -13,6 +14,7 @@ + diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/AddressEntityType.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/AddressEntityType.cs new file mode 100644 index 00000000..82db81b6 --- /dev/null +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/AddressEntityType.cs @@ -0,0 +1,92 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class AddressEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Address", + typeof(Address), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Address).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var city = runtimeEntityType.AddProperty( + "City", + typeof(string), + propertyInfo: typeof(Address).GetProperty("City", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var line1 = runtimeEntityType.AddProperty( + "Line1", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line1", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var line2 = runtimeEntityType.AddProperty( + "Line2", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line2", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var postalCode = runtimeEntityType.AddProperty( + "PostalCode", + typeof(string), + propertyInfo: typeof(Address).GetProperty("PostalCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var region = runtimeEntityType.AddProperty( + "Region", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Region", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Address"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs new file mode 100644 index 00000000..1dd4563b --- /dev/null +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs @@ -0,0 +1,114 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class DeviceFlowCodesEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.DeviceFlowCodes", + typeof(DeviceFlowCodes), + baseEntityType); + + var userCode = runtimeEntityType.AddProperty( + "UserCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("UserCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var deviceCode = runtimeEntityType.AddProperty( + "DeviceCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("DeviceCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var key = runtimeEntityType.AddKey( + new[] { userCode }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deviceCode }, + unique: true); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "DeviceCodes"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs new file mode 100644 index 00000000..8946b261 --- /dev/null +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRoleClaim", + typeof(IdentityRoleClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoleClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/IdentityRoleEntityType.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/IdentityRoleEntityType.cs new file mode 100644 index 00000000..2f1fec2b --- /dev/null +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/IdentityRoleEntityType.cs @@ -0,0 +1,78 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRole", + typeof(IdentityRole), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedName = runtimeEntityType.AddProperty( + "NormalizedName", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("NormalizedName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedName }, + unique: true); + index.AddAnnotation("Relational:Name", "RoleNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs new file mode 100644 index 00000000..55418a1e --- /dev/null +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserClaim", + typeof(IdentityUserClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityUserClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs new file mode 100644 index 00000000..3ca029bd --- /dev/null +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserLoginstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserLogin", + typeof(IdentityUserLogin), + baseEntityType); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerKey = runtimeEntityType.AddProperty( + "ProviderKey", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderKey", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerDisplayName = runtimeEntityType.AddProperty( + "ProviderDisplayName", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderDisplayName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { loginProvider, providerKey }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserLogins"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs new file mode 100644 index 00000000..70078d7a --- /dev/null +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs @@ -0,0 +1,82 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserRolestringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserRole", + typeof(IdentityUserRole), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { userId, roleId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs new file mode 100644 index 00000000..93ba6d31 --- /dev/null +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs @@ -0,0 +1,84 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserTokenstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserToken", + typeof(IdentityUserToken), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var value = runtimeEntityType.AddProperty( + "Value", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Value", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { userId, loginProvider, name }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserTokens"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/KeyEntityType.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/KeyEntityType.cs new file mode 100644 index 00000000..f6c6b4c7 --- /dev/null +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/KeyEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class KeyEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.Key", + typeof(Key), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var algorithm = runtimeEntityType.AddProperty( + "Algorithm", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Algorithm", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var created = runtimeEntityType.AddProperty( + "Created", + typeof(DateTime), + propertyInfo: typeof(Key).GetProperty("Created", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var dataProtected = runtimeEntityType.AddProperty( + "DataProtected", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("DataProtected", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var isX509Certificate = runtimeEntityType.AddProperty( + "IsX509Certificate", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("IsX509Certificate", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var use = runtimeEntityType.AddProperty( + "Use", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Use", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var version = runtimeEntityType.AddProperty( + "Version", + typeof(int), + propertyInfo: typeof(Key).GetProperty("Version", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { use }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Keys"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/LatLongEntityType.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/LatLongEntityType.cs new file mode 100644 index 00000000..3fd254bd --- /dev/null +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/LatLongEntityType.cs @@ -0,0 +1,80 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class LatLongEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.LatLong", + typeof(LatLong), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var latitude = runtimeEntityType.AddProperty( + "Latitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Latitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var longitude = runtimeEntityType.AddProperty( + "Longitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Longitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + unique: true, + required: true, + ownership: true); + + var deliveryLocation = principalEntityType.AddNavigation("DeliveryLocation", + runtimeForeignKey, + onDependent: false, + typeof(LatLong), + propertyInfo: typeof(Order).GetProperty("DeliveryLocation", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + eagerLoaded: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs new file mode 100644 index 00000000..db236e4c --- /dev/null +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs @@ -0,0 +1,77 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class NotificationSubscriptionEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.NotificationSubscription", + typeof(NotificationSubscription), + baseEntityType); + + var notificationSubscriptionId = runtimeEntityType.AddProperty( + "NotificationSubscriptionId", + typeof(int), + propertyInfo: typeof(NotificationSubscription).GetProperty("NotificationSubscriptionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var auth = runtimeEntityType.AddProperty( + "Auth", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Auth", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var p256dh = runtimeEntityType.AddProperty( + "P256dh", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("P256dh", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var url = runtimeEntityType.AddProperty( + "Url", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Url", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { notificationSubscriptionId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "NotificationSubscriptions"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/OrderEntityType.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/OrderEntityType.cs new file mode 100644 index 00000000..9d9ec6fd --- /dev/null +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/OrderEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class OrderEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Order", + typeof(Order), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Order).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var createdTime = runtimeEntityType.AddProperty( + "CreatedTime", + typeof(DateTime), + propertyInfo: typeof(Order).GetProperty("CreatedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var deliveryAddressId = runtimeEntityType.AddProperty( + "DeliveryAddressId", + typeof(int?), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(Order).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deliveryAddressId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("DeliveryAddressId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType); + + var deliveryAddress = declaringEntityType.AddNavigation("DeliveryAddress", + runtimeForeignKey, + onDependent: true, + typeof(Address), + propertyInfo: typeof(Order).GetProperty("DeliveryAddress", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/PersistedGrantEntityType.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/PersistedGrantEntityType.cs new file mode 100644 index 00000000..842d53a5 --- /dev/null +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/PersistedGrantEntityType.cs @@ -0,0 +1,127 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PersistedGrantEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.PersistedGrant", + typeof(PersistedGrant), + baseEntityType); + + var key = runtimeEntityType.AddProperty( + "Key", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Key", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var consumedTime = runtimeEntityType.AddProperty( + "ConsumedTime", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("ConsumedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(PersistedGrant).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var type = runtimeEntityType.AddProperty( + "Type", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Type", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var key0 = runtimeEntityType.AddKey( + new[] { key }); + runtimeEntityType.SetPrimaryKey(key0); + + var index = runtimeEntityType.AddIndex( + new[] { consumedTime }); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + var index1 = runtimeEntityType.AddIndex( + new[] { subjectId, clientId, type }); + + var index2 = runtimeEntityType.AddIndex( + new[] { subjectId, sessionId, type }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PersistedGrants"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/PizzaEntityType.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/PizzaEntityType.cs new file mode 100644 index 00000000..3a124e63 --- /dev/null +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/PizzaEntityType.cs @@ -0,0 +1,111 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Pizza", + typeof(Pizza), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var size = runtimeEntityType.AddProperty( + "Size", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Size", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var specialId = runtimeEntityType.AddProperty( + "SpecialId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("SpecialId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { orderId }); + + var index0 = runtimeEntityType.AddIndex( + new[] { specialId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var pizzas = principalEntityType.AddNavigation("Pizzas", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Order).GetProperty("Pizzas", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("SpecialId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var special = declaringEntityType.AddNavigation("Special", + runtimeForeignKey, + onDependent: true, + typeof(PizzaSpecial), + propertyInfo: typeof(Pizza).GetProperty("Special", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Pizzas"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs new file mode 100644 index 00000000..e86b0f50 --- /dev/null +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs @@ -0,0 +1,76 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaSpecialEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaSpecial", + typeof(PizzaSpecial), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(PizzaSpecial).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var basePrice = runtimeEntityType.AddProperty( + "BasePrice", + typeof(decimal), + propertyInfo: typeof(PizzaSpecial).GetProperty("BasePrice", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var imageUrl = runtimeEntityType.AddProperty( + "ImageUrl", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("ImageUrl", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Specials"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/PizzaStoreContextModel.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/PizzaStoreContextModel.cs new file mode 100644 index 00000000..8b516a68 --- /dev/null +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/PizzaStoreContextModel.cs @@ -0,0 +1,28 @@ +// +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + [DbContext(typeof(PizzaStoreContext))] + public partial class PizzaStoreContextModel : RuntimeModel + { + static PizzaStoreContextModel() + { + var model = new PizzaStoreContextModel(); + model.Initialize(); + model.Customize(); + _instance = model; + } + + private static PizzaStoreContextModel _instance; + public static IModel Instance => _instance; + + partial void Initialize(); + + partial void Customize(); + } +} diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs new file mode 100644 index 00000000..d46f50f4 --- /dev/null +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs @@ -0,0 +1,69 @@ +// +using System; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + public partial class PizzaStoreContextModel + { + partial void Initialize() + { + var address = AddressEntityType.Create(this); + var latLong = LatLongEntityType.Create(this); + var notificationSubscription = NotificationSubscriptionEntityType.Create(this); + var order = OrderEntityType.Create(this); + var pizza = PizzaEntityType.Create(this); + var pizzaSpecial = PizzaSpecialEntityType.Create(this); + var pizzaTopping = PizzaToppingEntityType.Create(this); + var pizzaStoreUser = PizzaStoreUserEntityType.Create(this); + var topping = ToppingEntityType.Create(this); + var deviceFlowCodes = DeviceFlowCodesEntityType.Create(this); + var key = KeyEntityType.Create(this); + var persistedGrant = PersistedGrantEntityType.Create(this); + var identityRole = IdentityRoleEntityType.Create(this); + var identityRoleClaimstring = IdentityRoleClaimstringEntityType.Create(this); + var identityUserClaimstring = IdentityUserClaimstringEntityType.Create(this); + var identityUserLoginstring = IdentityUserLoginstringEntityType.Create(this); + var identityUserRolestring = IdentityUserRolestringEntityType.Create(this); + var identityUserTokenstring = IdentityUserTokenstringEntityType.Create(this); + + LatLongEntityType.CreateForeignKey1(latLong, order); + OrderEntityType.CreateForeignKey1(order, address); + PizzaEntityType.CreateForeignKey1(pizza, order); + PizzaEntityType.CreateForeignKey2(pizza, pizzaSpecial); + PizzaToppingEntityType.CreateForeignKey1(pizzaTopping, pizza); + PizzaToppingEntityType.CreateForeignKey2(pizzaTopping, topping); + IdentityRoleClaimstringEntityType.CreateForeignKey1(identityRoleClaimstring, identityRole); + IdentityUserClaimstringEntityType.CreateForeignKey1(identityUserClaimstring, pizzaStoreUser); + IdentityUserLoginstringEntityType.CreateForeignKey1(identityUserLoginstring, pizzaStoreUser); + IdentityUserRolestringEntityType.CreateForeignKey1(identityUserRolestring, identityRole); + IdentityUserRolestringEntityType.CreateForeignKey2(identityUserRolestring, pizzaStoreUser); + IdentityUserTokenstringEntityType.CreateForeignKey1(identityUserTokenstring, pizzaStoreUser); + + AddressEntityType.CreateAnnotations(address); + LatLongEntityType.CreateAnnotations(latLong); + NotificationSubscriptionEntityType.CreateAnnotations(notificationSubscription); + OrderEntityType.CreateAnnotations(order); + PizzaEntityType.CreateAnnotations(pizza); + PizzaSpecialEntityType.CreateAnnotations(pizzaSpecial); + PizzaToppingEntityType.CreateAnnotations(pizzaTopping); + PizzaStoreUserEntityType.CreateAnnotations(pizzaStoreUser); + ToppingEntityType.CreateAnnotations(topping); + DeviceFlowCodesEntityType.CreateAnnotations(deviceFlowCodes); + KeyEntityType.CreateAnnotations(key); + PersistedGrantEntityType.CreateAnnotations(persistedGrant); + IdentityRoleEntityType.CreateAnnotations(identityRole); + IdentityRoleClaimstringEntityType.CreateAnnotations(identityRoleClaimstring); + IdentityUserClaimstringEntityType.CreateAnnotations(identityUserClaimstring); + IdentityUserLoginstringEntityType.CreateAnnotations(identityUserLoginstring); + IdentityUserRolestringEntityType.CreateAnnotations(identityUserRolestring); + IdentityUserTokenstringEntityType.CreateAnnotations(identityUserTokenstring); + + AddAnnotation("ProductVersion", "6.0.0"); + } + } +} diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs new file mode 100644 index 00000000..18b2d96d --- /dev/null +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs @@ -0,0 +1,156 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaStoreUserEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Server.PizzaStoreUser", + typeof(PizzaStoreUser), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var accessFailedCount = runtimeEntityType.AddProperty( + "AccessFailedCount", + typeof(int), + propertyInfo: typeof(IdentityUser).GetProperty("AccessFailedCount", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var email = runtimeEntityType.AddProperty( + "Email", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Email", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var emailConfirmed = runtimeEntityType.AddProperty( + "EmailConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("EmailConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnabled = runtimeEntityType.AddProperty( + "LockoutEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnd = runtimeEntityType.AddProperty( + "LockoutEnd", + typeof(DateTimeOffset?), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnd", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var normalizedEmail = runtimeEntityType.AddProperty( + "NormalizedEmail", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedEmail", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedUserName = runtimeEntityType.AddProperty( + "NormalizedUserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedUserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var passwordHash = runtimeEntityType.AddProperty( + "PasswordHash", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PasswordHash", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumber = runtimeEntityType.AddProperty( + "PhoneNumber", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumber", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumberConfirmed = runtimeEntityType.AddProperty( + "PhoneNumberConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumberConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var securityStamp = runtimeEntityType.AddProperty( + "SecurityStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("SecurityStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var twoFactorEnabled = runtimeEntityType.AddProperty( + "TwoFactorEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("TwoFactorEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var userName = runtimeEntityType.AddProperty( + "UserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("UserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedEmail }); + index.AddAnnotation("Relational:Name", "EmailIndex"); + + var index0 = runtimeEntityType.AddIndex( + new[] { normalizedUserName }, + unique: true); + index0.AddAnnotation("Relational:Name", "UserNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUsers"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/PizzaToppingEntityType.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/PizzaToppingEntityType.cs new file mode 100644 index 00000000..b97d2a24 --- /dev/null +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/PizzaToppingEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaTopping", + typeof(PizzaTopping), + baseEntityType); + + var pizzaId = runtimeEntityType.AddProperty( + "PizzaId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("PizzaId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var toppingId = runtimeEntityType.AddProperty( + "ToppingId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("ToppingId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { pizzaId, toppingId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { toppingId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("PizzaId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var toppings = principalEntityType.AddNavigation("Toppings", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Pizza).GetProperty("Toppings", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("ToppingId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var topping = declaringEntityType.AddNavigation("Topping", + runtimeForeignKey, + onDependent: true, + typeof(Topping), + propertyInfo: typeof(PizzaTopping).GetProperty("Topping", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PizzaTopping"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/ToppingEntityType.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/ToppingEntityType.cs new file mode 100644 index 00000000..9295f9bf --- /dev/null +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/Models/ToppingEntityType.cs @@ -0,0 +1,62 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class ToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Topping", + typeof(Topping), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Topping).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Topping).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var price = runtimeEntityType.AddProperty( + "Price", + typeof(decimal), + propertyInfo: typeof(Topping).GetProperty("Price", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Toppings"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/NotificationsController.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/NotificationsController.cs deleted file mode 100644 index bb3b96ff..00000000 --- a/save-points/05-checkout-with-validation/BlazingPizza.Server/NotificationsController.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("notifications")] - [ApiController] - [Authorize] - public class NotificationsController : Controller - { - private readonly PizzaStoreContext _db; - - public NotificationsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpPut("subscribe")] - public async Task Subscribe(NotificationSubscription subscription) - { - // We're storing at most one subscription per user, so delete old ones. - // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. - var userId = GetUserId(); - var oldSubscriptions = _db.NotificationSubscriptions.Where(e => e.UserId == userId); - _db.NotificationSubscriptions.RemoveRange(oldSubscriptions); - - // Store new subscription - subscription.UserId = userId; - _db.NotificationSubscriptions.Attach(subscription); - - await _db.SaveChangesAsync(); - return subscription; - } - - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } - } -} diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/OidcConfigurationController.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/OidcConfigurationController.cs index c074debf..1431697e 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Server/OidcConfigurationController.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/OidcConfigurationController.cs @@ -1,26 +1,21 @@ using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class OidcConfigurationController : Controller { - public class OidcConfigurationController : Controller + public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) { - public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) - { - ClientRequestParametersProvider = clientRequestParametersProvider; - } + ClientRequestParametersProvider = clientRequestParametersProvider; + } - public IClientRequestParametersProvider ClientRequestParametersProvider { get; } + public IClientRequestParametersProvider ClientRequestParametersProvider { get; } - [HttpGet("_configuration/{clientId}")] - public IActionResult GetClientRequestParameters([FromRoute]string clientId) - { - var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); - return Ok(parameters); - } + [HttpGet("_configuration/{clientId}")] + public IActionResult GetClientRequestParameters([FromRoute] string clientId) + { + var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); + return Ok(parameters); } } diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/OrdersController.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/OrdersController.cs index 2b8bc99b..308f3f64 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Server/OrdersController.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/OrdersController.cs @@ -1,114 +1,130 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; +using System.Security.Claims; +using System.Text.Json; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using WebPush; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +[Route("orders")] +[ApiController] +// [Authorize] +public class OrdersController : Controller { - [Route("orders")] - [ApiController] - // [Authorize] - public class OrdersController : Controller - { - private readonly PizzaStoreContext _db; + private readonly PizzaStoreContext _db; - public OrdersController(PizzaStoreContext db) - { - _db = db; - } + public OrdersController(PizzaStoreContext db) + { + _db = db; + } - [HttpGet] - public async Task>> GetOrders() - { - var orders = await _db.Orders - // .Where(o => o.UserId == GetUserId()) + [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(); - } + return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); + } - [HttpGet("{orderId}")] - public async Task> GetOrderWithStatus(int orderId) - { - var order = await _db.Orders + [HttpGet("{orderId}")] + public async Task> GetOrderWithStatus(int orderId) + { + var order = await _db.Orders .Where(o => o.OrderId == orderId) - // .Where(o => o.UserId == GetUserId()) + .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); + if (order == null) + { + return NotFound(); } - [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; - } - } + return OrderWithStatus.FromOrder(order); + } - _db.Orders.Attach(order); - await _db.SaveChangesAsync(); + [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; - // In the background, send push notifications if possible - var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); - if (subscription != null) + foreach (var topping in pizza.Toppings) { - _ = TrackAndSendNotificationsAsync(order, subscription); + topping.ToppingId = topping.Topping.Id; + topping.Topping = null; } - - return order.OrderId; } - private string GetUserId() + _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) { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); + _ = TrackAndSendNotificationsAsync(order, subscription); } - private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription 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 { - // 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!"); + var payload = JsonSerializer.Serialize(new + { + message, + url = $"myorders/{order.OrderId}", + }); + await webPushClient.SendNotificationAsync(pushSubscription, payload, vapidDetails); } - - private static Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) + catch (Exception ex) { - // This will be implemented later - return Task.CompletedTask; + Console.Error.WriteLine("Error sending push notification: " + ex.Message); } } } diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/PizzaApiExtensions.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/PizzaApiExtensions.cs new file mode 100644 index 00000000..524ca759 --- /dev/null +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/PizzaApiExtensions.cs @@ -0,0 +1,57 @@ +using System.Security.Claims; +using Microsoft.AspNetCore.Authorization; +using Microsoft.EntityFrameworkCore; + +namespace BlazingPizza.Server; + +public static class PizzaApiExtensions +{ + + public static WebApplication MapPizzaApi(this WebApplication app) + { + + // Subscribe to notifications + app.MapPut("/notifications/subscribe", [Authorize] async ( + HttpContext context, + PizzaStoreContext db, + NotificationSubscription subscription) => { + + // We're storing at most one subscription per user, so delete old ones. + // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. + var userId = GetUserId(context); + var oldSubscriptions = db.NotificationSubscriptions.Where(e => e.UserId == userId); + db.NotificationSubscriptions.RemoveRange(oldSubscriptions); + + // Store new subscription + subscription.UserId = userId; + db.NotificationSubscriptions.Attach(subscription); + + await db.SaveChangesAsync(); + return Results.Ok(subscription); + + }); + + // Specials + app.MapGet("/specials", async (PizzaStoreContext db) => { + + var specials = await db.Specials.ToListAsync(); + return Results.Ok(specials); + + }); + + // Toppings + app.MapGet("/toppings", async (PizzaStoreContext db) => { + var toppings = await db.Toppings.OrderBy(t => t.Name).ToListAsync(); + return Results.Ok(toppings); + }); + + return app; + + } + + private static string GetUserId(HttpContext context) + { + return context.User.FindFirstValue(ClaimTypes.NameIdentifier); + } + +} \ No newline at end of file diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/PizzaStoreContext.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/PizzaStoreContext.cs index f79c1c66..50ac87e4 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Server/PizzaStoreContext.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/PizzaStoreContext.cs @@ -1,39 +1,38 @@ -using IdentityServer4.EntityFramework.Options; +using Duende.IdentityServer.EntityFramework.Options; using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class PizzaStoreContext : ApiAuthorizationDbContext { - public class PizzaStoreContext : ApiAuthorizationDbContext - { - public PizzaStoreContext( + 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/05-checkout-with-validation/BlazingPizza.Server/PizzaStoreUser.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/PizzaStoreUser.cs index 171ce83d..7ab40235 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Server/PizzaStoreUser.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/PizzaStoreUser.cs @@ -1,8 +1,5 @@ using Microsoft.AspNetCore.Identity; -namespace BlazingPizza.Server -{ - public class PizzaStoreUser : IdentityUser - { - } -} \ No newline at end of file +namespace BlazingPizza.Server; + +public class PizzaStoreUser : IdentityUser { } \ No newline at end of file diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/PizzasController.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/PizzasController.cs deleted file mode 100644 index c082552c..00000000 --- a/save-points/05-checkout-with-validation/BlazingPizza.Server/PizzasController.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("pizzas")] - [ApiController] - public class PizzasController : Controller - { - private readonly PizzaStoreContext _db; - - public PizzasController(PizzaStoreContext db) - { - _db = db; - } - } -} diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/Program.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/Program.cs index 40a47641..b83debb4 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Server/Program.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/Program.cs @@ -1,33 +1,67 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; +using BlazingPizza.Server; +using Microsoft.AspNetCore.Authentication; +using Microsoft.EntityFrameworkCore; -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()) { - public class Program + var db = scope.ServiceProvider.GetRequiredService(); + if (db.Database.EnsureCreated()) { - 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(); - }); + SeedData.Initialize(db); } } + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + 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.MapPizzaApi(); + +app.MapRazorPages(); +app.MapControllers(); +app.MapFallbackToFile("index.html"); + +app.Run(); \ No newline at end of file diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/SeedData.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/SeedData.cs index 7c86a5b2..f02e2b77 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Server/SeedData.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Server/SeedData.cs @@ -1,193 +1,192 @@ -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public static class SeedData { - public static class SeedData + public static void Initialize(PizzaStoreContext db) { - public static void Initialize(PizzaStoreContext db) + var toppings = new Topping[] { - var toppings = new Topping[] + new Topping() { - new Topping() - { Name = "Extra cheese", Price = 2.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "American bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "British bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Canadian bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Tea and crumpets", Price = 5.00m - }, - new Topping() - { + }, + new Topping() + { Name = "Fresh-baked scones", Price = 4.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Bell peppers", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Onions", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Mushrooms", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Pepperoni", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Duck sausage", Price = 3.20m, - }, - new Topping() - { + }, + new Topping() + { Name = "Venison meatballs", Price = 2.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Served on a silver platter", Price = 250.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Lobster on top", Price = 64.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Sturgeon caviar", Price = 101.75m, - }, - new Topping() - { + }, + new Topping() + { Name = "Artichoke hearts", Price = 3.40m, - }, - new Topping() - { + }, + new Topping() + { Name = "Fresh tomatoes", Price = 1.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Basil", Price = 1.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Steak (medium-rare)", Price = 8.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Blazing hot peppers", Price = 4.20m, - }, - new Topping() - { + }, + new Topping() + { Name = "Buffalo chicken", Price = 5.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Blue cheese", Price = 2.50m, - }, - }; + }, + }; - var specials = new PizzaSpecial[] + var specials = new PizzaSpecial[] + { + 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() - { + }, + new PizzaSpecial() + { Id = 2, Name = "The Baconatorizor", Description = "It has EVERY kind of bacon", BasePrice = 11.99m, ImageUrl = "img/pizzas/bacon.jpg", - }, - new PizzaSpecial() - { + }, + 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() - { + }, + 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() - { + }, + 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() - { + }, + new PizzaSpecial() + { Id = 6, Name = "The Brit", Description = "When in London...", BasePrice = 10.25m, ImageUrl = "img/pizzas/brit.jpg", - }, - new PizzaSpecial() - { + }, + 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() - { + }, + new PizzaSpecial() + { Id = 8, Name = "Margherita", Description = "Traditional Italian pizza with tomatoes and basil", BasePrice = 9.99m, ImageUrl = "img/pizzas/margherita.jpg", - }, - }; + }, + }; - db.Toppings.AddRange(toppings); - db.Specials.AddRange(specials); - db.SaveChanges(); - } + db.Toppings.AddRange(toppings); + db.Specials.AddRange(specials); + db.SaveChanges(); } -} +} \ No newline at end of file diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/SpecialsController.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/SpecialsController.cs deleted file mode 100644 index a176844c..00000000 --- a/save-points/05-checkout-with-validation/BlazingPizza.Server/SpecialsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("specials")] - [ApiController] - public class SpecialsController : Controller - { - private readonly PizzaStoreContext _db; - - public SpecialsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetSpecials() - { - return (await _db.Specials.ToListAsync()).OrderByDescending(s => s.BasePrice).ToList(); - } - } -} diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/Startup.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/Startup.cs deleted file mode 100644 index ed3fca06..00000000 --- a/save-points/05-checkout-with-validation/BlazingPizza.Server/Startup.cs +++ /dev/null @@ -1,70 +0,0 @@ -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace BlazingPizza.Server -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - public void ConfigureServices(IServiceCollection services) - { - services.AddControllersWithViews(); - services.AddRazorPages(); - - services.AddDbContext(options => - options.UseSqlite("Data Source=pizza.db")); - - services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) - .AddEntityFrameworkStores(); - - services.AddIdentityServer() - .AddApiAuthorization(); - - services.AddAuthentication() - .AddIdentityServerJwt(); - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - app.UseWebAssemblyDebugging(); - } - else - { - app.UseExceptionHandler("/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); - } - - app.UseHttpsRedirection(); - app.UseBlazorFrameworkFiles(); - app.UseStaticFiles(); - - app.UseRouting(); - - app.UseAuthentication(); - app.UseIdentityServer(); - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - endpoints.MapRazorPages(); - endpoints.MapFallbackToFile("index.html"); - }); - } - } -} \ No newline at end of file diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Server/ToppingsController.cs b/save-points/05-checkout-with-validation/BlazingPizza.Server/ToppingsController.cs deleted file mode 100644 index 6a677639..00000000 --- a/save-points/05-checkout-with-validation/BlazingPizza.Server/ToppingsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("toppings")] - [ApiController] - public class ToppingsController : Controller - { - private readonly PizzaStoreContext _db; - - public ToppingsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetToppings() - { - return await _db.Toppings.OrderBy(t => t.Name).ToListAsync(); - } - } -} diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Shared/Address.cs b/save-points/05-checkout-with-validation/BlazingPizza.Shared/Address.cs index d76bc52a..a671359a 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Shared/Address.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Shared/Address.cs @@ -1,27 +1,24 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class Address { - public class Address - { - public int Id { get; set; } + public int Id { get; set; } - [Required, MaxLength(100)] - public string Name { get; set; } + [Required, MaxLength(100)] + public string Name { get; set; } - [Required, MaxLength(100)] - public string Line1 { get; set; } + [Required, MaxLength(100)] + public string Line1 { get; set; } - [MaxLength(100)] - public string Line2 { get; set; } + [MaxLength(100)] + public string Line2 { get; set; } - [Required, MaxLength(50)] - public string City { get; set; } + [Required, MaxLength(50)] + public string City { get; set; } - [Required, MaxLength(20)] - public string Region { get; set; } + [Required, MaxLength(20)] + public string Region { get; set; } - [Required, MaxLength(20)] - public string PostalCode { get; set; } - } + [Required, MaxLength(20)] + public string PostalCode { get; set; } } diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/save-points/05-checkout-with-validation/BlazingPizza.Shared/BlazingPizza.Shared.csproj index 911c57c5..fb17e53b 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/save-points/05-checkout-with-validation/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -1,10 +1,15 @@  - net5.0 + $(TargetFrameworkVersion) BlazingPizza + true + + + + diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Shared/LatLong.cs b/save-points/05-checkout-with-validation/BlazingPizza.Shared/LatLong.cs index 9b8c3811..a65971f8 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Shared/LatLong.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Shared/LatLong.cs @@ -1,27 +1,26 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class LatLong { - public class LatLong + public LatLong() { - public LatLong() - { - } + } - public LatLong(double latitude, double longitude) : this() - { - Latitude = latitude; - Longitude = longitude; - } + public LatLong(double latitude, double longitude) : this() + { + Latitude = latitude; + Longitude = longitude; + } - public double Latitude { get; set; } + public double Latitude { get; set; } - public double Longitude { get; set; } + public double Longitude { get; set; } - public static LatLong Interpolate(LatLong start, LatLong end, double proportion) - { - // The Earth is flat, right? So no need for spherical interpolation. - return new LatLong( + public static LatLong Interpolate(LatLong start, LatLong end, double proportion) + { + // The Earth is flat, right? So no need for spherical interpolation. + return new LatLong( start.Latitude + (end.Latitude - start.Latitude) * proportion, start.Longitude + (end.Longitude - start.Longitude) * proportion); - } } -} +} \ No newline at end of file diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Shared/NotificationSubscription.cs b/save-points/05-checkout-with-validation/BlazingPizza.Shared/NotificationSubscription.cs index 04259c2f..5c99e3f4 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Shared/NotificationSubscription.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Shared/NotificationSubscription.cs @@ -1,17 +1,14 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class NotificationSubscription { - public class NotificationSubscription - { - public int NotificationSubscriptionId { get; set; } + public int NotificationSubscriptionId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public string Url { get; set; } + public string Url { get; set; } - public string P256dh { get; set; } + public string P256dh { get; set; } - public string Auth { get; set; } - } + public string Auth { get; set; } } diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Shared/Order.cs b/save-points/05-checkout-with-validation/BlazingPizza.Shared/Order.cs index fb003bd6..b47efad0 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Shared/Order.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Shared/Order.cs @@ -1,25 +1,32 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +public class Order { - public class Order - { - public int OrderId { get; set; } + public int OrderId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public DateTime CreatedTime { get; set; } + public DateTime CreatedTime { get; set; } - public Address DeliveryAddress { get; set; } = new Address(); + public Address DeliveryAddress { get; set; } = new Address(); - public LatLong DeliveryLocation { get; set; } + public LatLong DeliveryLocation { get; set; } - public List Pizzas { get; set; } = new List(); + public List Pizzas { get; set; } = new List(); - public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); + public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); - public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); - } + public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Default, PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] +[JsonSerializable(typeof(Order))] +[JsonSerializable(typeof(OrderWithStatus))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Pizza))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Topping))] +public partial class OrderContext : JsonSerializerContext { } \ No newline at end of file diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Shared/OrderWithStatus.cs b/save-points/05-checkout-with-validation/BlazingPizza.Shared/OrderWithStatus.cs index 021de78c..fbfac7af 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Shared/OrderWithStatus.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Shared/OrderWithStatus.cs @@ -1,79 +1,78 @@ -using BlazingPizza.ComponentsLibrary.Map; -using System; -using System.Collections.Generic; +using System.Text.Json.Serialization; +using BlazingPizza.ComponentsLibrary.Map; -namespace BlazingPizza -{ - 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 Order Order { get; set; } +namespace BlazingPizza; - public string StatusText { get; set; } +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 bool IsDelivered => StatusText == "Delivered"; + public Order Order { get; set; } - public List MapMarkers { get; set; } + public string StatusText { 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 bool IsDelivered => StatusText == "Delivered"; - 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"; + public List MapMarkers { get; set; } - 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), - }; - } + 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); - return new OrderWithStatus - { - Order = order, - StatusText = statusText, - MapMarkers = mapMarkers, - }; + 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"; - private static LatLong ComputeStartPosition(Order order) + 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 { - // 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); + statusText = "Delivered"; + mapMarkers = new List + { + ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), + }; } - static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) - => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; + 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); + } + + static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) + => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; +} \ No newline at end of file diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Shared/Pizza.cs b/save-points/05-checkout-with-validation/BlazingPizza.Shared/Pizza.cs index ec1108a9..2a7a1c29 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Shared/Pizza.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Shared/Pizza.cs @@ -1,42 +1,44 @@ -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// /// Represents a customized pizza as part of an order +/// +public class Pizza { - /// - /// Represents a customized pizza as part of an order - /// - public class Pizza - { - public const int DefaultSize = 12; - public const int MinimumSize = 9; - public const int MaximumSize = 17; + public const int DefaultSize = 12; + public const int MinimumSize = 9; + public const int MaximumSize = 17; - public int Id { get; set; } + public int Id { get; set; } - public int OrderId { get; set; } + public int OrderId { get; set; } - public PizzaSpecial Special { get; set; } + public PizzaSpecial Special { get; set; } - public int SpecialId { get; set; } + public int SpecialId { get; set; } - public int Size { get; set; } + public int Size { get; set; } - public List Toppings { get; set; } + public List Toppings { get; set; } - public decimal GetBasePrice() - { - return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; - } + public decimal GetBasePrice() + { + return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; + } - public decimal GetTotalPrice() - { - return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); - } + public decimal GetTotalPrice() + { + return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); + } - public string GetFormattedTotalPrice() - { - return GetTotalPrice().ToString("0.00"); - } + public string GetFormattedTotalPrice() + { + return GetTotalPrice().ToString("0.00"); } } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Serialization)] +[JsonSerializable(typeof(Pizza))] +public partial class PizzaContext : JsonSerializerContext { } \ No newline at end of file diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Shared/PizzaSpecial.cs b/save-points/05-checkout-with-validation/BlazingPizza.Shared/PizzaSpecial.cs index 2f2b3383..1fd9006a 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Shared/PizzaSpecial.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Shared/PizzaSpecial.cs @@ -1,20 +1,19 @@ -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// Represents a pre-configured template for a pizza a user can order +/// +public class PizzaSpecial { - /// - /// Represents a pre-configured template for a pizza a user can order - /// - public class PizzaSpecial - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal BasePrice { get; set; } + public decimal BasePrice { get; set; } - public string Description { get; set; } + public string Description { get; set; } - public string ImageUrl { get; set; } + public string ImageUrl { get; set; } - public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); - } -} + public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); +} \ No newline at end of file diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Shared/PizzaTopping.cs b/save-points/05-checkout-with-validation/BlazingPizza.Shared/PizzaTopping.cs index f5a6c1ac..1c062732 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Shared/PizzaTopping.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Shared/PizzaTopping.cs @@ -1,11 +1,11 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class PizzaTopping { - public class PizzaTopping - { - public Topping Topping { get; set; } - - public int ToppingId { get; set; } - - public int PizzaId { get; set; } - } -} + public Topping Topping { get; set; } + + public int ToppingId { get; set; } + + public int PizzaId { get; set; } + +} \ No newline at end of file diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Shared/Topping.cs b/save-points/05-checkout-with-validation/BlazingPizza.Shared/Topping.cs index 61bdeb92..4eb67ae9 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Shared/Topping.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Shared/Topping.cs @@ -1,13 +1,13 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class Topping { - public class Topping - { - public int Id { get; set; } + public int Id { get; set; } + + public string Name { get; set; } - public string Name { get; set; } + public decimal Price { get; set; } - public decimal Price { get; set; } + public string GetFormattedPrice() => Price.ToString("0.00"); - public string GetFormattedPrice() => Price.ToString("0.00"); - } -} +} \ No newline at end of file diff --git a/save-points/05-checkout-with-validation/BlazingPizza.Shared/UserInfo.cs b/save-points/05-checkout-with-validation/BlazingPizza.Shared/UserInfo.cs index 4996ef80..babb4315 100644 --- a/save-points/05-checkout-with-validation/BlazingPizza.Shared/UserInfo.cs +++ b/save-points/05-checkout-with-validation/BlazingPizza.Shared/UserInfo.cs @@ -1,9 +1,9 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class UserInfo { - public class UserInfo - { - public bool IsAuthenticated { get; set; } + public bool IsAuthenticated { get; set; } + + public string Name { get; set; } - public string Name { get; set; } - } -} +} \ No newline at end of file diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Client/BlazingPizza.Client.csproj b/save-points/06-authentication-and-authorization/BlazingPizza.Client/BlazingPizza.Client.csproj index a833c6be..1847e754 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -1,13 +1,15 @@  - net5.0 + $(TargetFrameworkVersion) + true + - + diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Client/OrderState.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Client/OrderState.cs index 5265ae39..00dd3627 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Client/OrderState.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Client/OrderState.cs @@ -1,55 +1,52 @@ -using System.Collections.Generic; +namespace BlazingPizza.Client; -namespace BlazingPizza.Client +public class OrderState { - public class OrderState - { - public bool ShowingConfigureDialog { get; private set; } + public bool ShowingConfigureDialog { get; private set; } - public Pizza ConfiguringPizza { get; private set; } + public Pizza ConfiguringPizza { get; private set; } - public Order Order { get; private set; } = new Order(); + 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() + public void ShowConfigurePizzaDialog(PizzaSpecial special) + { + ConfiguringPizza = new Pizza() { - ConfiguringPizza = null; - ShowingConfigureDialog = false; - } + Special = special, + SpecialId = special.Id, + Size = Pizza.DefaultSize, + Toppings = new List(), + }; - public void ConfirmConfigurePizzaDialog() - { - Order.Pizzas.Add(ConfiguringPizza); - ConfiguringPizza = null; + ShowingConfigureDialog = true; + } - ShowingConfigureDialog = false; - } + public void CancelConfigurePizzaDialog() + { + ConfiguringPizza = null; + ShowingConfigureDialog = false; + } - public void RemoveConfiguredPizza(Pizza pizza) - { - Order.Pizzas.Remove(pizza); - } + public void ConfirmConfigurePizzaDialog() + { + Order.Pizzas.Add(ConfiguringPizza); + ConfiguringPizza = null; - public void ResetOrder() - { - Order = new Order(); - } + ShowingConfigureDialog = false; + } - public void ReplaceOrder(Order order) - { - Order = order; - } + public void RemoveConfiguredPizza(Pizza pizza) + { + Order.Pizzas.Remove(pizza); + } + + public void ResetOrder() + { + Order = new Order(); + } + + public void ReplaceOrder(Order order) + { + Order = order; } } diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Client/OrdersClient.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Client/OrdersClient.cs index 0f800e6f..5e9f9858 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Client/OrdersClient.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Client/OrdersClient.cs @@ -1,35 +1,30 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Net.Http.Json; -using System.Threading.Tasks; - -namespace BlazingPizza.Client +using System.Net.Http.Json; + +namespace BlazingPizza.Client; + +public class OrdersClient { - public class OrdersClient - { - private readonly HttpClient httpClient; + private readonly HttpClient httpClient; - public OrdersClient(HttpClient httpClient) - { - this.httpClient = httpClient; - } + public OrdersClient(HttpClient httpClient) + { + this.httpClient = httpClient; + } - public async Task> GetOrders() => - await httpClient.GetFromJsonAsync>("orders"); + 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; } -} \ No newline at end of file + +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Client/Pages/Checkout.razor b/save-points/06-authentication-and-authorization/BlazingPizza.Client/Pages/Checkout.razor index 7c6419f3..44b01467 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Client/Pages/Checkout.razor +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Client/Pages/Checkout.razor @@ -4,6 +4,8 @@ @inject OrdersClient OrdersClient @inject NavigationManager NavigationManager +Blazing Pizza - Checkout +
diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Client/Pages/MyOrders.razor b/save-points/06-authentication-and-authorization/BlazingPizza.Client/Pages/MyOrders.razor index 792d4ccf..b28dedeb 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Client/Pages/MyOrders.razor +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Client/Pages/MyOrders.razor @@ -3,6 +3,8 @@ @inject OrdersClient OrdersClient @inject NavigationManager NavigationManager +Blazing Pizza - My Orders +
@if (ordersWithStatus == null) { diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Client/Pages/OrderDetails.razor b/save-points/06-authentication-and-authorization/BlazingPizza.Client/Pages/OrderDetails.razor index edf57411..5de448cc 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Client/Pages/OrderDetails.razor +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Client/Pages/OrderDetails.razor @@ -5,6 +5,8 @@ @inject NavigationManager NavigationManager @implements IDisposable +Blazing Pizza - Order Details +
@if (invalidOrder) { diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Client/PizzaAuthenticationState.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Client/PizzaAuthenticationState.cs index 3f295928..78627625 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Client/PizzaAuthenticationState.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Client/PizzaAuthenticationState.cs @@ -1,9 +1,8 @@ using Microsoft.AspNetCore.Components.WebAssembly.Authentication; -namespace BlazingPizza.Client +namespace BlazingPizza.Client; + +public class PizzaAuthenticationState : RemoteAuthenticationState { - public class PizzaAuthenticationState : RemoteAuthenticationState - { - public Order Order { get; set; } - } + public Order Order { get; set; } } diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Client/Program.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Client/Program.cs index afeee128..c2129f0b 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Client/Program.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Client/Program.cs @@ -1,31 +1,21 @@ -using Microsoft.AspNetCore.Components.WebAssembly.Authentication; +using BlazingPizza.Client; +using Microsoft.AspNetCore.Components.Web; +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; -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.RootComponents.Add("head::after"); - builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); - builder.Services.AddHttpClient(client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)) - .AddHttpMessageHandler(); - builder.Services.AddScoped(); +builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); +builder.Services.AddHttpClient(client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)) + .AddHttpMessageHandler(); +builder.Services.AddScoped(); - // Add auth services - builder.Services.AddApiAuthorization(options => - { - options.AuthenticationPaths.LogOutSucceededPath = ""; - }); +// Add auth services +builder.Services.AddApiAuthorization(options => { + options.AuthenticationPaths.LogOutSucceededPath = ""; +}); - await builder.Build().RunAsync(); - } - } -} +await builder.Build().RunAsync(); diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 5f51ee3c..cb996b1b 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -1,7 +1,8 @@  - net5.0 + $(TargetFrameworkVersion) + true diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/LocalStorage.cs b/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/LocalStorage.cs index f36b098e..be8226ec 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/LocalStorage.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/LocalStorage.cs @@ -1,17 +1,15 @@ using Microsoft.JSInterop; -using System.Threading.Tasks; -namespace BlazingPizza.ComponentsLibrary +namespace BlazingPizza.ComponentsLibrary; + +public static class LocalStorage { - public static class LocalStorage - { - public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) + public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); - public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object 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) + public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key) => jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key); - } -} +} \ No newline at end of file diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/Map/Marker.cs b/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/Map/Marker.cs index 63006067..b067719c 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/Map/Marker.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/Map/Marker.cs @@ -1,13 +1,12 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Marker { - public class Marker - { - public string Description { get; set; } + public string Description { get; set; } - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } + public double Y { get; set; } - public bool ShowPopup { get; set; } - } + public bool ShowPopup { get; set; } } diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/Map/Point.cs b/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/Map/Point.cs index 03841826..34194163 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/Map/Point.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.ComponentsLibrary/Map/Point.cs @@ -1,9 +1,8 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Point { - public class Point - { - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } - } -} + public double Y { get; set; } +} \ No newline at end of file diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/BlazingPizza.Server.csproj b/save-points/06-authentication-and-authorization/BlazingPizza.Server/BlazingPizza.Server.csproj index fd7e3c51..227890e1 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -1,7 +1,8 @@  - net5.0 + $(TargetFrameworkVersion) + true diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/AddressEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/AddressEntityType.cs new file mode 100644 index 00000000..82db81b6 --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/AddressEntityType.cs @@ -0,0 +1,92 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class AddressEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Address", + typeof(Address), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Address).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var city = runtimeEntityType.AddProperty( + "City", + typeof(string), + propertyInfo: typeof(Address).GetProperty("City", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var line1 = runtimeEntityType.AddProperty( + "Line1", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line1", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var line2 = runtimeEntityType.AddProperty( + "Line2", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line2", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var postalCode = runtimeEntityType.AddProperty( + "PostalCode", + typeof(string), + propertyInfo: typeof(Address).GetProperty("PostalCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var region = runtimeEntityType.AddProperty( + "Region", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Region", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Address"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs new file mode 100644 index 00000000..1dd4563b --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs @@ -0,0 +1,114 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class DeviceFlowCodesEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.DeviceFlowCodes", + typeof(DeviceFlowCodes), + baseEntityType); + + var userCode = runtimeEntityType.AddProperty( + "UserCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("UserCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var deviceCode = runtimeEntityType.AddProperty( + "DeviceCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("DeviceCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var key = runtimeEntityType.AddKey( + new[] { userCode }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deviceCode }, + unique: true); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "DeviceCodes"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs new file mode 100644 index 00000000..8946b261 --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRoleClaim", + typeof(IdentityRoleClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoleClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityRoleEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityRoleEntityType.cs new file mode 100644 index 00000000..2f1fec2b --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityRoleEntityType.cs @@ -0,0 +1,78 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRole", + typeof(IdentityRole), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedName = runtimeEntityType.AddProperty( + "NormalizedName", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("NormalizedName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedName }, + unique: true); + index.AddAnnotation("Relational:Name", "RoleNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs new file mode 100644 index 00000000..55418a1e --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserClaim", + typeof(IdentityUserClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityUserClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs new file mode 100644 index 00000000..3ca029bd --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserLoginstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserLogin", + typeof(IdentityUserLogin), + baseEntityType); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerKey = runtimeEntityType.AddProperty( + "ProviderKey", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderKey", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerDisplayName = runtimeEntityType.AddProperty( + "ProviderDisplayName", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderDisplayName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { loginProvider, providerKey }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserLogins"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs new file mode 100644 index 00000000..70078d7a --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs @@ -0,0 +1,82 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserRolestringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserRole", + typeof(IdentityUserRole), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { userId, roleId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs new file mode 100644 index 00000000..93ba6d31 --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs @@ -0,0 +1,84 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserTokenstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserToken", + typeof(IdentityUserToken), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var value = runtimeEntityType.AddProperty( + "Value", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Value", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { userId, loginProvider, name }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserTokens"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/KeyEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/KeyEntityType.cs new file mode 100644 index 00000000..f6c6b4c7 --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/KeyEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class KeyEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.Key", + typeof(Key), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var algorithm = runtimeEntityType.AddProperty( + "Algorithm", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Algorithm", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var created = runtimeEntityType.AddProperty( + "Created", + typeof(DateTime), + propertyInfo: typeof(Key).GetProperty("Created", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var dataProtected = runtimeEntityType.AddProperty( + "DataProtected", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("DataProtected", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var isX509Certificate = runtimeEntityType.AddProperty( + "IsX509Certificate", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("IsX509Certificate", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var use = runtimeEntityType.AddProperty( + "Use", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Use", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var version = runtimeEntityType.AddProperty( + "Version", + typeof(int), + propertyInfo: typeof(Key).GetProperty("Version", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { use }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Keys"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/LatLongEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/LatLongEntityType.cs new file mode 100644 index 00000000..3fd254bd --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/LatLongEntityType.cs @@ -0,0 +1,80 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class LatLongEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.LatLong", + typeof(LatLong), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var latitude = runtimeEntityType.AddProperty( + "Latitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Latitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var longitude = runtimeEntityType.AddProperty( + "Longitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Longitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + unique: true, + required: true, + ownership: true); + + var deliveryLocation = principalEntityType.AddNavigation("DeliveryLocation", + runtimeForeignKey, + onDependent: false, + typeof(LatLong), + propertyInfo: typeof(Order).GetProperty("DeliveryLocation", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + eagerLoaded: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs new file mode 100644 index 00000000..db236e4c --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs @@ -0,0 +1,77 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class NotificationSubscriptionEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.NotificationSubscription", + typeof(NotificationSubscription), + baseEntityType); + + var notificationSubscriptionId = runtimeEntityType.AddProperty( + "NotificationSubscriptionId", + typeof(int), + propertyInfo: typeof(NotificationSubscription).GetProperty("NotificationSubscriptionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var auth = runtimeEntityType.AddProperty( + "Auth", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Auth", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var p256dh = runtimeEntityType.AddProperty( + "P256dh", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("P256dh", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var url = runtimeEntityType.AddProperty( + "Url", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Url", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { notificationSubscriptionId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "NotificationSubscriptions"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/OrderEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/OrderEntityType.cs new file mode 100644 index 00000000..9d9ec6fd --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/OrderEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class OrderEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Order", + typeof(Order), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Order).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var createdTime = runtimeEntityType.AddProperty( + "CreatedTime", + typeof(DateTime), + propertyInfo: typeof(Order).GetProperty("CreatedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var deliveryAddressId = runtimeEntityType.AddProperty( + "DeliveryAddressId", + typeof(int?), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(Order).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deliveryAddressId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("DeliveryAddressId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType); + + var deliveryAddress = declaringEntityType.AddNavigation("DeliveryAddress", + runtimeForeignKey, + onDependent: true, + typeof(Address), + propertyInfo: typeof(Order).GetProperty("DeliveryAddress", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PersistedGrantEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PersistedGrantEntityType.cs new file mode 100644 index 00000000..842d53a5 --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PersistedGrantEntityType.cs @@ -0,0 +1,127 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PersistedGrantEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.PersistedGrant", + typeof(PersistedGrant), + baseEntityType); + + var key = runtimeEntityType.AddProperty( + "Key", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Key", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var consumedTime = runtimeEntityType.AddProperty( + "ConsumedTime", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("ConsumedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(PersistedGrant).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var type = runtimeEntityType.AddProperty( + "Type", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Type", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var key0 = runtimeEntityType.AddKey( + new[] { key }); + runtimeEntityType.SetPrimaryKey(key0); + + var index = runtimeEntityType.AddIndex( + new[] { consumedTime }); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + var index1 = runtimeEntityType.AddIndex( + new[] { subjectId, clientId, type }); + + var index2 = runtimeEntityType.AddIndex( + new[] { subjectId, sessionId, type }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PersistedGrants"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaEntityType.cs new file mode 100644 index 00000000..3a124e63 --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaEntityType.cs @@ -0,0 +1,111 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Pizza", + typeof(Pizza), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var size = runtimeEntityType.AddProperty( + "Size", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Size", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var specialId = runtimeEntityType.AddProperty( + "SpecialId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("SpecialId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { orderId }); + + var index0 = runtimeEntityType.AddIndex( + new[] { specialId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var pizzas = principalEntityType.AddNavigation("Pizzas", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Order).GetProperty("Pizzas", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("SpecialId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var special = declaringEntityType.AddNavigation("Special", + runtimeForeignKey, + onDependent: true, + typeof(PizzaSpecial), + propertyInfo: typeof(Pizza).GetProperty("Special", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Pizzas"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs new file mode 100644 index 00000000..e86b0f50 --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs @@ -0,0 +1,76 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaSpecialEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaSpecial", + typeof(PizzaSpecial), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(PizzaSpecial).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var basePrice = runtimeEntityType.AddProperty( + "BasePrice", + typeof(decimal), + propertyInfo: typeof(PizzaSpecial).GetProperty("BasePrice", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var imageUrl = runtimeEntityType.AddProperty( + "ImageUrl", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("ImageUrl", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Specials"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaStoreContextModel.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaStoreContextModel.cs new file mode 100644 index 00000000..8b516a68 --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaStoreContextModel.cs @@ -0,0 +1,28 @@ +// +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + [DbContext(typeof(PizzaStoreContext))] + public partial class PizzaStoreContextModel : RuntimeModel + { + static PizzaStoreContextModel() + { + var model = new PizzaStoreContextModel(); + model.Initialize(); + model.Customize(); + _instance = model; + } + + private static PizzaStoreContextModel _instance; + public static IModel Instance => _instance; + + partial void Initialize(); + + partial void Customize(); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs new file mode 100644 index 00000000..d46f50f4 --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs @@ -0,0 +1,69 @@ +// +using System; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + public partial class PizzaStoreContextModel + { + partial void Initialize() + { + var address = AddressEntityType.Create(this); + var latLong = LatLongEntityType.Create(this); + var notificationSubscription = NotificationSubscriptionEntityType.Create(this); + var order = OrderEntityType.Create(this); + var pizza = PizzaEntityType.Create(this); + var pizzaSpecial = PizzaSpecialEntityType.Create(this); + var pizzaTopping = PizzaToppingEntityType.Create(this); + var pizzaStoreUser = PizzaStoreUserEntityType.Create(this); + var topping = ToppingEntityType.Create(this); + var deviceFlowCodes = DeviceFlowCodesEntityType.Create(this); + var key = KeyEntityType.Create(this); + var persistedGrant = PersistedGrantEntityType.Create(this); + var identityRole = IdentityRoleEntityType.Create(this); + var identityRoleClaimstring = IdentityRoleClaimstringEntityType.Create(this); + var identityUserClaimstring = IdentityUserClaimstringEntityType.Create(this); + var identityUserLoginstring = IdentityUserLoginstringEntityType.Create(this); + var identityUserRolestring = IdentityUserRolestringEntityType.Create(this); + var identityUserTokenstring = IdentityUserTokenstringEntityType.Create(this); + + LatLongEntityType.CreateForeignKey1(latLong, order); + OrderEntityType.CreateForeignKey1(order, address); + PizzaEntityType.CreateForeignKey1(pizza, order); + PizzaEntityType.CreateForeignKey2(pizza, pizzaSpecial); + PizzaToppingEntityType.CreateForeignKey1(pizzaTopping, pizza); + PizzaToppingEntityType.CreateForeignKey2(pizzaTopping, topping); + IdentityRoleClaimstringEntityType.CreateForeignKey1(identityRoleClaimstring, identityRole); + IdentityUserClaimstringEntityType.CreateForeignKey1(identityUserClaimstring, pizzaStoreUser); + IdentityUserLoginstringEntityType.CreateForeignKey1(identityUserLoginstring, pizzaStoreUser); + IdentityUserRolestringEntityType.CreateForeignKey1(identityUserRolestring, identityRole); + IdentityUserRolestringEntityType.CreateForeignKey2(identityUserRolestring, pizzaStoreUser); + IdentityUserTokenstringEntityType.CreateForeignKey1(identityUserTokenstring, pizzaStoreUser); + + AddressEntityType.CreateAnnotations(address); + LatLongEntityType.CreateAnnotations(latLong); + NotificationSubscriptionEntityType.CreateAnnotations(notificationSubscription); + OrderEntityType.CreateAnnotations(order); + PizzaEntityType.CreateAnnotations(pizza); + PizzaSpecialEntityType.CreateAnnotations(pizzaSpecial); + PizzaToppingEntityType.CreateAnnotations(pizzaTopping); + PizzaStoreUserEntityType.CreateAnnotations(pizzaStoreUser); + ToppingEntityType.CreateAnnotations(topping); + DeviceFlowCodesEntityType.CreateAnnotations(deviceFlowCodes); + KeyEntityType.CreateAnnotations(key); + PersistedGrantEntityType.CreateAnnotations(persistedGrant); + IdentityRoleEntityType.CreateAnnotations(identityRole); + IdentityRoleClaimstringEntityType.CreateAnnotations(identityRoleClaimstring); + IdentityUserClaimstringEntityType.CreateAnnotations(identityUserClaimstring); + IdentityUserLoginstringEntityType.CreateAnnotations(identityUserLoginstring); + IdentityUserRolestringEntityType.CreateAnnotations(identityUserRolestring); + IdentityUserTokenstringEntityType.CreateAnnotations(identityUserTokenstring); + + AddAnnotation("ProductVersion", "6.0.0"); + } + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs new file mode 100644 index 00000000..18b2d96d --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs @@ -0,0 +1,156 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaStoreUserEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Server.PizzaStoreUser", + typeof(PizzaStoreUser), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var accessFailedCount = runtimeEntityType.AddProperty( + "AccessFailedCount", + typeof(int), + propertyInfo: typeof(IdentityUser).GetProperty("AccessFailedCount", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var email = runtimeEntityType.AddProperty( + "Email", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Email", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var emailConfirmed = runtimeEntityType.AddProperty( + "EmailConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("EmailConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnabled = runtimeEntityType.AddProperty( + "LockoutEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnd = runtimeEntityType.AddProperty( + "LockoutEnd", + typeof(DateTimeOffset?), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnd", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var normalizedEmail = runtimeEntityType.AddProperty( + "NormalizedEmail", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedEmail", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedUserName = runtimeEntityType.AddProperty( + "NormalizedUserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedUserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var passwordHash = runtimeEntityType.AddProperty( + "PasswordHash", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PasswordHash", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumber = runtimeEntityType.AddProperty( + "PhoneNumber", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumber", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumberConfirmed = runtimeEntityType.AddProperty( + "PhoneNumberConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumberConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var securityStamp = runtimeEntityType.AddProperty( + "SecurityStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("SecurityStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var twoFactorEnabled = runtimeEntityType.AddProperty( + "TwoFactorEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("TwoFactorEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var userName = runtimeEntityType.AddProperty( + "UserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("UserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedEmail }); + index.AddAnnotation("Relational:Name", "EmailIndex"); + + var index0 = runtimeEntityType.AddIndex( + new[] { normalizedUserName }, + unique: true); + index0.AddAnnotation("Relational:Name", "UserNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUsers"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaToppingEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaToppingEntityType.cs new file mode 100644 index 00000000..b97d2a24 --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/PizzaToppingEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaTopping", + typeof(PizzaTopping), + baseEntityType); + + var pizzaId = runtimeEntityType.AddProperty( + "PizzaId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("PizzaId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var toppingId = runtimeEntityType.AddProperty( + "ToppingId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("ToppingId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { pizzaId, toppingId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { toppingId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("PizzaId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var toppings = principalEntityType.AddNavigation("Toppings", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Pizza).GetProperty("Toppings", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("ToppingId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var topping = declaringEntityType.AddNavigation("Topping", + runtimeForeignKey, + onDependent: true, + typeof(Topping), + propertyInfo: typeof(PizzaTopping).GetProperty("Topping", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PizzaTopping"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/ToppingEntityType.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/ToppingEntityType.cs new file mode 100644 index 00000000..9295f9bf --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Models/ToppingEntityType.cs @@ -0,0 +1,62 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class ToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Topping", + typeof(Topping), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Topping).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Topping).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var price = runtimeEntityType.AddProperty( + "Price", + typeof(decimal), + propertyInfo: typeof(Topping).GetProperty("Price", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Toppings"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/OidcConfigurationController.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/OidcConfigurationController.cs index c074debf..50a0a8ad 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Server/OidcConfigurationController.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/OidcConfigurationController.cs @@ -1,9 +1,9 @@ -using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; -using Microsoft.AspNetCore.Mvc; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; +using Microsoft.AspNetCore.Mvc; namespace BlazingPizza.Server { @@ -17,7 +17,7 @@ public OidcConfigurationController(IClientRequestParametersProvider clientReques public IClientRequestParametersProvider ClientRequestParametersProvider { get; } [HttpGet("_configuration/{clientId}")] - public IActionResult GetClientRequestParameters([FromRoute]string clientId) + public IActionResult GetClientRequestParameters([FromRoute] string clientId) { var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); return Ok(parameters); diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/PizzaApiExtensions.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/PizzaApiExtensions.cs new file mode 100644 index 00000000..524ca759 --- /dev/null +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/PizzaApiExtensions.cs @@ -0,0 +1,57 @@ +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/06-authentication-and-authorization/BlazingPizza.Server/PizzaStoreContext.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/PizzaStoreContext.cs index f79c1c66..4830d1a4 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Server/PizzaStoreContext.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/PizzaStoreContext.cs @@ -1,4 +1,4 @@ -using IdentityServer4.EntityFramework.Options; +using Duende.IdentityServer.EntityFramework.Options; using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/PizzasController.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/PizzasController.cs deleted file mode 100644 index c082552c..00000000 --- a/save-points/06-authentication-and-authorization/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/06-authentication-and-authorization/BlazingPizza.Server/Program.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Program.cs index 40a47641..b83debb4 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Program.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Program.cs @@ -1,33 +1,67 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; +using BlazingPizza.Server; +using Microsoft.AspNetCore.Authentication; +using Microsoft.EntityFrameworkCore; -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()) { - public class Program + var db = scope.ServiceProvider.GetRequiredService(); + if (db.Database.EnsureCreated()) { - 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(); - }); + SeedData.Initialize(db); } } + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + 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.MapPizzaApi(); + +app.MapRazorPages(); +app.MapControllers(); +app.MapFallbackToFile("index.html"); + +app.Run(); \ No newline at end of file diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/SeedData.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/SeedData.cs index 7c86a5b2..f02e2b77 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Server/SeedData.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Server/SeedData.cs @@ -1,193 +1,192 @@ -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public static class SeedData { - public static class SeedData + public static void Initialize(PizzaStoreContext db) { - public static void Initialize(PizzaStoreContext db) + var toppings = new Topping[] { - var toppings = new Topping[] + new Topping() { - new Topping() - { Name = "Extra cheese", Price = 2.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "American bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "British bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Canadian bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Tea and crumpets", Price = 5.00m - }, - new Topping() - { + }, + new Topping() + { Name = "Fresh-baked scones", Price = 4.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Bell peppers", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Onions", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Mushrooms", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Pepperoni", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Duck sausage", Price = 3.20m, - }, - new Topping() - { + }, + new Topping() + { Name = "Venison meatballs", Price = 2.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Served on a silver platter", Price = 250.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Lobster on top", Price = 64.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Sturgeon caviar", Price = 101.75m, - }, - new Topping() - { + }, + new Topping() + { Name = "Artichoke hearts", Price = 3.40m, - }, - new Topping() - { + }, + new Topping() + { Name = "Fresh tomatoes", Price = 1.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Basil", Price = 1.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Steak (medium-rare)", Price = 8.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Blazing hot peppers", Price = 4.20m, - }, - new Topping() - { + }, + new Topping() + { Name = "Buffalo chicken", Price = 5.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Blue cheese", Price = 2.50m, - }, - }; + }, + }; - var specials = new PizzaSpecial[] + var specials = new PizzaSpecial[] + { + 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() - { + }, + new PizzaSpecial() + { Id = 2, Name = "The Baconatorizor", Description = "It has EVERY kind of bacon", BasePrice = 11.99m, ImageUrl = "img/pizzas/bacon.jpg", - }, - new PizzaSpecial() - { + }, + 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() - { + }, + 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() - { + }, + 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() - { + }, + new PizzaSpecial() + { Id = 6, Name = "The Brit", Description = "When in London...", BasePrice = 10.25m, ImageUrl = "img/pizzas/brit.jpg", - }, - new PizzaSpecial() - { + }, + 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() - { + }, + new PizzaSpecial() + { Id = 8, Name = "Margherita", Description = "Traditional Italian pizza with tomatoes and basil", BasePrice = 9.99m, ImageUrl = "img/pizzas/margherita.jpg", - }, - }; + }, + }; - db.Toppings.AddRange(toppings); - db.Specials.AddRange(specials); - db.SaveChanges(); - } + db.Toppings.AddRange(toppings); + db.Specials.AddRange(specials); + db.SaveChanges(); } -} +} \ No newline at end of file diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/SpecialsController.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/SpecialsController.cs deleted file mode 100644 index a176844c..00000000 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Server/SpecialsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("specials")] - [ApiController] - public class SpecialsController : Controller - { - private readonly PizzaStoreContext _db; - - public SpecialsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetSpecials() - { - return (await _db.Specials.ToListAsync()).OrderByDescending(s => s.BasePrice).ToList(); - } - } -} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Startup.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/Startup.cs deleted file mode 100644 index ed3fca06..00000000 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Server/Startup.cs +++ /dev/null @@ -1,70 +0,0 @@ -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace BlazingPizza.Server -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - public void ConfigureServices(IServiceCollection services) - { - services.AddControllersWithViews(); - services.AddRazorPages(); - - services.AddDbContext(options => - options.UseSqlite("Data Source=pizza.db")); - - services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) - .AddEntityFrameworkStores(); - - services.AddIdentityServer() - .AddApiAuthorization(); - - services.AddAuthentication() - .AddIdentityServerJwt(); - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - app.UseWebAssemblyDebugging(); - } - else - { - app.UseExceptionHandler("/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); - } - - app.UseHttpsRedirection(); - app.UseBlazorFrameworkFiles(); - app.UseStaticFiles(); - - app.UseRouting(); - - app.UseAuthentication(); - app.UseIdentityServer(); - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - endpoints.MapRazorPages(); - endpoints.MapFallbackToFile("index.html"); - }); - } - } -} \ No newline at end of file diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Server/ToppingsController.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Server/ToppingsController.cs deleted file mode 100644 index 6a677639..00000000 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Server/ToppingsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("toppings")] - [ApiController] - public class ToppingsController : Controller - { - private readonly PizzaStoreContext _db; - - public ToppingsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetToppings() - { - return await _db.Toppings.OrderBy(t => t.Name).ToListAsync(); - } - } -} diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Address.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Address.cs index d76bc52a..a671359a 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Address.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Address.cs @@ -1,27 +1,24 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class Address { - public class Address - { - public int Id { get; set; } + public int Id { get; set; } - [Required, MaxLength(100)] - public string Name { get; set; } + [Required, MaxLength(100)] + public string Name { get; set; } - [Required, MaxLength(100)] - public string Line1 { get; set; } + [Required, MaxLength(100)] + public string Line1 { get; set; } - [MaxLength(100)] - public string Line2 { get; set; } + [MaxLength(100)] + public string Line2 { get; set; } - [Required, MaxLength(50)] - public string City { get; set; } + [Required, MaxLength(50)] + public string City { get; set; } - [Required, MaxLength(20)] - public string Region { get; set; } + [Required, MaxLength(20)] + public string Region { get; set; } - [Required, MaxLength(20)] - public string PostalCode { get; set; } - } + [Required, MaxLength(20)] + public string PostalCode { get; set; } } diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/BlazingPizza.Shared.csproj index 911c57c5..fb17e53b 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -1,10 +1,15 @@  - net5.0 + $(TargetFrameworkVersion) BlazingPizza + true + + + + diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/LatLong.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/LatLong.cs index 9b8c3811..a65971f8 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/LatLong.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/LatLong.cs @@ -1,27 +1,26 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class LatLong { - public class LatLong + public LatLong() { - public LatLong() - { - } + } - public LatLong(double latitude, double longitude) : this() - { - Latitude = latitude; - Longitude = longitude; - } + public LatLong(double latitude, double longitude) : this() + { + Latitude = latitude; + Longitude = longitude; + } - public double Latitude { get; set; } + public double Latitude { get; set; } - public double Longitude { get; set; } + public double Longitude { get; set; } - public static LatLong Interpolate(LatLong start, LatLong end, double proportion) - { - // The Earth is flat, right? So no need for spherical interpolation. - return new LatLong( + public static LatLong Interpolate(LatLong start, LatLong end, double proportion) + { + // The Earth is flat, right? So no need for spherical interpolation. + return new LatLong( start.Latitude + (end.Latitude - start.Latitude) * proportion, start.Longitude + (end.Longitude - start.Longitude) * proportion); - } } -} +} \ No newline at end of file diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/NotificationSubscription.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/NotificationSubscription.cs index 04259c2f..5c99e3f4 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/NotificationSubscription.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/NotificationSubscription.cs @@ -1,17 +1,14 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class NotificationSubscription { - public class NotificationSubscription - { - public int NotificationSubscriptionId { get; set; } + public int NotificationSubscriptionId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public string Url { get; set; } + public string Url { get; set; } - public string P256dh { get; set; } + public string P256dh { get; set; } - public string Auth { get; set; } - } + public string Auth { get; set; } } diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Order.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Order.cs index fb003bd6..b47efad0 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Order.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Order.cs @@ -1,25 +1,32 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +public class Order { - public class Order - { - public int OrderId { get; set; } + public int OrderId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public DateTime CreatedTime { get; set; } + public DateTime CreatedTime { get; set; } - public Address DeliveryAddress { get; set; } = new Address(); + public Address DeliveryAddress { get; set; } = new Address(); - public LatLong DeliveryLocation { get; set; } + public LatLong DeliveryLocation { get; set; } - public List Pizzas { get; set; } = new List(); + public List Pizzas { get; set; } = new List(); - public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); + public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); - public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); - } + public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Default, PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] +[JsonSerializable(typeof(Order))] +[JsonSerializable(typeof(OrderWithStatus))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Pizza))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Topping))] +public partial class OrderContext : JsonSerializerContext { } \ No newline at end of file diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/OrderWithStatus.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/OrderWithStatus.cs index 021de78c..fbfac7af 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/OrderWithStatus.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/OrderWithStatus.cs @@ -1,79 +1,78 @@ -using BlazingPizza.ComponentsLibrary.Map; -using System; -using System.Collections.Generic; +using System.Text.Json.Serialization; +using BlazingPizza.ComponentsLibrary.Map; -namespace BlazingPizza -{ - 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 Order Order { get; set; } +namespace BlazingPizza; - public string StatusText { get; set; } +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 bool IsDelivered => StatusText == "Delivered"; + public Order Order { get; set; } - public List MapMarkers { get; set; } + public string StatusText { 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 bool IsDelivered => StatusText == "Delivered"; - 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"; + public List MapMarkers { get; set; } - 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), - }; - } + 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); - return new OrderWithStatus - { - Order = order, - StatusText = statusText, - MapMarkers = mapMarkers, - }; + 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"; - private static LatLong ComputeStartPosition(Order order) + 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 { - // 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); + statusText = "Delivered"; + mapMarkers = new List + { + ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), + }; } - static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) - => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; + 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); + } + + static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) + => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; +} \ No newline at end of file diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Pizza.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Pizza.cs index ec1108a9..2a7a1c29 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Pizza.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Pizza.cs @@ -1,42 +1,44 @@ -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// /// Represents a customized pizza as part of an order +/// +public class Pizza { - /// - /// Represents a customized pizza as part of an order - /// - public class Pizza - { - public const int DefaultSize = 12; - public const int MinimumSize = 9; - public const int MaximumSize = 17; + public const int DefaultSize = 12; + public const int MinimumSize = 9; + public const int MaximumSize = 17; - public int Id { get; set; } + public int Id { get; set; } - public int OrderId { get; set; } + public int OrderId { get; set; } - public PizzaSpecial Special { get; set; } + public PizzaSpecial Special { get; set; } - public int SpecialId { get; set; } + public int SpecialId { get; set; } - public int Size { get; set; } + public int Size { get; set; } - public List Toppings { get; set; } + public List Toppings { get; set; } - public decimal GetBasePrice() - { - return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; - } + public decimal GetBasePrice() + { + return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; + } - public decimal GetTotalPrice() - { - return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); - } + public decimal GetTotalPrice() + { + return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); + } - public string GetFormattedTotalPrice() - { - return GetTotalPrice().ToString("0.00"); - } + public string GetFormattedTotalPrice() + { + return GetTotalPrice().ToString("0.00"); } } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Serialization)] +[JsonSerializable(typeof(Pizza))] +public partial class PizzaContext : JsonSerializerContext { } \ No newline at end of file diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/PizzaSpecial.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/PizzaSpecial.cs index 2f2b3383..1fd9006a 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/PizzaSpecial.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/PizzaSpecial.cs @@ -1,20 +1,19 @@ -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// Represents a pre-configured template for a pizza a user can order +/// +public class PizzaSpecial { - /// - /// Represents a pre-configured template for a pizza a user can order - /// - public class PizzaSpecial - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal BasePrice { get; set; } + public decimal BasePrice { get; set; } - public string Description { get; set; } + public string Description { get; set; } - public string ImageUrl { get; set; } + public string ImageUrl { get; set; } - public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); - } -} + public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); +} \ No newline at end of file diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/PizzaTopping.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/PizzaTopping.cs index f5a6c1ac..1c062732 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/PizzaTopping.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/PizzaTopping.cs @@ -1,11 +1,11 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class PizzaTopping { - public class PizzaTopping - { - public Topping Topping { get; set; } - - public int ToppingId { get; set; } - - public int PizzaId { get; set; } - } -} + public Topping Topping { get; set; } + + public int ToppingId { get; set; } + + public int PizzaId { get; set; } + +} \ No newline at end of file diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Topping.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Topping.cs index 61bdeb92..4eb67ae9 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Topping.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/Topping.cs @@ -1,13 +1,13 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class Topping { - public class Topping - { - public int Id { get; set; } + public int Id { get; set; } + + public string Name { get; set; } - public string Name { get; set; } + public decimal Price { get; set; } - public decimal Price { get; set; } + public string GetFormattedPrice() => Price.ToString("0.00"); - public string GetFormattedPrice() => Price.ToString("0.00"); - } -} +} \ No newline at end of file diff --git a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/UserInfo.cs b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/UserInfo.cs index 4996ef80..babb4315 100644 --- a/save-points/06-authentication-and-authorization/BlazingPizza.Shared/UserInfo.cs +++ b/save-points/06-authentication-and-authorization/BlazingPizza.Shared/UserInfo.cs @@ -1,9 +1,9 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class UserInfo { - public class UserInfo - { - public bool IsAuthenticated { get; set; } + public bool IsAuthenticated { get; set; } + + public string Name { get; set; } - public string Name { get; set; } - } -} +} \ No newline at end of file diff --git a/save-points/07-javascript-interop/BlazingPizza.Client/BlazingPizza.Client.csproj b/save-points/07-javascript-interop/BlazingPizza.Client/BlazingPizza.Client.csproj index a833c6be..1847e754 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/save-points/07-javascript-interop/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -1,13 +1,15 @@  - net5.0 + $(TargetFrameworkVersion) + true + - + diff --git a/save-points/07-javascript-interop/BlazingPizza.Client/JSRuntimeExtensions.cs b/save-points/07-javascript-interop/BlazingPizza.Client/JSRuntimeExtensions.cs index 89da520c..ef171321 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Client/JSRuntimeExtensions.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Client/JSRuntimeExtensions.cs @@ -1,13 +1,11 @@ using Microsoft.JSInterop; -using System.Threading.Tasks; -namespace BlazingPizza.Client +namespace BlazingPizza.Client; + +public static class JSRuntimeExtensions { - public static class JSRuntimeExtensions + public static ValueTask Confirm(this IJSRuntime jsRuntime, string message) { - public static ValueTask Confirm(this IJSRuntime jsRuntime, string message) - { - return jsRuntime.InvokeAsync("confirm", message); - } + return jsRuntime.InvokeAsync("confirm", message); } } diff --git a/save-points/07-javascript-interop/BlazingPizza.Client/OrderState.cs b/save-points/07-javascript-interop/BlazingPizza.Client/OrderState.cs index 5265ae39..00dd3627 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Client/OrderState.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Client/OrderState.cs @@ -1,55 +1,52 @@ -using System.Collections.Generic; +namespace BlazingPizza.Client; -namespace BlazingPizza.Client +public class OrderState { - public class OrderState - { - public bool ShowingConfigureDialog { get; private set; } + public bool ShowingConfigureDialog { get; private set; } - public Pizza ConfiguringPizza { get; private set; } + public Pizza ConfiguringPizza { get; private set; } - public Order Order { get; private set; } = new Order(); + 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() + public void ShowConfigurePizzaDialog(PizzaSpecial special) + { + ConfiguringPizza = new Pizza() { - ConfiguringPizza = null; - ShowingConfigureDialog = false; - } + Special = special, + SpecialId = special.Id, + Size = Pizza.DefaultSize, + Toppings = new List(), + }; - public void ConfirmConfigurePizzaDialog() - { - Order.Pizzas.Add(ConfiguringPizza); - ConfiguringPizza = null; + ShowingConfigureDialog = true; + } - ShowingConfigureDialog = false; - } + public void CancelConfigurePizzaDialog() + { + ConfiguringPizza = null; + ShowingConfigureDialog = false; + } - public void RemoveConfiguredPizza(Pizza pizza) - { - Order.Pizzas.Remove(pizza); - } + public void ConfirmConfigurePizzaDialog() + { + Order.Pizzas.Add(ConfiguringPizza); + ConfiguringPizza = null; - public void ResetOrder() - { - Order = new Order(); - } + ShowingConfigureDialog = false; + } - public void ReplaceOrder(Order order) - { - Order = order; - } + public void RemoveConfiguredPizza(Pizza pizza) + { + Order.Pizzas.Remove(pizza); + } + + public void ResetOrder() + { + Order = new Order(); + } + + public void ReplaceOrder(Order order) + { + Order = order; } } diff --git a/save-points/07-javascript-interop/BlazingPizza.Client/OrdersClient.cs b/save-points/07-javascript-interop/BlazingPizza.Client/OrdersClient.cs index 0f800e6f..b4a08f1e 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Client/OrdersClient.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Client/OrdersClient.cs @@ -1,35 +1,36 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Net.Http.Json; -using System.Threading.Tasks; - -namespace BlazingPizza.Client +using System.Net.Http.Json; +using System.Text.Json; + +namespace BlazingPizza.Client; + +public class OrdersClient { - public class OrdersClient + private readonly HttpClient httpClient; + + public OrdersClient(HttpClient httpClient) { - private readonly HttpClient httpClient; + this.httpClient = httpClient; + } - public OrdersClient(HttpClient httpClient) - { - this.httpClient = httpClient; - } + public async Task> GetOrders() => + await httpClient.GetFromJsonAsync("orders", OrderContext.Default.ListOrderWithStatus); - public async Task> GetOrders() => - await httpClient.GetFromJsonAsync>("orders"); + public async Task GetOrder(int orderId) => + await httpClient.GetFromJsonAsync($"orders/{orderId}", OrderContext.Default.OrderWithStatus); - public async Task GetOrder(int orderId) => - await httpClient.GetFromJsonAsync($"orders/{orderId}"); + public async Task PlaceOrder(Order order) + { + var response = await httpClient.PostAsJsonAsync("orders", order, OrderContext.Default.Order); + response.EnsureSuccessStatusCode(); + var orderId = await response.Content.ReadFromJsonAsync(); + return orderId; + } - public async Task PlaceOrder(Order order) - { - var response = await httpClient.PostAsJsonAsync("orders", order); - response.EnsureSuccessStatusCode(); - var orderId = await response.Content.ReadFromJsonAsync(); - return orderId; - } + public async Task SubscribeToNotifications(NotificationSubscription subscription) + { + var response = await httpClient.PutAsJsonAsync("notifications/subscribe", subscription); + response.EnsureSuccessStatusCode(); } -} \ No newline at end of file +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Client/Pages/Checkout.razor b/save-points/07-javascript-interop/BlazingPizza.Client/Pages/Checkout.razor index 7c6419f3..44b01467 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Client/Pages/Checkout.razor +++ b/save-points/07-javascript-interop/BlazingPizza.Client/Pages/Checkout.razor @@ -4,6 +4,8 @@ @inject OrdersClient OrdersClient @inject NavigationManager NavigationManager +Blazing Pizza - Checkout +
diff --git a/save-points/07-javascript-interop/BlazingPizza.Client/Pages/MyOrders.razor b/save-points/07-javascript-interop/BlazingPizza.Client/Pages/MyOrders.razor index 792d4ccf..b28dedeb 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Client/Pages/MyOrders.razor +++ b/save-points/07-javascript-interop/BlazingPizza.Client/Pages/MyOrders.razor @@ -3,6 +3,8 @@ @inject OrdersClient OrdersClient @inject NavigationManager NavigationManager +Blazing Pizza - My Orders +
@if (ordersWithStatus == null) { diff --git a/save-points/07-javascript-interop/BlazingPizza.Client/Pages/OrderDetails.razor b/save-points/07-javascript-interop/BlazingPizza.Client/Pages/OrderDetails.razor index 7df9161e..548bbd59 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Client/Pages/OrderDetails.razor +++ b/save-points/07-javascript-interop/BlazingPizza.Client/Pages/OrderDetails.razor @@ -5,6 +5,8 @@ @inject NavigationManager NavigationManager @implements IDisposable +Blazing Pizza - Order Details +
@if (invalidOrder) { diff --git a/save-points/07-javascript-interop/BlazingPizza.Client/PizzaAuthenticationState.cs b/save-points/07-javascript-interop/BlazingPizza.Client/PizzaAuthenticationState.cs index 3f295928..78627625 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Client/PizzaAuthenticationState.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Client/PizzaAuthenticationState.cs @@ -1,9 +1,8 @@ using Microsoft.AspNetCore.Components.WebAssembly.Authentication; -namespace BlazingPizza.Client +namespace BlazingPizza.Client; + +public class PizzaAuthenticationState : RemoteAuthenticationState { - public class PizzaAuthenticationState : RemoteAuthenticationState - { - public Order Order { get; set; } - } + public Order Order { get; set; } } diff --git a/save-points/07-javascript-interop/BlazingPizza.Client/Program.cs b/save-points/07-javascript-interop/BlazingPizza.Client/Program.cs index afeee128..c2129f0b 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Client/Program.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Client/Program.cs @@ -1,31 +1,21 @@ -using Microsoft.AspNetCore.Components.WebAssembly.Authentication; +using BlazingPizza.Client; +using Microsoft.AspNetCore.Components.Web; +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; -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.RootComponents.Add("head::after"); - builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); - builder.Services.AddHttpClient(client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)) - .AddHttpMessageHandler(); - builder.Services.AddScoped(); +builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); +builder.Services.AddHttpClient(client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)) + .AddHttpMessageHandler(); +builder.Services.AddScoped(); - // Add auth services - builder.Services.AddApiAuthorization(options => - { - options.AuthenticationPaths.LogOutSucceededPath = ""; - }); +// Add auth services +builder.Services.AddApiAuthorization(options => { + options.AuthenticationPaths.LogOutSucceededPath = ""; +}); - await builder.Build().RunAsync(); - } - } -} +await builder.Build().RunAsync(); diff --git a/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 5f51ee3c..cb996b1b 100644 --- a/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -1,7 +1,8 @@  - net5.0 + $(TargetFrameworkVersion) + true diff --git a/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/LocalStorage.cs b/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/LocalStorage.cs index f36b098e..be8226ec 100644 --- a/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/LocalStorage.cs +++ b/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/LocalStorage.cs @@ -1,17 +1,15 @@ using Microsoft.JSInterop; -using System.Threading.Tasks; -namespace BlazingPizza.ComponentsLibrary +namespace BlazingPizza.ComponentsLibrary; + +public static class LocalStorage { - public static class LocalStorage - { - public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) + public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); - public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object 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) + public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key) => jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key); - } -} +} \ No newline at end of file diff --git a/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/Map/Marker.cs b/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/Map/Marker.cs index 63006067..b067719c 100644 --- a/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/Map/Marker.cs +++ b/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/Map/Marker.cs @@ -1,13 +1,12 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Marker { - public class Marker - { - public string Description { get; set; } + public string Description { get; set; } - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } + public double Y { get; set; } - public bool ShowPopup { get; set; } - } + public bool ShowPopup { get; set; } } diff --git a/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/Map/Point.cs b/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/Map/Point.cs index 03841826..34194163 100644 --- a/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/Map/Point.cs +++ b/save-points/07-javascript-interop/BlazingPizza.ComponentsLibrary/Map/Point.cs @@ -1,9 +1,8 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Point { - public class Point - { - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } - } -} + public double Y { get; set; } +} \ No newline at end of file diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/BlazingPizza.Server.csproj b/save-points/07-javascript-interop/BlazingPizza.Server/BlazingPizza.Server.csproj index fd7e3c51..abd2317b 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/save-points/07-javascript-interop/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -1,7 +1,8 @@  - net5.0 + $(TargetFrameworkVersion) + true @@ -13,6 +14,7 @@ + diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/AddressEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/AddressEntityType.cs new file mode 100644 index 00000000..82db81b6 --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/AddressEntityType.cs @@ -0,0 +1,92 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class AddressEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Address", + typeof(Address), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Address).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var city = runtimeEntityType.AddProperty( + "City", + typeof(string), + propertyInfo: typeof(Address).GetProperty("City", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var line1 = runtimeEntityType.AddProperty( + "Line1", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line1", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var line2 = runtimeEntityType.AddProperty( + "Line2", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line2", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var postalCode = runtimeEntityType.AddProperty( + "PostalCode", + typeof(string), + propertyInfo: typeof(Address).GetProperty("PostalCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var region = runtimeEntityType.AddProperty( + "Region", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Region", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Address"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs new file mode 100644 index 00000000..1dd4563b --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs @@ -0,0 +1,114 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class DeviceFlowCodesEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.DeviceFlowCodes", + typeof(DeviceFlowCodes), + baseEntityType); + + var userCode = runtimeEntityType.AddProperty( + "UserCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("UserCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var deviceCode = runtimeEntityType.AddProperty( + "DeviceCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("DeviceCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var key = runtimeEntityType.AddKey( + new[] { userCode }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deviceCode }, + unique: true); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "DeviceCodes"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs new file mode 100644 index 00000000..8946b261 --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRoleClaim", + typeof(IdentityRoleClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoleClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityRoleEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityRoleEntityType.cs new file mode 100644 index 00000000..2f1fec2b --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityRoleEntityType.cs @@ -0,0 +1,78 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRole", + typeof(IdentityRole), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedName = runtimeEntityType.AddProperty( + "NormalizedName", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("NormalizedName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedName }, + unique: true); + index.AddAnnotation("Relational:Name", "RoleNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs new file mode 100644 index 00000000..55418a1e --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserClaim", + typeof(IdentityUserClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityUserClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs new file mode 100644 index 00000000..3ca029bd --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserLoginstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserLogin", + typeof(IdentityUserLogin), + baseEntityType); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerKey = runtimeEntityType.AddProperty( + "ProviderKey", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderKey", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerDisplayName = runtimeEntityType.AddProperty( + "ProviderDisplayName", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderDisplayName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { loginProvider, providerKey }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserLogins"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs new file mode 100644 index 00000000..70078d7a --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs @@ -0,0 +1,82 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserRolestringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserRole", + typeof(IdentityUserRole), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { userId, roleId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs new file mode 100644 index 00000000..93ba6d31 --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs @@ -0,0 +1,84 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserTokenstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserToken", + typeof(IdentityUserToken), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var value = runtimeEntityType.AddProperty( + "Value", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Value", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { userId, loginProvider, name }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserTokens"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/KeyEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/KeyEntityType.cs new file mode 100644 index 00000000..f6c6b4c7 --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/KeyEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class KeyEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.Key", + typeof(Key), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var algorithm = runtimeEntityType.AddProperty( + "Algorithm", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Algorithm", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var created = runtimeEntityType.AddProperty( + "Created", + typeof(DateTime), + propertyInfo: typeof(Key).GetProperty("Created", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var dataProtected = runtimeEntityType.AddProperty( + "DataProtected", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("DataProtected", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var isX509Certificate = runtimeEntityType.AddProperty( + "IsX509Certificate", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("IsX509Certificate", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var use = runtimeEntityType.AddProperty( + "Use", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Use", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var version = runtimeEntityType.AddProperty( + "Version", + typeof(int), + propertyInfo: typeof(Key).GetProperty("Version", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { use }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Keys"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/LatLongEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/LatLongEntityType.cs new file mode 100644 index 00000000..3fd254bd --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/LatLongEntityType.cs @@ -0,0 +1,80 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class LatLongEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.LatLong", + typeof(LatLong), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var latitude = runtimeEntityType.AddProperty( + "Latitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Latitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var longitude = runtimeEntityType.AddProperty( + "Longitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Longitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + unique: true, + required: true, + ownership: true); + + var deliveryLocation = principalEntityType.AddNavigation("DeliveryLocation", + runtimeForeignKey, + onDependent: false, + typeof(LatLong), + propertyInfo: typeof(Order).GetProperty("DeliveryLocation", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + eagerLoaded: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs new file mode 100644 index 00000000..db236e4c --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs @@ -0,0 +1,77 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class NotificationSubscriptionEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.NotificationSubscription", + typeof(NotificationSubscription), + baseEntityType); + + var notificationSubscriptionId = runtimeEntityType.AddProperty( + "NotificationSubscriptionId", + typeof(int), + propertyInfo: typeof(NotificationSubscription).GetProperty("NotificationSubscriptionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var auth = runtimeEntityType.AddProperty( + "Auth", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Auth", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var p256dh = runtimeEntityType.AddProperty( + "P256dh", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("P256dh", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var url = runtimeEntityType.AddProperty( + "Url", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Url", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { notificationSubscriptionId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "NotificationSubscriptions"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/OrderEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/OrderEntityType.cs new file mode 100644 index 00000000..9d9ec6fd --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/OrderEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class OrderEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Order", + typeof(Order), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Order).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var createdTime = runtimeEntityType.AddProperty( + "CreatedTime", + typeof(DateTime), + propertyInfo: typeof(Order).GetProperty("CreatedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var deliveryAddressId = runtimeEntityType.AddProperty( + "DeliveryAddressId", + typeof(int?), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(Order).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deliveryAddressId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("DeliveryAddressId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType); + + var deliveryAddress = declaringEntityType.AddNavigation("DeliveryAddress", + runtimeForeignKey, + onDependent: true, + typeof(Address), + propertyInfo: typeof(Order).GetProperty("DeliveryAddress", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/PersistedGrantEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/PersistedGrantEntityType.cs new file mode 100644 index 00000000..842d53a5 --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/PersistedGrantEntityType.cs @@ -0,0 +1,127 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PersistedGrantEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.PersistedGrant", + typeof(PersistedGrant), + baseEntityType); + + var key = runtimeEntityType.AddProperty( + "Key", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Key", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var consumedTime = runtimeEntityType.AddProperty( + "ConsumedTime", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("ConsumedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(PersistedGrant).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var type = runtimeEntityType.AddProperty( + "Type", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Type", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var key0 = runtimeEntityType.AddKey( + new[] { key }); + runtimeEntityType.SetPrimaryKey(key0); + + var index = runtimeEntityType.AddIndex( + new[] { consumedTime }); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + var index1 = runtimeEntityType.AddIndex( + new[] { subjectId, clientId, type }); + + var index2 = runtimeEntityType.AddIndex( + new[] { subjectId, sessionId, type }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PersistedGrants"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaEntityType.cs new file mode 100644 index 00000000..3a124e63 --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaEntityType.cs @@ -0,0 +1,111 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Pizza", + typeof(Pizza), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var size = runtimeEntityType.AddProperty( + "Size", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Size", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var specialId = runtimeEntityType.AddProperty( + "SpecialId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("SpecialId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { orderId }); + + var index0 = runtimeEntityType.AddIndex( + new[] { specialId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var pizzas = principalEntityType.AddNavigation("Pizzas", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Order).GetProperty("Pizzas", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("SpecialId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var special = declaringEntityType.AddNavigation("Special", + runtimeForeignKey, + onDependent: true, + typeof(PizzaSpecial), + propertyInfo: typeof(Pizza).GetProperty("Special", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Pizzas"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs new file mode 100644 index 00000000..e86b0f50 --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs @@ -0,0 +1,76 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaSpecialEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaSpecial", + typeof(PizzaSpecial), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(PizzaSpecial).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var basePrice = runtimeEntityType.AddProperty( + "BasePrice", + typeof(decimal), + propertyInfo: typeof(PizzaSpecial).GetProperty("BasePrice", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var imageUrl = runtimeEntityType.AddProperty( + "ImageUrl", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("ImageUrl", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Specials"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaStoreContextModel.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaStoreContextModel.cs new file mode 100644 index 00000000..8b516a68 --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaStoreContextModel.cs @@ -0,0 +1,28 @@ +// +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + [DbContext(typeof(PizzaStoreContext))] + public partial class PizzaStoreContextModel : RuntimeModel + { + static PizzaStoreContextModel() + { + var model = new PizzaStoreContextModel(); + model.Initialize(); + model.Customize(); + _instance = model; + } + + private static PizzaStoreContextModel _instance; + public static IModel Instance => _instance; + + partial void Initialize(); + + partial void Customize(); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs new file mode 100644 index 00000000..d46f50f4 --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs @@ -0,0 +1,69 @@ +// +using System; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + public partial class PizzaStoreContextModel + { + partial void Initialize() + { + var address = AddressEntityType.Create(this); + var latLong = LatLongEntityType.Create(this); + var notificationSubscription = NotificationSubscriptionEntityType.Create(this); + var order = OrderEntityType.Create(this); + var pizza = PizzaEntityType.Create(this); + var pizzaSpecial = PizzaSpecialEntityType.Create(this); + var pizzaTopping = PizzaToppingEntityType.Create(this); + var pizzaStoreUser = PizzaStoreUserEntityType.Create(this); + var topping = ToppingEntityType.Create(this); + var deviceFlowCodes = DeviceFlowCodesEntityType.Create(this); + var key = KeyEntityType.Create(this); + var persistedGrant = PersistedGrantEntityType.Create(this); + var identityRole = IdentityRoleEntityType.Create(this); + var identityRoleClaimstring = IdentityRoleClaimstringEntityType.Create(this); + var identityUserClaimstring = IdentityUserClaimstringEntityType.Create(this); + var identityUserLoginstring = IdentityUserLoginstringEntityType.Create(this); + var identityUserRolestring = IdentityUserRolestringEntityType.Create(this); + var identityUserTokenstring = IdentityUserTokenstringEntityType.Create(this); + + LatLongEntityType.CreateForeignKey1(latLong, order); + OrderEntityType.CreateForeignKey1(order, address); + PizzaEntityType.CreateForeignKey1(pizza, order); + PizzaEntityType.CreateForeignKey2(pizza, pizzaSpecial); + PizzaToppingEntityType.CreateForeignKey1(pizzaTopping, pizza); + PizzaToppingEntityType.CreateForeignKey2(pizzaTopping, topping); + IdentityRoleClaimstringEntityType.CreateForeignKey1(identityRoleClaimstring, identityRole); + IdentityUserClaimstringEntityType.CreateForeignKey1(identityUserClaimstring, pizzaStoreUser); + IdentityUserLoginstringEntityType.CreateForeignKey1(identityUserLoginstring, pizzaStoreUser); + IdentityUserRolestringEntityType.CreateForeignKey1(identityUserRolestring, identityRole); + IdentityUserRolestringEntityType.CreateForeignKey2(identityUserRolestring, pizzaStoreUser); + IdentityUserTokenstringEntityType.CreateForeignKey1(identityUserTokenstring, pizzaStoreUser); + + AddressEntityType.CreateAnnotations(address); + LatLongEntityType.CreateAnnotations(latLong); + NotificationSubscriptionEntityType.CreateAnnotations(notificationSubscription); + OrderEntityType.CreateAnnotations(order); + PizzaEntityType.CreateAnnotations(pizza); + PizzaSpecialEntityType.CreateAnnotations(pizzaSpecial); + PizzaToppingEntityType.CreateAnnotations(pizzaTopping); + PizzaStoreUserEntityType.CreateAnnotations(pizzaStoreUser); + ToppingEntityType.CreateAnnotations(topping); + DeviceFlowCodesEntityType.CreateAnnotations(deviceFlowCodes); + KeyEntityType.CreateAnnotations(key); + PersistedGrantEntityType.CreateAnnotations(persistedGrant); + IdentityRoleEntityType.CreateAnnotations(identityRole); + IdentityRoleClaimstringEntityType.CreateAnnotations(identityRoleClaimstring); + IdentityUserClaimstringEntityType.CreateAnnotations(identityUserClaimstring); + IdentityUserLoginstringEntityType.CreateAnnotations(identityUserLoginstring); + IdentityUserRolestringEntityType.CreateAnnotations(identityUserRolestring); + IdentityUserTokenstringEntityType.CreateAnnotations(identityUserTokenstring); + + AddAnnotation("ProductVersion", "6.0.0"); + } + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs new file mode 100644 index 00000000..18b2d96d --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs @@ -0,0 +1,156 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaStoreUserEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Server.PizzaStoreUser", + typeof(PizzaStoreUser), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var accessFailedCount = runtimeEntityType.AddProperty( + "AccessFailedCount", + typeof(int), + propertyInfo: typeof(IdentityUser).GetProperty("AccessFailedCount", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var email = runtimeEntityType.AddProperty( + "Email", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Email", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var emailConfirmed = runtimeEntityType.AddProperty( + "EmailConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("EmailConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnabled = runtimeEntityType.AddProperty( + "LockoutEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnd = runtimeEntityType.AddProperty( + "LockoutEnd", + typeof(DateTimeOffset?), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnd", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var normalizedEmail = runtimeEntityType.AddProperty( + "NormalizedEmail", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedEmail", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedUserName = runtimeEntityType.AddProperty( + "NormalizedUserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedUserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var passwordHash = runtimeEntityType.AddProperty( + "PasswordHash", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PasswordHash", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumber = runtimeEntityType.AddProperty( + "PhoneNumber", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumber", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumberConfirmed = runtimeEntityType.AddProperty( + "PhoneNumberConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumberConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var securityStamp = runtimeEntityType.AddProperty( + "SecurityStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("SecurityStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var twoFactorEnabled = runtimeEntityType.AddProperty( + "TwoFactorEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("TwoFactorEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var userName = runtimeEntityType.AddProperty( + "UserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("UserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedEmail }); + index.AddAnnotation("Relational:Name", "EmailIndex"); + + var index0 = runtimeEntityType.AddIndex( + new[] { normalizedUserName }, + unique: true); + index0.AddAnnotation("Relational:Name", "UserNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUsers"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaToppingEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaToppingEntityType.cs new file mode 100644 index 00000000..b97d2a24 --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/PizzaToppingEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaTopping", + typeof(PizzaTopping), + baseEntityType); + + var pizzaId = runtimeEntityType.AddProperty( + "PizzaId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("PizzaId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var toppingId = runtimeEntityType.AddProperty( + "ToppingId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("ToppingId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { pizzaId, toppingId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { toppingId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("PizzaId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var toppings = principalEntityType.AddNavigation("Toppings", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Pizza).GetProperty("Toppings", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("ToppingId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var topping = declaringEntityType.AddNavigation("Topping", + runtimeForeignKey, + onDependent: true, + typeof(Topping), + propertyInfo: typeof(PizzaTopping).GetProperty("Topping", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PizzaTopping"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Models/ToppingEntityType.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Models/ToppingEntityType.cs new file mode 100644 index 00000000..9295f9bf --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Models/ToppingEntityType.cs @@ -0,0 +1,62 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class ToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Topping", + typeof(Topping), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Topping).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Topping).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var price = runtimeEntityType.AddProperty( + "Price", + typeof(decimal), + propertyInfo: typeof(Topping).GetProperty("Price", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Toppings"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/NotificationsController.cs b/save-points/07-javascript-interop/BlazingPizza.Server/NotificationsController.cs deleted file mode 100644 index bb3b96ff..00000000 --- a/save-points/07-javascript-interop/BlazingPizza.Server/NotificationsController.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("notifications")] - [ApiController] - [Authorize] - public class NotificationsController : Controller - { - private readonly PizzaStoreContext _db; - - public NotificationsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpPut("subscribe")] - public async Task Subscribe(NotificationSubscription subscription) - { - // We're storing at most one subscription per user, so delete old ones. - // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. - var userId = GetUserId(); - var oldSubscriptions = _db.NotificationSubscriptions.Where(e => e.UserId == userId); - _db.NotificationSubscriptions.RemoveRange(oldSubscriptions); - - // Store new subscription - subscription.UserId = userId; - _db.NotificationSubscriptions.Attach(subscription); - - await _db.SaveChangesAsync(); - return subscription; - } - - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } - } -} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/OidcConfigurationController.cs b/save-points/07-javascript-interop/BlazingPizza.Server/OidcConfigurationController.cs index c074debf..1431697e 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Server/OidcConfigurationController.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Server/OidcConfigurationController.cs @@ -1,26 +1,21 @@ using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class OidcConfigurationController : Controller { - public class OidcConfigurationController : Controller + public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) { - public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) - { - ClientRequestParametersProvider = clientRequestParametersProvider; - } + ClientRequestParametersProvider = clientRequestParametersProvider; + } - public IClientRequestParametersProvider ClientRequestParametersProvider { get; } + public IClientRequestParametersProvider ClientRequestParametersProvider { get; } - [HttpGet("_configuration/{clientId}")] - public IActionResult GetClientRequestParameters([FromRoute]string clientId) - { - var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); - return Ok(parameters); - } + [HttpGet("_configuration/{clientId}")] + public IActionResult GetClientRequestParameters([FromRoute] string clientId) + { + var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); + return Ok(parameters); } } diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/OrdersController.cs b/save-points/07-javascript-interop/BlazingPizza.Server/OrdersController.cs index 72b59890..3d2ba63f 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Server/OrdersController.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Server/OrdersController.cs @@ -1,30 +1,28 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; +using System.Security.Claims; +using System.Text.Json; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using WebPush; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +[Route("orders")] +[ApiController] +[Authorize] +public class OrdersController : Controller { - [Route("orders")] - [ApiController] - [Authorize] - public class OrdersController : Controller - { - private readonly PizzaStoreContext _db; + private readonly PizzaStoreContext _db; - public OrdersController(PizzaStoreContext db) - { - _db = db; - } + public OrdersController(PizzaStoreContext db) + { + _db = db; + } - [HttpGet] - public async Task>> GetOrders() - { - var orders = await _db.Orders + [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) @@ -32,13 +30,13 @@ public async Task>> GetOrders() .OrderByDescending(o => o.CreatedTime) .ToListAsync(); - return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); - } + return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); + } - [HttpGet("{orderId}")] - public async Task> GetOrderWithStatus(int orderId) - { - var order = await _db.Orders + [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) @@ -46,70 +44,87 @@ public async Task> GetOrderWithStatus(int orderId) .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) .SingleOrDefaultAsync(); - if (order == null) - { - return NotFound(); - } - - return OrderWithStatus.FromOrder(order); + if (order == null) + { + return NotFound(); } - [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; - } - } + return OrderWithStatus.FromOrder(order); + } - _db.Orders.Attach(order); - await _db.SaveChangesAsync(); + [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; - // In the background, send push notifications if possible - var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); - if (subscription != null) + foreach (var topping in pizza.Toppings) { - _ = TrackAndSendNotificationsAsync(order, subscription); + topping.ToppingId = topping.Topping.Id; + topping.Topping = null; } - - return order.OrderId; } - private string GetUserId() + _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) { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); + _ = TrackAndSendNotificationsAsync(order, subscription); } - private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription 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 { - // 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!"); + var payload = JsonSerializer.Serialize(new + { + message, + url = $"myorders/{order.OrderId}", + }); + await webPushClient.SendNotificationAsync(pushSubscription, payload, vapidDetails); } - - private static Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) + catch (Exception ex) { - // This will be implemented later - return Task.CompletedTask; + Console.Error.WriteLine("Error sending push notification: " + ex.Message); } } } diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/PizzaApiExtensions.cs b/save-points/07-javascript-interop/BlazingPizza.Server/PizzaApiExtensions.cs new file mode 100644 index 00000000..524ca759 --- /dev/null +++ b/save-points/07-javascript-interop/BlazingPizza.Server/PizzaApiExtensions.cs @@ -0,0 +1,57 @@ +using System.Security.Claims; +using Microsoft.AspNetCore.Authorization; +using Microsoft.EntityFrameworkCore; + +namespace BlazingPizza.Server; + +public static class PizzaApiExtensions +{ + + public static WebApplication MapPizzaApi(this WebApplication app) + { + + // Subscribe to notifications + app.MapPut("/notifications/subscribe", [Authorize] async ( + HttpContext context, + PizzaStoreContext db, + NotificationSubscription subscription) => { + + // We're storing at most one subscription per user, so delete old ones. + // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. + var userId = GetUserId(context); + var oldSubscriptions = db.NotificationSubscriptions.Where(e => e.UserId == userId); + db.NotificationSubscriptions.RemoveRange(oldSubscriptions); + + // Store new subscription + subscription.UserId = userId; + db.NotificationSubscriptions.Attach(subscription); + + await db.SaveChangesAsync(); + return Results.Ok(subscription); + + }); + + // Specials + app.MapGet("/specials", async (PizzaStoreContext db) => { + + var specials = await db.Specials.ToListAsync(); + return Results.Ok(specials); + + }); + + // Toppings + app.MapGet("/toppings", async (PizzaStoreContext db) => { + var toppings = await db.Toppings.OrderBy(t => t.Name).ToListAsync(); + return Results.Ok(toppings); + }); + + return app; + + } + + private static string GetUserId(HttpContext context) + { + return context.User.FindFirstValue(ClaimTypes.NameIdentifier); + } + +} \ No newline at end of file diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/PizzaStoreContext.cs b/save-points/07-javascript-interop/BlazingPizza.Server/PizzaStoreContext.cs index f79c1c66..50ac87e4 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Server/PizzaStoreContext.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Server/PizzaStoreContext.cs @@ -1,39 +1,38 @@ -using IdentityServer4.EntityFramework.Options; +using Duende.IdentityServer.EntityFramework.Options; using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class PizzaStoreContext : ApiAuthorizationDbContext { - public class PizzaStoreContext : ApiAuthorizationDbContext - { - public PizzaStoreContext( + 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/07-javascript-interop/BlazingPizza.Server/PizzaStoreUser.cs b/save-points/07-javascript-interop/BlazingPizza.Server/PizzaStoreUser.cs index 171ce83d..7ab40235 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Server/PizzaStoreUser.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Server/PizzaStoreUser.cs @@ -1,8 +1,5 @@ using Microsoft.AspNetCore.Identity; -namespace BlazingPizza.Server -{ - public class PizzaStoreUser : IdentityUser - { - } -} \ No newline at end of file +namespace BlazingPizza.Server; + +public class PizzaStoreUser : IdentityUser { } \ No newline at end of file diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/PizzasController.cs b/save-points/07-javascript-interop/BlazingPizza.Server/PizzasController.cs deleted file mode 100644 index c082552c..00000000 --- a/save-points/07-javascript-interop/BlazingPizza.Server/PizzasController.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("pizzas")] - [ApiController] - public class PizzasController : Controller - { - private readonly PizzaStoreContext _db; - - public PizzasController(PizzaStoreContext db) - { - _db = db; - } - } -} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Program.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Program.cs index 40a47641..b83debb4 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Server/Program.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Server/Program.cs @@ -1,33 +1,67 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; +using BlazingPizza.Server; +using Microsoft.AspNetCore.Authentication; +using Microsoft.EntityFrameworkCore; -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()) { - public class Program + var db = scope.ServiceProvider.GetRequiredService(); + if (db.Database.EnsureCreated()) { - 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(); - }); + SeedData.Initialize(db); } } + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + 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.MapPizzaApi(); + +app.MapRazorPages(); +app.MapControllers(); +app.MapFallbackToFile("index.html"); + +app.Run(); \ No newline at end of file diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/SeedData.cs b/save-points/07-javascript-interop/BlazingPizza.Server/SeedData.cs index 7c86a5b2..f02e2b77 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Server/SeedData.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Server/SeedData.cs @@ -1,193 +1,192 @@ -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public static class SeedData { - public static class SeedData + public static void Initialize(PizzaStoreContext db) { - public static void Initialize(PizzaStoreContext db) + var toppings = new Topping[] { - var toppings = new Topping[] + new Topping() { - new Topping() - { Name = "Extra cheese", Price = 2.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "American bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "British bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Canadian bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Tea and crumpets", Price = 5.00m - }, - new Topping() - { + }, + new Topping() + { Name = "Fresh-baked scones", Price = 4.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Bell peppers", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Onions", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Mushrooms", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Pepperoni", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Duck sausage", Price = 3.20m, - }, - new Topping() - { + }, + new Topping() + { Name = "Venison meatballs", Price = 2.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Served on a silver platter", Price = 250.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Lobster on top", Price = 64.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Sturgeon caviar", Price = 101.75m, - }, - new Topping() - { + }, + new Topping() + { Name = "Artichoke hearts", Price = 3.40m, - }, - new Topping() - { + }, + new Topping() + { Name = "Fresh tomatoes", Price = 1.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Basil", Price = 1.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Steak (medium-rare)", Price = 8.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Blazing hot peppers", Price = 4.20m, - }, - new Topping() - { + }, + new Topping() + { Name = "Buffalo chicken", Price = 5.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Blue cheese", Price = 2.50m, - }, - }; + }, + }; - var specials = new PizzaSpecial[] + var specials = new PizzaSpecial[] + { + 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() - { + }, + new PizzaSpecial() + { Id = 2, Name = "The Baconatorizor", Description = "It has EVERY kind of bacon", BasePrice = 11.99m, ImageUrl = "img/pizzas/bacon.jpg", - }, - new PizzaSpecial() - { + }, + 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() - { + }, + 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() - { + }, + 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() - { + }, + new PizzaSpecial() + { Id = 6, Name = "The Brit", Description = "When in London...", BasePrice = 10.25m, ImageUrl = "img/pizzas/brit.jpg", - }, - new PizzaSpecial() - { + }, + 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() - { + }, + new PizzaSpecial() + { Id = 8, Name = "Margherita", Description = "Traditional Italian pizza with tomatoes and basil", BasePrice = 9.99m, ImageUrl = "img/pizzas/margherita.jpg", - }, - }; + }, + }; - db.Toppings.AddRange(toppings); - db.Specials.AddRange(specials); - db.SaveChanges(); - } + db.Toppings.AddRange(toppings); + db.Specials.AddRange(specials); + db.SaveChanges(); } -} +} \ No newline at end of file diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/SpecialsController.cs b/save-points/07-javascript-interop/BlazingPizza.Server/SpecialsController.cs deleted file mode 100644 index a176844c..00000000 --- a/save-points/07-javascript-interop/BlazingPizza.Server/SpecialsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("specials")] - [ApiController] - public class SpecialsController : Controller - { - private readonly PizzaStoreContext _db; - - public SpecialsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetSpecials() - { - return (await _db.Specials.ToListAsync()).OrderByDescending(s => s.BasePrice).ToList(); - } - } -} diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/Startup.cs b/save-points/07-javascript-interop/BlazingPizza.Server/Startup.cs deleted file mode 100644 index ed3fca06..00000000 --- a/save-points/07-javascript-interop/BlazingPizza.Server/Startup.cs +++ /dev/null @@ -1,70 +0,0 @@ -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace BlazingPizza.Server -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - public void ConfigureServices(IServiceCollection services) - { - services.AddControllersWithViews(); - services.AddRazorPages(); - - services.AddDbContext(options => - options.UseSqlite("Data Source=pizza.db")); - - services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) - .AddEntityFrameworkStores(); - - services.AddIdentityServer() - .AddApiAuthorization(); - - services.AddAuthentication() - .AddIdentityServerJwt(); - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - app.UseWebAssemblyDebugging(); - } - else - { - app.UseExceptionHandler("/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); - } - - app.UseHttpsRedirection(); - app.UseBlazorFrameworkFiles(); - app.UseStaticFiles(); - - app.UseRouting(); - - app.UseAuthentication(); - app.UseIdentityServer(); - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - endpoints.MapRazorPages(); - endpoints.MapFallbackToFile("index.html"); - }); - } - } -} \ No newline at end of file diff --git a/save-points/07-javascript-interop/BlazingPizza.Server/ToppingsController.cs b/save-points/07-javascript-interop/BlazingPizza.Server/ToppingsController.cs deleted file mode 100644 index 6a677639..00000000 --- a/save-points/07-javascript-interop/BlazingPizza.Server/ToppingsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("toppings")] - [ApiController] - public class ToppingsController : Controller - { - private readonly PizzaStoreContext _db; - - public ToppingsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetToppings() - { - return await _db.Toppings.OrderBy(t => t.Name).ToListAsync(); - } - } -} diff --git a/save-points/07-javascript-interop/BlazingPizza.Shared/Address.cs b/save-points/07-javascript-interop/BlazingPizza.Shared/Address.cs index d76bc52a..a671359a 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Shared/Address.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Shared/Address.cs @@ -1,27 +1,24 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class Address { - public class Address - { - public int Id { get; set; } + public int Id { get; set; } - [Required, MaxLength(100)] - public string Name { get; set; } + [Required, MaxLength(100)] + public string Name { get; set; } - [Required, MaxLength(100)] - public string Line1 { get; set; } + [Required, MaxLength(100)] + public string Line1 { get; set; } - [MaxLength(100)] - public string Line2 { get; set; } + [MaxLength(100)] + public string Line2 { get; set; } - [Required, MaxLength(50)] - public string City { get; set; } + [Required, MaxLength(50)] + public string City { get; set; } - [Required, MaxLength(20)] - public string Region { get; set; } + [Required, MaxLength(20)] + public string Region { get; set; } - [Required, MaxLength(20)] - public string PostalCode { get; set; } - } + [Required, MaxLength(20)] + public string PostalCode { get; set; } } diff --git a/save-points/07-javascript-interop/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/save-points/07-javascript-interop/BlazingPizza.Shared/BlazingPizza.Shared.csproj index 911c57c5..fb17e53b 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/save-points/07-javascript-interop/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -1,10 +1,15 @@  - net5.0 + $(TargetFrameworkVersion) BlazingPizza + true + + + + diff --git a/save-points/07-javascript-interop/BlazingPizza.Shared/LatLong.cs b/save-points/07-javascript-interop/BlazingPizza.Shared/LatLong.cs index 9b8c3811..a65971f8 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Shared/LatLong.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Shared/LatLong.cs @@ -1,27 +1,26 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class LatLong { - public class LatLong + public LatLong() { - public LatLong() - { - } + } - public LatLong(double latitude, double longitude) : this() - { - Latitude = latitude; - Longitude = longitude; - } + public LatLong(double latitude, double longitude) : this() + { + Latitude = latitude; + Longitude = longitude; + } - public double Latitude { get; set; } + public double Latitude { get; set; } - public double Longitude { get; set; } + public double Longitude { get; set; } - public static LatLong Interpolate(LatLong start, LatLong end, double proportion) - { - // The Earth is flat, right? So no need for spherical interpolation. - return new LatLong( + public static LatLong Interpolate(LatLong start, LatLong end, double proportion) + { + // The Earth is flat, right? So no need for spherical interpolation. + return new LatLong( start.Latitude + (end.Latitude - start.Latitude) * proportion, start.Longitude + (end.Longitude - start.Longitude) * proportion); - } } -} +} \ No newline at end of file diff --git a/save-points/07-javascript-interop/BlazingPizza.Shared/NotificationSubscription.cs b/save-points/07-javascript-interop/BlazingPizza.Shared/NotificationSubscription.cs index 04259c2f..5c99e3f4 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Shared/NotificationSubscription.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Shared/NotificationSubscription.cs @@ -1,17 +1,14 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class NotificationSubscription { - public class NotificationSubscription - { - public int NotificationSubscriptionId { get; set; } + public int NotificationSubscriptionId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public string Url { get; set; } + public string Url { get; set; } - public string P256dh { get; set; } + public string P256dh { get; set; } - public string Auth { get; set; } - } + public string Auth { get; set; } } diff --git a/save-points/07-javascript-interop/BlazingPizza.Shared/Order.cs b/save-points/07-javascript-interop/BlazingPizza.Shared/Order.cs index fb003bd6..b47efad0 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Shared/Order.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Shared/Order.cs @@ -1,25 +1,32 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +public class Order { - public class Order - { - public int OrderId { get; set; } + public int OrderId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public DateTime CreatedTime { get; set; } + public DateTime CreatedTime { get; set; } - public Address DeliveryAddress { get; set; } = new Address(); + public Address DeliveryAddress { get; set; } = new Address(); - public LatLong DeliveryLocation { get; set; } + public LatLong DeliveryLocation { get; set; } - public List Pizzas { get; set; } = new List(); + public List Pizzas { get; set; } = new List(); - public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); + public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); - public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); - } + public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Default, PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] +[JsonSerializable(typeof(Order))] +[JsonSerializable(typeof(OrderWithStatus))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Pizza))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Topping))] +public partial class OrderContext : JsonSerializerContext { } \ No newline at end of file diff --git a/save-points/07-javascript-interop/BlazingPizza.Shared/OrderWithStatus.cs b/save-points/07-javascript-interop/BlazingPizza.Shared/OrderWithStatus.cs index 021de78c..fbfac7af 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Shared/OrderWithStatus.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Shared/OrderWithStatus.cs @@ -1,79 +1,78 @@ -using BlazingPizza.ComponentsLibrary.Map; -using System; -using System.Collections.Generic; +using System.Text.Json.Serialization; +using BlazingPizza.ComponentsLibrary.Map; -namespace BlazingPizza -{ - 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 Order Order { get; set; } +namespace BlazingPizza; - public string StatusText { get; set; } +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 bool IsDelivered => StatusText == "Delivered"; + public Order Order { get; set; } - public List MapMarkers { get; set; } + public string StatusText { 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 bool IsDelivered => StatusText == "Delivered"; - 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"; + public List MapMarkers { get; set; } - 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), - }; - } + 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); - return new OrderWithStatus - { - Order = order, - StatusText = statusText, - MapMarkers = mapMarkers, - }; + 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"; - private static LatLong ComputeStartPosition(Order order) + 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 { - // 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); + statusText = "Delivered"; + mapMarkers = new List + { + ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), + }; } - static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) - => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; + 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); + } + + static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) + => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; +} \ No newline at end of file diff --git a/save-points/07-javascript-interop/BlazingPizza.Shared/Pizza.cs b/save-points/07-javascript-interop/BlazingPizza.Shared/Pizza.cs index ec1108a9..2a7a1c29 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Shared/Pizza.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Shared/Pizza.cs @@ -1,42 +1,44 @@ -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// /// Represents a customized pizza as part of an order +/// +public class Pizza { - /// - /// Represents a customized pizza as part of an order - /// - public class Pizza - { - public const int DefaultSize = 12; - public const int MinimumSize = 9; - public const int MaximumSize = 17; + public const int DefaultSize = 12; + public const int MinimumSize = 9; + public const int MaximumSize = 17; - public int Id { get; set; } + public int Id { get; set; } - public int OrderId { get; set; } + public int OrderId { get; set; } - public PizzaSpecial Special { get; set; } + public PizzaSpecial Special { get; set; } - public int SpecialId { get; set; } + public int SpecialId { get; set; } - public int Size { get; set; } + public int Size { get; set; } - public List Toppings { get; set; } + public List Toppings { get; set; } - public decimal GetBasePrice() - { - return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; - } + public decimal GetBasePrice() + { + return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; + } - public decimal GetTotalPrice() - { - return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); - } + public decimal GetTotalPrice() + { + return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); + } - public string GetFormattedTotalPrice() - { - return GetTotalPrice().ToString("0.00"); - } + public string GetFormattedTotalPrice() + { + return GetTotalPrice().ToString("0.00"); } } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Serialization)] +[JsonSerializable(typeof(Pizza))] +public partial class PizzaContext : JsonSerializerContext { } \ No newline at end of file diff --git a/save-points/07-javascript-interop/BlazingPizza.Shared/PizzaSpecial.cs b/save-points/07-javascript-interop/BlazingPizza.Shared/PizzaSpecial.cs index 2f2b3383..1fd9006a 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Shared/PizzaSpecial.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Shared/PizzaSpecial.cs @@ -1,20 +1,19 @@ -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// Represents a pre-configured template for a pizza a user can order +/// +public class PizzaSpecial { - /// - /// Represents a pre-configured template for a pizza a user can order - /// - public class PizzaSpecial - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal BasePrice { get; set; } + public decimal BasePrice { get; set; } - public string Description { get; set; } + public string Description { get; set; } - public string ImageUrl { get; set; } + public string ImageUrl { get; set; } - public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); - } -} + public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); +} \ No newline at end of file diff --git a/save-points/07-javascript-interop/BlazingPizza.Shared/PizzaTopping.cs b/save-points/07-javascript-interop/BlazingPizza.Shared/PizzaTopping.cs index f5a6c1ac..1c062732 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Shared/PizzaTopping.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Shared/PizzaTopping.cs @@ -1,11 +1,11 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class PizzaTopping { - public class PizzaTopping - { - public Topping Topping { get; set; } - - public int ToppingId { get; set; } - - public int PizzaId { get; set; } - } -} + public Topping Topping { get; set; } + + public int ToppingId { get; set; } + + public int PizzaId { get; set; } + +} \ No newline at end of file diff --git a/save-points/07-javascript-interop/BlazingPizza.Shared/Topping.cs b/save-points/07-javascript-interop/BlazingPizza.Shared/Topping.cs index 61bdeb92..4eb67ae9 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Shared/Topping.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Shared/Topping.cs @@ -1,13 +1,13 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class Topping { - public class Topping - { - public int Id { get; set; } + public int Id { get; set; } + + public string Name { get; set; } - public string Name { get; set; } + public decimal Price { get; set; } - public decimal Price { get; set; } + public string GetFormattedPrice() => Price.ToString("0.00"); - public string GetFormattedPrice() => Price.ToString("0.00"); - } -} +} \ No newline at end of file diff --git a/save-points/07-javascript-interop/BlazingPizza.Shared/UserInfo.cs b/save-points/07-javascript-interop/BlazingPizza.Shared/UserInfo.cs index 4996ef80..babb4315 100644 --- a/save-points/07-javascript-interop/BlazingPizza.Shared/UserInfo.cs +++ b/save-points/07-javascript-interop/BlazingPizza.Shared/UserInfo.cs @@ -1,9 +1,9 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class UserInfo { - public class UserInfo - { - public bool IsAuthenticated { get; set; } + public bool IsAuthenticated { get; set; } + + public string Name { get; set; } - public string Name { get; set; } - } -} +} \ No newline at end of file diff --git a/save-points/08-templated-components/BlazingComponents/BlazingComponents.csproj b/save-points/08-templated-components/BlazingComponents/BlazingComponents.csproj index 6325ad64..e0a4b76a 100644 --- a/save-points/08-templated-components/BlazingComponents/BlazingComponents.csproj +++ b/save-points/08-templated-components/BlazingComponents/BlazingComponents.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/save-points/08-templated-components/BlazingPizza.Client/BlazingPizza.Client.csproj b/save-points/08-templated-components/BlazingPizza.Client/BlazingPizza.Client.csproj index c6ff02af..44802d79 100644 --- a/save-points/08-templated-components/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/save-points/08-templated-components/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -1,13 +1,15 @@  - net5.0 + $(TargetFrameworkVersion) + true + - + diff --git a/save-points/08-templated-components/BlazingPizza.Client/JSRuntimeExtensions.cs b/save-points/08-templated-components/BlazingPizza.Client/JSRuntimeExtensions.cs index 89da520c..ef171321 100644 --- a/save-points/08-templated-components/BlazingPizza.Client/JSRuntimeExtensions.cs +++ b/save-points/08-templated-components/BlazingPizza.Client/JSRuntimeExtensions.cs @@ -1,13 +1,11 @@ using Microsoft.JSInterop; -using System.Threading.Tasks; -namespace BlazingPizza.Client +namespace BlazingPizza.Client; + +public static class JSRuntimeExtensions { - public static class JSRuntimeExtensions + public static ValueTask Confirm(this IJSRuntime jsRuntime, string message) { - public static ValueTask Confirm(this IJSRuntime jsRuntime, string message) - { - return jsRuntime.InvokeAsync("confirm", message); - } + return jsRuntime.InvokeAsync("confirm", message); } } diff --git a/save-points/08-templated-components/BlazingPizza.Client/OrderState.cs b/save-points/08-templated-components/BlazingPizza.Client/OrderState.cs index 5265ae39..00dd3627 100644 --- a/save-points/08-templated-components/BlazingPizza.Client/OrderState.cs +++ b/save-points/08-templated-components/BlazingPizza.Client/OrderState.cs @@ -1,55 +1,52 @@ -using System.Collections.Generic; +namespace BlazingPizza.Client; -namespace BlazingPizza.Client +public class OrderState { - public class OrderState - { - public bool ShowingConfigureDialog { get; private set; } + public bool ShowingConfigureDialog { get; private set; } - public Pizza ConfiguringPizza { get; private set; } + public Pizza ConfiguringPizza { get; private set; } - public Order Order { get; private set; } = new Order(); + 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() + public void ShowConfigurePizzaDialog(PizzaSpecial special) + { + ConfiguringPizza = new Pizza() { - ConfiguringPizza = null; - ShowingConfigureDialog = false; - } + Special = special, + SpecialId = special.Id, + Size = Pizza.DefaultSize, + Toppings = new List(), + }; - public void ConfirmConfigurePizzaDialog() - { - Order.Pizzas.Add(ConfiguringPizza); - ConfiguringPizza = null; + ShowingConfigureDialog = true; + } - ShowingConfigureDialog = false; - } + public void CancelConfigurePizzaDialog() + { + ConfiguringPizza = null; + ShowingConfigureDialog = false; + } - public void RemoveConfiguredPizza(Pizza pizza) - { - Order.Pizzas.Remove(pizza); - } + public void ConfirmConfigurePizzaDialog() + { + Order.Pizzas.Add(ConfiguringPizza); + ConfiguringPizza = null; - public void ResetOrder() - { - Order = new Order(); - } + ShowingConfigureDialog = false; + } - public void ReplaceOrder(Order order) - { - Order = order; - } + public void RemoveConfiguredPizza(Pizza pizza) + { + Order.Pizzas.Remove(pizza); + } + + public void ResetOrder() + { + Order = new Order(); + } + + public void ReplaceOrder(Order order) + { + Order = order; } } diff --git a/save-points/08-templated-components/BlazingPizza.Client/OrdersClient.cs b/save-points/08-templated-components/BlazingPizza.Client/OrdersClient.cs index 0f800e6f..b4a08f1e 100644 --- a/save-points/08-templated-components/BlazingPizza.Client/OrdersClient.cs +++ b/save-points/08-templated-components/BlazingPizza.Client/OrdersClient.cs @@ -1,35 +1,36 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Net.Http.Json; -using System.Threading.Tasks; - -namespace BlazingPizza.Client +using System.Net.Http.Json; +using System.Text.Json; + +namespace BlazingPizza.Client; + +public class OrdersClient { - public class OrdersClient + private readonly HttpClient httpClient; + + public OrdersClient(HttpClient httpClient) { - private readonly HttpClient httpClient; + this.httpClient = httpClient; + } - public OrdersClient(HttpClient httpClient) - { - this.httpClient = httpClient; - } + public async Task> GetOrders() => + await httpClient.GetFromJsonAsync("orders", OrderContext.Default.ListOrderWithStatus); - public async Task> GetOrders() => - await httpClient.GetFromJsonAsync>("orders"); + public async Task GetOrder(int orderId) => + await httpClient.GetFromJsonAsync($"orders/{orderId}", OrderContext.Default.OrderWithStatus); - public async Task GetOrder(int orderId) => - await httpClient.GetFromJsonAsync($"orders/{orderId}"); + public async Task PlaceOrder(Order order) + { + var response = await httpClient.PostAsJsonAsync("orders", order, OrderContext.Default.Order); + response.EnsureSuccessStatusCode(); + var orderId = await response.Content.ReadFromJsonAsync(); + return orderId; + } - public async Task PlaceOrder(Order order) - { - var response = await httpClient.PostAsJsonAsync("orders", order); - response.EnsureSuccessStatusCode(); - var orderId = await response.Content.ReadFromJsonAsync(); - return orderId; - } + public async Task SubscribeToNotifications(NotificationSubscription subscription) + { + var response = await httpClient.PutAsJsonAsync("notifications/subscribe", subscription); + response.EnsureSuccessStatusCode(); } -} \ No newline at end of file +} diff --git a/save-points/08-templated-components/BlazingPizza.Client/Pages/Checkout.razor b/save-points/08-templated-components/BlazingPizza.Client/Pages/Checkout.razor index 7c6419f3..44b01467 100644 --- a/save-points/08-templated-components/BlazingPizza.Client/Pages/Checkout.razor +++ b/save-points/08-templated-components/BlazingPizza.Client/Pages/Checkout.razor @@ -4,6 +4,8 @@ @inject OrdersClient OrdersClient @inject NavigationManager NavigationManager +Blazing Pizza - Checkout +
diff --git a/save-points/08-templated-components/BlazingPizza.Client/Pages/MyOrders.razor b/save-points/08-templated-components/BlazingPizza.Client/Pages/MyOrders.razor index e4e6f953..8d97c52d 100644 --- a/save-points/08-templated-components/BlazingPizza.Client/Pages/MyOrders.razor +++ b/save-points/08-templated-components/BlazingPizza.Client/Pages/MyOrders.razor @@ -3,6 +3,8 @@ @inject OrdersClient OrdersClient @inject NavigationManager NavigationManager +Blazing Pizza - My Orders +
Loading... diff --git a/save-points/08-templated-components/BlazingPizza.Client/Pages/OrderDetails.razor b/save-points/08-templated-components/BlazingPizza.Client/Pages/OrderDetails.razor index 7df9161e..548bbd59 100644 --- a/save-points/08-templated-components/BlazingPizza.Client/Pages/OrderDetails.razor +++ b/save-points/08-templated-components/BlazingPizza.Client/Pages/OrderDetails.razor @@ -5,6 +5,8 @@ @inject NavigationManager NavigationManager @implements IDisposable +Blazing Pizza - Order Details +
@if (invalidOrder) { diff --git a/save-points/08-templated-components/BlazingPizza.Client/PizzaAuthenticationState.cs b/save-points/08-templated-components/BlazingPizza.Client/PizzaAuthenticationState.cs index 3f295928..78627625 100644 --- a/save-points/08-templated-components/BlazingPizza.Client/PizzaAuthenticationState.cs +++ b/save-points/08-templated-components/BlazingPizza.Client/PizzaAuthenticationState.cs @@ -1,9 +1,8 @@ using Microsoft.AspNetCore.Components.WebAssembly.Authentication; -namespace BlazingPizza.Client +namespace BlazingPizza.Client; + +public class PizzaAuthenticationState : RemoteAuthenticationState { - public class PizzaAuthenticationState : RemoteAuthenticationState - { - public Order Order { get; set; } - } + public Order Order { get; set; } } diff --git a/save-points/08-templated-components/BlazingPizza.Client/Program.cs b/save-points/08-templated-components/BlazingPizza.Client/Program.cs index afeee128..c2129f0b 100644 --- a/save-points/08-templated-components/BlazingPizza.Client/Program.cs +++ b/save-points/08-templated-components/BlazingPizza.Client/Program.cs @@ -1,31 +1,21 @@ -using Microsoft.AspNetCore.Components.WebAssembly.Authentication; +using BlazingPizza.Client; +using Microsoft.AspNetCore.Components.Web; +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; -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.RootComponents.Add("head::after"); - builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); - builder.Services.AddHttpClient(client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)) - .AddHttpMessageHandler(); - builder.Services.AddScoped(); +builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); +builder.Services.AddHttpClient(client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)) + .AddHttpMessageHandler(); +builder.Services.AddScoped(); - // Add auth services - builder.Services.AddApiAuthorization(options => - { - options.AuthenticationPaths.LogOutSucceededPath = ""; - }); +// Add auth services +builder.Services.AddApiAuthorization(options => { + options.AuthenticationPaths.LogOutSucceededPath = ""; +}); - await builder.Build().RunAsync(); - } - } -} +await builder.Build().RunAsync(); diff --git a/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 5f51ee3c..cb996b1b 100644 --- a/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -1,7 +1,8 @@  - net5.0 + $(TargetFrameworkVersion) + true diff --git a/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/LocalStorage.cs b/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/LocalStorage.cs index f36b098e..be8226ec 100644 --- a/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/LocalStorage.cs +++ b/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/LocalStorage.cs @@ -1,17 +1,15 @@ using Microsoft.JSInterop; -using System.Threading.Tasks; -namespace BlazingPizza.ComponentsLibrary +namespace BlazingPizza.ComponentsLibrary; + +public static class LocalStorage { - public static class LocalStorage - { - public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) + public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); - public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object 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) + public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key) => jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key); - } -} +} \ No newline at end of file diff --git a/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/Map/Marker.cs b/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/Map/Marker.cs index 63006067..b067719c 100644 --- a/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/Map/Marker.cs +++ b/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/Map/Marker.cs @@ -1,13 +1,12 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Marker { - public class Marker - { - public string Description { get; set; } + public string Description { get; set; } - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } + public double Y { get; set; } - public bool ShowPopup { get; set; } - } + public bool ShowPopup { get; set; } } diff --git a/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/Map/Point.cs b/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/Map/Point.cs index 03841826..34194163 100644 --- a/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/Map/Point.cs +++ b/save-points/08-templated-components/BlazingPizza.ComponentsLibrary/Map/Point.cs @@ -1,9 +1,8 @@ -namespace BlazingPizza.ComponentsLibrary.Map +namespace BlazingPizza.ComponentsLibrary.Map; + +public class Point { - public class Point - { - public double X { get; set; } + public double X { get; set; } - public double Y { get; set; } - } -} + public double Y { get; set; } +} \ No newline at end of file diff --git a/save-points/08-templated-components/BlazingPizza.Server/BlazingPizza.Server.csproj b/save-points/08-templated-components/BlazingPizza.Server/BlazingPizza.Server.csproj index fd7e3c51..abd2317b 100644 --- a/save-points/08-templated-components/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/save-points/08-templated-components/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -1,7 +1,8 @@  - net5.0 + $(TargetFrameworkVersion) + true @@ -13,6 +14,7 @@ + diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/AddressEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/AddressEntityType.cs new file mode 100644 index 00000000..82db81b6 --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/AddressEntityType.cs @@ -0,0 +1,92 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class AddressEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Address", + typeof(Address), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Address).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var city = runtimeEntityType.AddProperty( + "City", + typeof(string), + propertyInfo: typeof(Address).GetProperty("City", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var line1 = runtimeEntityType.AddProperty( + "Line1", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line1", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var line2 = runtimeEntityType.AddProperty( + "Line2", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line2", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var postalCode = runtimeEntityType.AddProperty( + "PostalCode", + typeof(string), + propertyInfo: typeof(Address).GetProperty("PostalCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var region = runtimeEntityType.AddProperty( + "Region", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Region", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Address"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs new file mode 100644 index 00000000..1dd4563b --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs @@ -0,0 +1,114 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class DeviceFlowCodesEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.DeviceFlowCodes", + typeof(DeviceFlowCodes), + baseEntityType); + + var userCode = runtimeEntityType.AddProperty( + "UserCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("UserCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var deviceCode = runtimeEntityType.AddProperty( + "DeviceCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("DeviceCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var key = runtimeEntityType.AddKey( + new[] { userCode }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deviceCode }, + unique: true); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "DeviceCodes"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs new file mode 100644 index 00000000..8946b261 --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRoleClaim", + typeof(IdentityRoleClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoleClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityRoleEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityRoleEntityType.cs new file mode 100644 index 00000000..2f1fec2b --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityRoleEntityType.cs @@ -0,0 +1,78 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRole", + typeof(IdentityRole), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedName = runtimeEntityType.AddProperty( + "NormalizedName", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("NormalizedName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedName }, + unique: true); + index.AddAnnotation("Relational:Name", "RoleNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs new file mode 100644 index 00000000..55418a1e --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserClaim", + typeof(IdentityUserClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityUserClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs new file mode 100644 index 00000000..3ca029bd --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserLoginstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserLogin", + typeof(IdentityUserLogin), + baseEntityType); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerKey = runtimeEntityType.AddProperty( + "ProviderKey", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderKey", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerDisplayName = runtimeEntityType.AddProperty( + "ProviderDisplayName", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderDisplayName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { loginProvider, providerKey }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserLogins"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs new file mode 100644 index 00000000..70078d7a --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs @@ -0,0 +1,82 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserRolestringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserRole", + typeof(IdentityUserRole), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { userId, roleId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs new file mode 100644 index 00000000..93ba6d31 --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs @@ -0,0 +1,84 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserTokenstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserToken", + typeof(IdentityUserToken), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var value = runtimeEntityType.AddProperty( + "Value", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Value", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { userId, loginProvider, name }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserTokens"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/KeyEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/KeyEntityType.cs new file mode 100644 index 00000000..f6c6b4c7 --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/KeyEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class KeyEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.Key", + typeof(Key), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var algorithm = runtimeEntityType.AddProperty( + "Algorithm", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Algorithm", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var created = runtimeEntityType.AddProperty( + "Created", + typeof(DateTime), + propertyInfo: typeof(Key).GetProperty("Created", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var dataProtected = runtimeEntityType.AddProperty( + "DataProtected", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("DataProtected", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var isX509Certificate = runtimeEntityType.AddProperty( + "IsX509Certificate", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("IsX509Certificate", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var use = runtimeEntityType.AddProperty( + "Use", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Use", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var version = runtimeEntityType.AddProperty( + "Version", + typeof(int), + propertyInfo: typeof(Key).GetProperty("Version", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { use }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Keys"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/LatLongEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/LatLongEntityType.cs new file mode 100644 index 00000000..3fd254bd --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/LatLongEntityType.cs @@ -0,0 +1,80 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class LatLongEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.LatLong", + typeof(LatLong), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var latitude = runtimeEntityType.AddProperty( + "Latitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Latitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var longitude = runtimeEntityType.AddProperty( + "Longitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Longitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + unique: true, + required: true, + ownership: true); + + var deliveryLocation = principalEntityType.AddNavigation("DeliveryLocation", + runtimeForeignKey, + onDependent: false, + typeof(LatLong), + propertyInfo: typeof(Order).GetProperty("DeliveryLocation", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + eagerLoaded: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs new file mode 100644 index 00000000..db236e4c --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs @@ -0,0 +1,77 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class NotificationSubscriptionEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.NotificationSubscription", + typeof(NotificationSubscription), + baseEntityType); + + var notificationSubscriptionId = runtimeEntityType.AddProperty( + "NotificationSubscriptionId", + typeof(int), + propertyInfo: typeof(NotificationSubscription).GetProperty("NotificationSubscriptionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var auth = runtimeEntityType.AddProperty( + "Auth", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Auth", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var p256dh = runtimeEntityType.AddProperty( + "P256dh", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("P256dh", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var url = runtimeEntityType.AddProperty( + "Url", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Url", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { notificationSubscriptionId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "NotificationSubscriptions"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/OrderEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/OrderEntityType.cs new file mode 100644 index 00000000..9d9ec6fd --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/OrderEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class OrderEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Order", + typeof(Order), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Order).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var createdTime = runtimeEntityType.AddProperty( + "CreatedTime", + typeof(DateTime), + propertyInfo: typeof(Order).GetProperty("CreatedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var deliveryAddressId = runtimeEntityType.AddProperty( + "DeliveryAddressId", + typeof(int?), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(Order).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deliveryAddressId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("DeliveryAddressId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType); + + var deliveryAddress = declaringEntityType.AddNavigation("DeliveryAddress", + runtimeForeignKey, + onDependent: true, + typeof(Address), + propertyInfo: typeof(Order).GetProperty("DeliveryAddress", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/PersistedGrantEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/PersistedGrantEntityType.cs new file mode 100644 index 00000000..842d53a5 --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/PersistedGrantEntityType.cs @@ -0,0 +1,127 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PersistedGrantEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.PersistedGrant", + typeof(PersistedGrant), + baseEntityType); + + var key = runtimeEntityType.AddProperty( + "Key", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Key", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var consumedTime = runtimeEntityType.AddProperty( + "ConsumedTime", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("ConsumedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(PersistedGrant).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var type = runtimeEntityType.AddProperty( + "Type", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Type", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var key0 = runtimeEntityType.AddKey( + new[] { key }); + runtimeEntityType.SetPrimaryKey(key0); + + var index = runtimeEntityType.AddIndex( + new[] { consumedTime }); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + var index1 = runtimeEntityType.AddIndex( + new[] { subjectId, clientId, type }); + + var index2 = runtimeEntityType.AddIndex( + new[] { subjectId, sessionId, type }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PersistedGrants"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaEntityType.cs new file mode 100644 index 00000000..3a124e63 --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaEntityType.cs @@ -0,0 +1,111 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Pizza", + typeof(Pizza), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var size = runtimeEntityType.AddProperty( + "Size", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Size", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var specialId = runtimeEntityType.AddProperty( + "SpecialId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("SpecialId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { orderId }); + + var index0 = runtimeEntityType.AddIndex( + new[] { specialId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var pizzas = principalEntityType.AddNavigation("Pizzas", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Order).GetProperty("Pizzas", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("SpecialId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var special = declaringEntityType.AddNavigation("Special", + runtimeForeignKey, + onDependent: true, + typeof(PizzaSpecial), + propertyInfo: typeof(Pizza).GetProperty("Special", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Pizzas"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs new file mode 100644 index 00000000..e86b0f50 --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs @@ -0,0 +1,76 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaSpecialEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaSpecial", + typeof(PizzaSpecial), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(PizzaSpecial).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var basePrice = runtimeEntityType.AddProperty( + "BasePrice", + typeof(decimal), + propertyInfo: typeof(PizzaSpecial).GetProperty("BasePrice", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var imageUrl = runtimeEntityType.AddProperty( + "ImageUrl", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("ImageUrl", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Specials"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaStoreContextModel.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaStoreContextModel.cs new file mode 100644 index 00000000..8b516a68 --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaStoreContextModel.cs @@ -0,0 +1,28 @@ +// +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + [DbContext(typeof(PizzaStoreContext))] + public partial class PizzaStoreContextModel : RuntimeModel + { + static PizzaStoreContextModel() + { + var model = new PizzaStoreContextModel(); + model.Initialize(); + model.Customize(); + _instance = model; + } + + private static PizzaStoreContextModel _instance; + public static IModel Instance => _instance; + + partial void Initialize(); + + partial void Customize(); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs new file mode 100644 index 00000000..d46f50f4 --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs @@ -0,0 +1,69 @@ +// +using System; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + public partial class PizzaStoreContextModel + { + partial void Initialize() + { + var address = AddressEntityType.Create(this); + var latLong = LatLongEntityType.Create(this); + var notificationSubscription = NotificationSubscriptionEntityType.Create(this); + var order = OrderEntityType.Create(this); + var pizza = PizzaEntityType.Create(this); + var pizzaSpecial = PizzaSpecialEntityType.Create(this); + var pizzaTopping = PizzaToppingEntityType.Create(this); + var pizzaStoreUser = PizzaStoreUserEntityType.Create(this); + var topping = ToppingEntityType.Create(this); + var deviceFlowCodes = DeviceFlowCodesEntityType.Create(this); + var key = KeyEntityType.Create(this); + var persistedGrant = PersistedGrantEntityType.Create(this); + var identityRole = IdentityRoleEntityType.Create(this); + var identityRoleClaimstring = IdentityRoleClaimstringEntityType.Create(this); + var identityUserClaimstring = IdentityUserClaimstringEntityType.Create(this); + var identityUserLoginstring = IdentityUserLoginstringEntityType.Create(this); + var identityUserRolestring = IdentityUserRolestringEntityType.Create(this); + var identityUserTokenstring = IdentityUserTokenstringEntityType.Create(this); + + LatLongEntityType.CreateForeignKey1(latLong, order); + OrderEntityType.CreateForeignKey1(order, address); + PizzaEntityType.CreateForeignKey1(pizza, order); + PizzaEntityType.CreateForeignKey2(pizza, pizzaSpecial); + PizzaToppingEntityType.CreateForeignKey1(pizzaTopping, pizza); + PizzaToppingEntityType.CreateForeignKey2(pizzaTopping, topping); + IdentityRoleClaimstringEntityType.CreateForeignKey1(identityRoleClaimstring, identityRole); + IdentityUserClaimstringEntityType.CreateForeignKey1(identityUserClaimstring, pizzaStoreUser); + IdentityUserLoginstringEntityType.CreateForeignKey1(identityUserLoginstring, pizzaStoreUser); + IdentityUserRolestringEntityType.CreateForeignKey1(identityUserRolestring, identityRole); + IdentityUserRolestringEntityType.CreateForeignKey2(identityUserRolestring, pizzaStoreUser); + IdentityUserTokenstringEntityType.CreateForeignKey1(identityUserTokenstring, pizzaStoreUser); + + AddressEntityType.CreateAnnotations(address); + LatLongEntityType.CreateAnnotations(latLong); + NotificationSubscriptionEntityType.CreateAnnotations(notificationSubscription); + OrderEntityType.CreateAnnotations(order); + PizzaEntityType.CreateAnnotations(pizza); + PizzaSpecialEntityType.CreateAnnotations(pizzaSpecial); + PizzaToppingEntityType.CreateAnnotations(pizzaTopping); + PizzaStoreUserEntityType.CreateAnnotations(pizzaStoreUser); + ToppingEntityType.CreateAnnotations(topping); + DeviceFlowCodesEntityType.CreateAnnotations(deviceFlowCodes); + KeyEntityType.CreateAnnotations(key); + PersistedGrantEntityType.CreateAnnotations(persistedGrant); + IdentityRoleEntityType.CreateAnnotations(identityRole); + IdentityRoleClaimstringEntityType.CreateAnnotations(identityRoleClaimstring); + IdentityUserClaimstringEntityType.CreateAnnotations(identityUserClaimstring); + IdentityUserLoginstringEntityType.CreateAnnotations(identityUserLoginstring); + IdentityUserRolestringEntityType.CreateAnnotations(identityUserRolestring); + IdentityUserTokenstringEntityType.CreateAnnotations(identityUserTokenstring); + + AddAnnotation("ProductVersion", "6.0.0"); + } + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs new file mode 100644 index 00000000..18b2d96d --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs @@ -0,0 +1,156 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaStoreUserEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Server.PizzaStoreUser", + typeof(PizzaStoreUser), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var accessFailedCount = runtimeEntityType.AddProperty( + "AccessFailedCount", + typeof(int), + propertyInfo: typeof(IdentityUser).GetProperty("AccessFailedCount", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var email = runtimeEntityType.AddProperty( + "Email", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Email", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var emailConfirmed = runtimeEntityType.AddProperty( + "EmailConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("EmailConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnabled = runtimeEntityType.AddProperty( + "LockoutEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnd = runtimeEntityType.AddProperty( + "LockoutEnd", + typeof(DateTimeOffset?), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnd", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var normalizedEmail = runtimeEntityType.AddProperty( + "NormalizedEmail", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedEmail", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedUserName = runtimeEntityType.AddProperty( + "NormalizedUserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedUserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var passwordHash = runtimeEntityType.AddProperty( + "PasswordHash", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PasswordHash", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumber = runtimeEntityType.AddProperty( + "PhoneNumber", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumber", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumberConfirmed = runtimeEntityType.AddProperty( + "PhoneNumberConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumberConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var securityStamp = runtimeEntityType.AddProperty( + "SecurityStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("SecurityStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var twoFactorEnabled = runtimeEntityType.AddProperty( + "TwoFactorEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("TwoFactorEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var userName = runtimeEntityType.AddProperty( + "UserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("UserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedEmail }); + index.AddAnnotation("Relational:Name", "EmailIndex"); + + var index0 = runtimeEntityType.AddIndex( + new[] { normalizedUserName }, + unique: true); + index0.AddAnnotation("Relational:Name", "UserNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUsers"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaToppingEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaToppingEntityType.cs new file mode 100644 index 00000000..b97d2a24 --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/PizzaToppingEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaTopping", + typeof(PizzaTopping), + baseEntityType); + + var pizzaId = runtimeEntityType.AddProperty( + "PizzaId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("PizzaId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var toppingId = runtimeEntityType.AddProperty( + "ToppingId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("ToppingId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { pizzaId, toppingId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { toppingId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("PizzaId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var toppings = principalEntityType.AddNavigation("Toppings", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Pizza).GetProperty("Toppings", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("ToppingId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var topping = declaringEntityType.AddNavigation("Topping", + runtimeForeignKey, + onDependent: true, + typeof(Topping), + propertyInfo: typeof(PizzaTopping).GetProperty("Topping", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PizzaTopping"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Models/ToppingEntityType.cs b/save-points/08-templated-components/BlazingPizza.Server/Models/ToppingEntityType.cs new file mode 100644 index 00000000..9295f9bf --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/Models/ToppingEntityType.cs @@ -0,0 +1,62 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class ToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Topping", + typeof(Topping), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Topping).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Topping).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var price = runtimeEntityType.AddProperty( + "Price", + typeof(decimal), + propertyInfo: typeof(Topping).GetProperty("Price", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Toppings"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/08-templated-components/BlazingPizza.Server/NotificationsController.cs b/save-points/08-templated-components/BlazingPizza.Server/NotificationsController.cs deleted file mode 100644 index bb3b96ff..00000000 --- a/save-points/08-templated-components/BlazingPizza.Server/NotificationsController.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("notifications")] - [ApiController] - [Authorize] - public class NotificationsController : Controller - { - private readonly PizzaStoreContext _db; - - public NotificationsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpPut("subscribe")] - public async Task Subscribe(NotificationSubscription subscription) - { - // We're storing at most one subscription per user, so delete old ones. - // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. - var userId = GetUserId(); - var oldSubscriptions = _db.NotificationSubscriptions.Where(e => e.UserId == userId); - _db.NotificationSubscriptions.RemoveRange(oldSubscriptions); - - // Store new subscription - subscription.UserId = userId; - _db.NotificationSubscriptions.Attach(subscription); - - await _db.SaveChangesAsync(); - return subscription; - } - - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } - } -} diff --git a/save-points/08-templated-components/BlazingPizza.Server/OidcConfigurationController.cs b/save-points/08-templated-components/BlazingPizza.Server/OidcConfigurationController.cs index c074debf..1431697e 100644 --- a/save-points/08-templated-components/BlazingPizza.Server/OidcConfigurationController.cs +++ b/save-points/08-templated-components/BlazingPizza.Server/OidcConfigurationController.cs @@ -1,26 +1,21 @@ using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class OidcConfigurationController : Controller { - public class OidcConfigurationController : Controller + public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) { - public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) - { - ClientRequestParametersProvider = clientRequestParametersProvider; - } + ClientRequestParametersProvider = clientRequestParametersProvider; + } - public IClientRequestParametersProvider ClientRequestParametersProvider { get; } + public IClientRequestParametersProvider ClientRequestParametersProvider { get; } - [HttpGet("_configuration/{clientId}")] - public IActionResult GetClientRequestParameters([FromRoute]string clientId) - { - var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); - return Ok(parameters); - } + [HttpGet("_configuration/{clientId}")] + public IActionResult GetClientRequestParameters([FromRoute] string clientId) + { + var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); + return Ok(parameters); } } diff --git a/save-points/08-templated-components/BlazingPizza.Server/OrdersController.cs b/save-points/08-templated-components/BlazingPizza.Server/OrdersController.cs index 72b59890..3d2ba63f 100644 --- a/save-points/08-templated-components/BlazingPizza.Server/OrdersController.cs +++ b/save-points/08-templated-components/BlazingPizza.Server/OrdersController.cs @@ -1,30 +1,28 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; +using System.Security.Claims; +using System.Text.Json; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using WebPush; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +[Route("orders")] +[ApiController] +[Authorize] +public class OrdersController : Controller { - [Route("orders")] - [ApiController] - [Authorize] - public class OrdersController : Controller - { - private readonly PizzaStoreContext _db; + private readonly PizzaStoreContext _db; - public OrdersController(PizzaStoreContext db) - { - _db = db; - } + public OrdersController(PizzaStoreContext db) + { + _db = db; + } - [HttpGet] - public async Task>> GetOrders() - { - var orders = await _db.Orders + [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) @@ -32,13 +30,13 @@ public async Task>> GetOrders() .OrderByDescending(o => o.CreatedTime) .ToListAsync(); - return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); - } + return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); + } - [HttpGet("{orderId}")] - public async Task> GetOrderWithStatus(int orderId) - { - var order = await _db.Orders + [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) @@ -46,70 +44,87 @@ public async Task> GetOrderWithStatus(int orderId) .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) .SingleOrDefaultAsync(); - if (order == null) - { - return NotFound(); - } - - return OrderWithStatus.FromOrder(order); + if (order == null) + { + return NotFound(); } - [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; - } - } + return OrderWithStatus.FromOrder(order); + } - _db.Orders.Attach(order); - await _db.SaveChangesAsync(); + [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; - // In the background, send push notifications if possible - var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); - if (subscription != null) + foreach (var topping in pizza.Toppings) { - _ = TrackAndSendNotificationsAsync(order, subscription); + topping.ToppingId = topping.Topping.Id; + topping.Topping = null; } - - return order.OrderId; } - private string GetUserId() + _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) { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); + _ = TrackAndSendNotificationsAsync(order, subscription); } - private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription 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 { - // 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!"); + var payload = JsonSerializer.Serialize(new + { + message, + url = $"myorders/{order.OrderId}", + }); + await webPushClient.SendNotificationAsync(pushSubscription, payload, vapidDetails); } - - private static Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) + catch (Exception ex) { - // This will be implemented later - return Task.CompletedTask; + Console.Error.WriteLine("Error sending push notification: " + ex.Message); } } } diff --git a/save-points/08-templated-components/BlazingPizza.Server/PizzaApiExtensions.cs b/save-points/08-templated-components/BlazingPizza.Server/PizzaApiExtensions.cs new file mode 100644 index 00000000..524ca759 --- /dev/null +++ b/save-points/08-templated-components/BlazingPizza.Server/PizzaApiExtensions.cs @@ -0,0 +1,57 @@ +using System.Security.Claims; +using Microsoft.AspNetCore.Authorization; +using Microsoft.EntityFrameworkCore; + +namespace BlazingPizza.Server; + +public static class PizzaApiExtensions +{ + + public static WebApplication MapPizzaApi(this WebApplication app) + { + + // Subscribe to notifications + app.MapPut("/notifications/subscribe", [Authorize] async ( + HttpContext context, + PizzaStoreContext db, + NotificationSubscription subscription) => { + + // We're storing at most one subscription per user, so delete old ones. + // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. + var userId = GetUserId(context); + var oldSubscriptions = db.NotificationSubscriptions.Where(e => e.UserId == userId); + db.NotificationSubscriptions.RemoveRange(oldSubscriptions); + + // Store new subscription + subscription.UserId = userId; + db.NotificationSubscriptions.Attach(subscription); + + await db.SaveChangesAsync(); + return Results.Ok(subscription); + + }); + + // Specials + app.MapGet("/specials", async (PizzaStoreContext db) => { + + var specials = await db.Specials.ToListAsync(); + return Results.Ok(specials); + + }); + + // Toppings + app.MapGet("/toppings", async (PizzaStoreContext db) => { + var toppings = await db.Toppings.OrderBy(t => t.Name).ToListAsync(); + return Results.Ok(toppings); + }); + + return app; + + } + + private static string GetUserId(HttpContext context) + { + return context.User.FindFirstValue(ClaimTypes.NameIdentifier); + } + +} \ No newline at end of file diff --git a/save-points/08-templated-components/BlazingPizza.Server/PizzaStoreContext.cs b/save-points/08-templated-components/BlazingPizza.Server/PizzaStoreContext.cs index f79c1c66..50ac87e4 100644 --- a/save-points/08-templated-components/BlazingPizza.Server/PizzaStoreContext.cs +++ b/save-points/08-templated-components/BlazingPizza.Server/PizzaStoreContext.cs @@ -1,39 +1,38 @@ -using IdentityServer4.EntityFramework.Options; +using Duende.IdentityServer.EntityFramework.Options; using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class PizzaStoreContext : ApiAuthorizationDbContext { - public class PizzaStoreContext : ApiAuthorizationDbContext - { - public PizzaStoreContext( + 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/08-templated-components/BlazingPizza.Server/PizzaStoreUser.cs b/save-points/08-templated-components/BlazingPizza.Server/PizzaStoreUser.cs index 171ce83d..7ab40235 100644 --- a/save-points/08-templated-components/BlazingPizza.Server/PizzaStoreUser.cs +++ b/save-points/08-templated-components/BlazingPizza.Server/PizzaStoreUser.cs @@ -1,8 +1,5 @@ using Microsoft.AspNetCore.Identity; -namespace BlazingPizza.Server -{ - public class PizzaStoreUser : IdentityUser - { - } -} \ No newline at end of file +namespace BlazingPizza.Server; + +public class PizzaStoreUser : IdentityUser { } \ No newline at end of file diff --git a/save-points/08-templated-components/BlazingPizza.Server/PizzasController.cs b/save-points/08-templated-components/BlazingPizza.Server/PizzasController.cs deleted file mode 100644 index c082552c..00000000 --- a/save-points/08-templated-components/BlazingPizza.Server/PizzasController.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("pizzas")] - [ApiController] - public class PizzasController : Controller - { - private readonly PizzaStoreContext _db; - - public PizzasController(PizzaStoreContext db) - { - _db = db; - } - } -} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Program.cs b/save-points/08-templated-components/BlazingPizza.Server/Program.cs index 40a47641..b83debb4 100644 --- a/save-points/08-templated-components/BlazingPizza.Server/Program.cs +++ b/save-points/08-templated-components/BlazingPizza.Server/Program.cs @@ -1,33 +1,67 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; +using BlazingPizza.Server; +using Microsoft.AspNetCore.Authentication; +using Microsoft.EntityFrameworkCore; -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()) { - public class Program + var db = scope.ServiceProvider.GetRequiredService(); + if (db.Database.EnsureCreated()) { - 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(); - }); + SeedData.Initialize(db); } } + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + 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.MapPizzaApi(); + +app.MapRazorPages(); +app.MapControllers(); +app.MapFallbackToFile("index.html"); + +app.Run(); \ No newline at end of file diff --git a/save-points/08-templated-components/BlazingPizza.Server/SeedData.cs b/save-points/08-templated-components/BlazingPizza.Server/SeedData.cs index 7c86a5b2..f02e2b77 100644 --- a/save-points/08-templated-components/BlazingPizza.Server/SeedData.cs +++ b/save-points/08-templated-components/BlazingPizza.Server/SeedData.cs @@ -1,193 +1,192 @@ -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public static class SeedData { - public static class SeedData + public static void Initialize(PizzaStoreContext db) { - public static void Initialize(PizzaStoreContext db) + var toppings = new Topping[] { - var toppings = new Topping[] + new Topping() { - new Topping() - { Name = "Extra cheese", Price = 2.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "American bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "British bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Canadian bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Tea and crumpets", Price = 5.00m - }, - new Topping() - { + }, + new Topping() + { Name = "Fresh-baked scones", Price = 4.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Bell peppers", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Onions", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Mushrooms", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Pepperoni", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Duck sausage", Price = 3.20m, - }, - new Topping() - { + }, + new Topping() + { Name = "Venison meatballs", Price = 2.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Served on a silver platter", Price = 250.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Lobster on top", Price = 64.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Sturgeon caviar", Price = 101.75m, - }, - new Topping() - { + }, + new Topping() + { Name = "Artichoke hearts", Price = 3.40m, - }, - new Topping() - { + }, + new Topping() + { Name = "Fresh tomatoes", Price = 1.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Basil", Price = 1.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Steak (medium-rare)", Price = 8.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Blazing hot peppers", Price = 4.20m, - }, - new Topping() - { + }, + new Topping() + { Name = "Buffalo chicken", Price = 5.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Blue cheese", Price = 2.50m, - }, - }; + }, + }; - var specials = new PizzaSpecial[] + var specials = new PizzaSpecial[] + { + 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() - { + }, + new PizzaSpecial() + { Id = 2, Name = "The Baconatorizor", Description = "It has EVERY kind of bacon", BasePrice = 11.99m, ImageUrl = "img/pizzas/bacon.jpg", - }, - new PizzaSpecial() - { + }, + 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() - { + }, + 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() - { + }, + 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() - { + }, + new PizzaSpecial() + { Id = 6, Name = "The Brit", Description = "When in London...", BasePrice = 10.25m, ImageUrl = "img/pizzas/brit.jpg", - }, - new PizzaSpecial() - { + }, + 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() - { + }, + new PizzaSpecial() + { Id = 8, Name = "Margherita", Description = "Traditional Italian pizza with tomatoes and basil", BasePrice = 9.99m, ImageUrl = "img/pizzas/margherita.jpg", - }, - }; + }, + }; - db.Toppings.AddRange(toppings); - db.Specials.AddRange(specials); - db.SaveChanges(); - } + db.Toppings.AddRange(toppings); + db.Specials.AddRange(specials); + db.SaveChanges(); } -} +} \ No newline at end of file diff --git a/save-points/08-templated-components/BlazingPizza.Server/SpecialsController.cs b/save-points/08-templated-components/BlazingPizza.Server/SpecialsController.cs deleted file mode 100644 index a176844c..00000000 --- a/save-points/08-templated-components/BlazingPizza.Server/SpecialsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("specials")] - [ApiController] - public class SpecialsController : Controller - { - private readonly PizzaStoreContext _db; - - public SpecialsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetSpecials() - { - return (await _db.Specials.ToListAsync()).OrderByDescending(s => s.BasePrice).ToList(); - } - } -} diff --git a/save-points/08-templated-components/BlazingPizza.Server/Startup.cs b/save-points/08-templated-components/BlazingPizza.Server/Startup.cs deleted file mode 100644 index ed3fca06..00000000 --- a/save-points/08-templated-components/BlazingPizza.Server/Startup.cs +++ /dev/null @@ -1,70 +0,0 @@ -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace BlazingPizza.Server -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - public void ConfigureServices(IServiceCollection services) - { - services.AddControllersWithViews(); - services.AddRazorPages(); - - services.AddDbContext(options => - options.UseSqlite("Data Source=pizza.db")); - - services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) - .AddEntityFrameworkStores(); - - services.AddIdentityServer() - .AddApiAuthorization(); - - services.AddAuthentication() - .AddIdentityServerJwt(); - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - app.UseWebAssemblyDebugging(); - } - else - { - app.UseExceptionHandler("/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); - } - - app.UseHttpsRedirection(); - app.UseBlazorFrameworkFiles(); - app.UseStaticFiles(); - - app.UseRouting(); - - app.UseAuthentication(); - app.UseIdentityServer(); - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - endpoints.MapRazorPages(); - endpoints.MapFallbackToFile("index.html"); - }); - } - } -} \ No newline at end of file diff --git a/save-points/08-templated-components/BlazingPizza.Server/ToppingsController.cs b/save-points/08-templated-components/BlazingPizza.Server/ToppingsController.cs deleted file mode 100644 index 6a677639..00000000 --- a/save-points/08-templated-components/BlazingPizza.Server/ToppingsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("toppings")] - [ApiController] - public class ToppingsController : Controller - { - private readonly PizzaStoreContext _db; - - public ToppingsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetToppings() - { - return await _db.Toppings.OrderBy(t => t.Name).ToListAsync(); - } - } -} diff --git a/save-points/08-templated-components/BlazingPizza.Shared/Address.cs b/save-points/08-templated-components/BlazingPizza.Shared/Address.cs index d76bc52a..a671359a 100644 --- a/save-points/08-templated-components/BlazingPizza.Shared/Address.cs +++ b/save-points/08-templated-components/BlazingPizza.Shared/Address.cs @@ -1,27 +1,24 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class Address { - public class Address - { - public int Id { get; set; } + public int Id { get; set; } - [Required, MaxLength(100)] - public string Name { get; set; } + [Required, MaxLength(100)] + public string Name { get; set; } - [Required, MaxLength(100)] - public string Line1 { get; set; } + [Required, MaxLength(100)] + public string Line1 { get; set; } - [MaxLength(100)] - public string Line2 { get; set; } + [MaxLength(100)] + public string Line2 { get; set; } - [Required, MaxLength(50)] - public string City { get; set; } + [Required, MaxLength(50)] + public string City { get; set; } - [Required, MaxLength(20)] - public string Region { get; set; } + [Required, MaxLength(20)] + public string Region { get; set; } - [Required, MaxLength(20)] - public string PostalCode { get; set; } - } + [Required, MaxLength(20)] + public string PostalCode { get; set; } } diff --git a/save-points/08-templated-components/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/save-points/08-templated-components/BlazingPizza.Shared/BlazingPizza.Shared.csproj index 911c57c5..fb17e53b 100644 --- a/save-points/08-templated-components/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/save-points/08-templated-components/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -1,10 +1,15 @@  - net5.0 + $(TargetFrameworkVersion) BlazingPizza + true + + + + diff --git a/save-points/08-templated-components/BlazingPizza.Shared/LatLong.cs b/save-points/08-templated-components/BlazingPizza.Shared/LatLong.cs index 9b8c3811..a65971f8 100644 --- a/save-points/08-templated-components/BlazingPizza.Shared/LatLong.cs +++ b/save-points/08-templated-components/BlazingPizza.Shared/LatLong.cs @@ -1,27 +1,26 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class LatLong { - public class LatLong + public LatLong() { - public LatLong() - { - } + } - public LatLong(double latitude, double longitude) : this() - { - Latitude = latitude; - Longitude = longitude; - } + public LatLong(double latitude, double longitude) : this() + { + Latitude = latitude; + Longitude = longitude; + } - public double Latitude { get; set; } + public double Latitude { get; set; } - public double Longitude { get; set; } + public double Longitude { get; set; } - public static LatLong Interpolate(LatLong start, LatLong end, double proportion) - { - // The Earth is flat, right? So no need for spherical interpolation. - return new LatLong( + public static LatLong Interpolate(LatLong start, LatLong end, double proportion) + { + // The Earth is flat, right? So no need for spherical interpolation. + return new LatLong( start.Latitude + (end.Latitude - start.Latitude) * proportion, start.Longitude + (end.Longitude - start.Longitude) * proportion); - } } -} +} \ No newline at end of file diff --git a/save-points/08-templated-components/BlazingPizza.Shared/NotificationSubscription.cs b/save-points/08-templated-components/BlazingPizza.Shared/NotificationSubscription.cs index 04259c2f..5c99e3f4 100644 --- a/save-points/08-templated-components/BlazingPizza.Shared/NotificationSubscription.cs +++ b/save-points/08-templated-components/BlazingPizza.Shared/NotificationSubscription.cs @@ -1,17 +1,14 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class NotificationSubscription { - public class NotificationSubscription - { - public int NotificationSubscriptionId { get; set; } + public int NotificationSubscriptionId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public string Url { get; set; } + public string Url { get; set; } - public string P256dh { get; set; } + public string P256dh { get; set; } - public string Auth { get; set; } - } + public string Auth { get; set; } } diff --git a/save-points/08-templated-components/BlazingPizza.Shared/Order.cs b/save-points/08-templated-components/BlazingPizza.Shared/Order.cs index fb003bd6..b47efad0 100644 --- a/save-points/08-templated-components/BlazingPizza.Shared/Order.cs +++ b/save-points/08-templated-components/BlazingPizza.Shared/Order.cs @@ -1,25 +1,32 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +public class Order { - public class Order - { - public int OrderId { get; set; } + public int OrderId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public DateTime CreatedTime { get; set; } + public DateTime CreatedTime { get; set; } - public Address DeliveryAddress { get; set; } = new Address(); + public Address DeliveryAddress { get; set; } = new Address(); - public LatLong DeliveryLocation { get; set; } + public LatLong DeliveryLocation { get; set; } - public List Pizzas { get; set; } = new List(); + public List Pizzas { get; set; } = new List(); - public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); + public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); - public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); - } + public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Default, PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] +[JsonSerializable(typeof(Order))] +[JsonSerializable(typeof(OrderWithStatus))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Pizza))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Topping))] +public partial class OrderContext : JsonSerializerContext { } \ No newline at end of file diff --git a/save-points/08-templated-components/BlazingPizza.Shared/OrderWithStatus.cs b/save-points/08-templated-components/BlazingPizza.Shared/OrderWithStatus.cs index 021de78c..fbfac7af 100644 --- a/save-points/08-templated-components/BlazingPizza.Shared/OrderWithStatus.cs +++ b/save-points/08-templated-components/BlazingPizza.Shared/OrderWithStatus.cs @@ -1,79 +1,78 @@ -using BlazingPizza.ComponentsLibrary.Map; -using System; -using System.Collections.Generic; +using System.Text.Json.Serialization; +using BlazingPizza.ComponentsLibrary.Map; -namespace BlazingPizza -{ - 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 Order Order { get; set; } +namespace BlazingPizza; - public string StatusText { get; set; } +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 bool IsDelivered => StatusText == "Delivered"; + public Order Order { get; set; } - public List MapMarkers { get; set; } + public string StatusText { 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 bool IsDelivered => StatusText == "Delivered"; - 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"; + public List MapMarkers { get; set; } - 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), - }; - } + 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); - return new OrderWithStatus - { - Order = order, - StatusText = statusText, - MapMarkers = mapMarkers, - }; + 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"; - private static LatLong ComputeStartPosition(Order order) + 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 { - // 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); + statusText = "Delivered"; + mapMarkers = new List + { + ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), + }; } - static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) - => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; + 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); + } + + static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) + => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; +} \ No newline at end of file diff --git a/save-points/08-templated-components/BlazingPizza.Shared/Pizza.cs b/save-points/08-templated-components/BlazingPizza.Shared/Pizza.cs index ec1108a9..2a7a1c29 100644 --- a/save-points/08-templated-components/BlazingPizza.Shared/Pizza.cs +++ b/save-points/08-templated-components/BlazingPizza.Shared/Pizza.cs @@ -1,42 +1,44 @@ -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// /// Represents a customized pizza as part of an order +/// +public class Pizza { - /// - /// Represents a customized pizza as part of an order - /// - public class Pizza - { - public const int DefaultSize = 12; - public const int MinimumSize = 9; - public const int MaximumSize = 17; + public const int DefaultSize = 12; + public const int MinimumSize = 9; + public const int MaximumSize = 17; - public int Id { get; set; } + public int Id { get; set; } - public int OrderId { get; set; } + public int OrderId { get; set; } - public PizzaSpecial Special { get; set; } + public PizzaSpecial Special { get; set; } - public int SpecialId { get; set; } + public int SpecialId { get; set; } - public int Size { get; set; } + public int Size { get; set; } - public List Toppings { get; set; } + public List Toppings { get; set; } - public decimal GetBasePrice() - { - return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; - } + public decimal GetBasePrice() + { + return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; + } - public decimal GetTotalPrice() - { - return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); - } + public decimal GetTotalPrice() + { + return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); + } - public string GetFormattedTotalPrice() - { - return GetTotalPrice().ToString("0.00"); - } + public string GetFormattedTotalPrice() + { + return GetTotalPrice().ToString("0.00"); } } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Serialization)] +[JsonSerializable(typeof(Pizza))] +public partial class PizzaContext : JsonSerializerContext { } \ No newline at end of file diff --git a/save-points/08-templated-components/BlazingPizza.Shared/PizzaSpecial.cs b/save-points/08-templated-components/BlazingPizza.Shared/PizzaSpecial.cs index 2f2b3383..1fd9006a 100644 --- a/save-points/08-templated-components/BlazingPizza.Shared/PizzaSpecial.cs +++ b/save-points/08-templated-components/BlazingPizza.Shared/PizzaSpecial.cs @@ -1,20 +1,19 @@ -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// Represents a pre-configured template for a pizza a user can order +/// +public class PizzaSpecial { - /// - /// Represents a pre-configured template for a pizza a user can order - /// - public class PizzaSpecial - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal BasePrice { get; set; } + public decimal BasePrice { get; set; } - public string Description { get; set; } + public string Description { get; set; } - public string ImageUrl { get; set; } + public string ImageUrl { get; set; } - public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); - } -} + public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); +} \ No newline at end of file diff --git a/save-points/08-templated-components/BlazingPizza.Shared/PizzaTopping.cs b/save-points/08-templated-components/BlazingPizza.Shared/PizzaTopping.cs index f5a6c1ac..1c062732 100644 --- a/save-points/08-templated-components/BlazingPizza.Shared/PizzaTopping.cs +++ b/save-points/08-templated-components/BlazingPizza.Shared/PizzaTopping.cs @@ -1,11 +1,11 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class PizzaTopping { - public class PizzaTopping - { - public Topping Topping { get; set; } - - public int ToppingId { get; set; } - - public int PizzaId { get; set; } - } -} + public Topping Topping { get; set; } + + public int ToppingId { get; set; } + + public int PizzaId { get; set; } + +} \ No newline at end of file diff --git a/save-points/08-templated-components/BlazingPizza.Shared/Topping.cs b/save-points/08-templated-components/BlazingPizza.Shared/Topping.cs index 61bdeb92..4eb67ae9 100644 --- a/save-points/08-templated-components/BlazingPizza.Shared/Topping.cs +++ b/save-points/08-templated-components/BlazingPizza.Shared/Topping.cs @@ -1,13 +1,13 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class Topping { - public class Topping - { - public int Id { get; set; } + public int Id { get; set; } + + public string Name { get; set; } - public string Name { get; set; } + public decimal Price { get; set; } - public decimal Price { get; set; } + public string GetFormattedPrice() => Price.ToString("0.00"); - public string GetFormattedPrice() => Price.ToString("0.00"); - } -} +} \ No newline at end of file diff --git a/save-points/08-templated-components/BlazingPizza.Shared/UserInfo.cs b/save-points/08-templated-components/BlazingPizza.Shared/UserInfo.cs index 4996ef80..babb4315 100644 --- a/save-points/08-templated-components/BlazingPizza.Shared/UserInfo.cs +++ b/save-points/08-templated-components/BlazingPizza.Shared/UserInfo.cs @@ -1,9 +1,9 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class UserInfo { - public class UserInfo - { - public bool IsAuthenticated { get; set; } + public bool IsAuthenticated { get; set; } + + public string Name { get; set; } - public string Name { get; set; } - } -} +} \ No newline at end of file diff --git a/save-points/09-progressive-web-app/BlazingComponents/BlazingComponents.csproj b/save-points/09-progressive-web-app/BlazingComponents/BlazingComponents.csproj index df017b6f..89335194 100644 --- a/save-points/09-progressive-web-app/BlazingComponents/BlazingComponents.csproj +++ b/save-points/09-progressive-web-app/BlazingComponents/BlazingComponents.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + $(TargetFrameworkVersion) 3.0 diff --git a/save-points/09-progressive-web-app/BlazingPizza.Client/BlazingPizza.Client.csproj b/save-points/09-progressive-web-app/BlazingPizza.Client/BlazingPizza.Client.csproj index c6ff02af..3573ae56 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/save-points/09-progressive-web-app/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -1,7 +1,8 @@  - net5.0 + $(TargetFrameworkVersion) + enable diff --git a/save-points/09-progressive-web-app/BlazingPizza.Client/JSRuntimeExtensions.cs b/save-points/09-progressive-web-app/BlazingPizza.Client/JSRuntimeExtensions.cs index 89da520c..ef171321 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Client/JSRuntimeExtensions.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Client/JSRuntimeExtensions.cs @@ -1,13 +1,11 @@ using Microsoft.JSInterop; -using System.Threading.Tasks; -namespace BlazingPizza.Client +namespace BlazingPizza.Client; + +public static class JSRuntimeExtensions { - public static class JSRuntimeExtensions + public static ValueTask Confirm(this IJSRuntime jsRuntime, string message) { - public static ValueTask Confirm(this IJSRuntime jsRuntime, string message) - { - return jsRuntime.InvokeAsync("confirm", message); - } + return jsRuntime.InvokeAsync("confirm", message); } } diff --git a/save-points/09-progressive-web-app/BlazingPizza.Client/OrderState.cs b/save-points/09-progressive-web-app/BlazingPizza.Client/OrderState.cs index 5265ae39..00dd3627 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Client/OrderState.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Client/OrderState.cs @@ -1,55 +1,52 @@ -using System.Collections.Generic; +namespace BlazingPizza.Client; -namespace BlazingPizza.Client +public class OrderState { - public class OrderState - { - public bool ShowingConfigureDialog { get; private set; } + public bool ShowingConfigureDialog { get; private set; } - public Pizza ConfiguringPizza { get; private set; } + public Pizza ConfiguringPizza { get; private set; } - public Order Order { get; private set; } = new Order(); + 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() + public void ShowConfigurePizzaDialog(PizzaSpecial special) + { + ConfiguringPizza = new Pizza() { - ConfiguringPizza = null; - ShowingConfigureDialog = false; - } + Special = special, + SpecialId = special.Id, + Size = Pizza.DefaultSize, + Toppings = new List(), + }; - public void ConfirmConfigurePizzaDialog() - { - Order.Pizzas.Add(ConfiguringPizza); - ConfiguringPizza = null; + ShowingConfigureDialog = true; + } - ShowingConfigureDialog = false; - } + public void CancelConfigurePizzaDialog() + { + ConfiguringPizza = null; + ShowingConfigureDialog = false; + } - public void RemoveConfiguredPizza(Pizza pizza) - { - Order.Pizzas.Remove(pizza); - } + public void ConfirmConfigurePizzaDialog() + { + Order.Pizzas.Add(ConfiguringPizza); + ConfiguringPizza = null; - public void ResetOrder() - { - Order = new Order(); - } + ShowingConfigureDialog = false; + } - public void ReplaceOrder(Order order) - { - Order = order; - } + public void RemoveConfiguredPizza(Pizza pizza) + { + Order.Pizzas.Remove(pizza); + } + + public void ResetOrder() + { + Order = new Order(); + } + + public void ReplaceOrder(Order order) + { + Order = order; } } diff --git a/save-points/09-progressive-web-app/BlazingPizza.Client/OrdersClient.cs b/save-points/09-progressive-web-app/BlazingPizza.Client/OrdersClient.cs index 01c63572..c2c1a398 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Client/OrdersClient.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Client/OrdersClient.cs @@ -1,41 +1,35 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Net.Http.Json; -using System.Threading.Tasks; - -namespace BlazingPizza.Client +using System.Net.Http.Json; + +namespace BlazingPizza.Client; + +public class OrdersClient { - public class OrdersClient - { - private readonly HttpClient httpClient; + private readonly HttpClient httpClient; - public OrdersClient(HttpClient httpClient) - { - this.httpClient = httpClient; - } + public OrdersClient(HttpClient httpClient) + { + this.httpClient = httpClient; + } - public async Task> GetOrders() => - await httpClient.GetFromJsonAsync>("orders"); + public async Task> GetOrders() => + await httpClient.GetFromJsonAsync("orders", OrderContext.Default.ListOrderWithStatus); - public async Task GetOrder(int orderId) => - await httpClient.GetFromJsonAsync($"orders/{orderId}"); + public async Task GetOrder(int orderId) => + await httpClient.GetFromJsonAsync($"orders/{orderId}", OrderContext.Default.OrderWithStatus); - public async Task PlaceOrder(Order order) - { - var response = await httpClient.PostAsJsonAsync("orders", order); - response.EnsureSuccessStatusCode(); - var orderId = await response.Content.ReadFromJsonAsync(); - return orderId; - } + public async Task PlaceOrder(Order order) + { + var response = await httpClient.PostAsJsonAsync("orders", order, OrderContext.Default.Order); + response.EnsureSuccessStatusCode(); + var orderId = await response.Content.ReadFromJsonAsync(); + return orderId; + } - public async Task SubscribeToNotifications(NotificationSubscription subscription) - { - var response = await httpClient.PutAsJsonAsync("notifications/subscribe", subscription); - response.EnsureSuccessStatusCode(); - } + public async Task SubscribeToNotifications(NotificationSubscription subscription) + { + var response = await httpClient.PutAsJsonAsync("notifications/subscribe", subscription); + response.EnsureSuccessStatusCode(); } } diff --git a/save-points/09-progressive-web-app/BlazingPizza.Client/Pages/Checkout.razor b/save-points/09-progressive-web-app/BlazingPizza.Client/Pages/Checkout.razor index 611f152c..c78cacd1 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Client/Pages/Checkout.razor +++ b/save-points/09-progressive-web-app/BlazingPizza.Client/Pages/Checkout.razor @@ -5,6 +5,8 @@ @inject NavigationManager NavigationManager @inject IJSRuntime JSRuntime +Blazing Pizza - Checkout +
diff --git a/save-points/09-progressive-web-app/BlazingPizza.Client/Pages/MyOrders.razor b/save-points/09-progressive-web-app/BlazingPizza.Client/Pages/MyOrders.razor index 39e23e20..ad99fb4f 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Client/Pages/MyOrders.razor +++ b/save-points/09-progressive-web-app/BlazingPizza.Client/Pages/MyOrders.razor @@ -2,6 +2,8 @@ @attribute [Authorize] @inject OrdersClient OrdersClient +Blazing Pizza - My Orders +
Loading... diff --git a/save-points/09-progressive-web-app/BlazingPizza.Client/Pages/OrderDetails.razor b/save-points/09-progressive-web-app/BlazingPizza.Client/Pages/OrderDetails.razor index 29693df9..b9500427 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Client/Pages/OrderDetails.razor +++ b/save-points/09-progressive-web-app/BlazingPizza.Client/Pages/OrderDetails.razor @@ -4,6 +4,8 @@ @inject OrdersClient OrdersClient @implements IDisposable +Blazing Pizza - Order Details +
@if (invalidOrder) { diff --git a/save-points/09-progressive-web-app/BlazingPizza.Client/PizzaAuthenticationState.cs b/save-points/09-progressive-web-app/BlazingPizza.Client/PizzaAuthenticationState.cs index 3f295928..78627625 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Client/PizzaAuthenticationState.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Client/PizzaAuthenticationState.cs @@ -1,9 +1,8 @@ using Microsoft.AspNetCore.Components.WebAssembly.Authentication; -namespace BlazingPizza.Client +namespace BlazingPizza.Client; + +public class PizzaAuthenticationState : RemoteAuthenticationState { - public class PizzaAuthenticationState : RemoteAuthenticationState - { - public Order Order { get; set; } - } + public Order Order { get; set; } } diff --git a/save-points/09-progressive-web-app/BlazingPizza.Client/Program.cs b/save-points/09-progressive-web-app/BlazingPizza.Client/Program.cs index afeee128..c2129f0b 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Client/Program.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Client/Program.cs @@ -1,31 +1,21 @@ -using Microsoft.AspNetCore.Components.WebAssembly.Authentication; +using BlazingPizza.Client; +using Microsoft.AspNetCore.Components.Web; +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; -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.RootComponents.Add("head::after"); - builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); - builder.Services.AddHttpClient(client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)) - .AddHttpMessageHandler(); - builder.Services.AddScoped(); +builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); +builder.Services.AddHttpClient(client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)) + .AddHttpMessageHandler(); +builder.Services.AddScoped(); - // Add auth services - builder.Services.AddApiAuthorization(options => - { - options.AuthenticationPaths.LogOutSucceededPath = ""; - }); +// Add auth services +builder.Services.AddApiAuthorization(options => { + options.AuthenticationPaths.LogOutSucceededPath = ""; +}); - await builder.Build().RunAsync(); - } - } -} +await builder.Build().RunAsync(); diff --git a/save-points/09-progressive-web-app/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj b/save-points/09-progressive-web-app/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj index 255af646..edb7908d 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/save-points/09-progressive-web-app/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -1,7 +1,8 @@  - net5.0 + $(TargetFrameworkVersion) + enable diff --git a/save-points/09-progressive-web-app/BlazingPizza.ComponentsLibrary/LocalStorage.cs b/save-points/09-progressive-web-app/BlazingPizza.ComponentsLibrary/LocalStorage.cs index f36b098e..be8226ec 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.ComponentsLibrary/LocalStorage.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.ComponentsLibrary/LocalStorage.cs @@ -1,17 +1,15 @@ using Microsoft.JSInterop; -using System.Threading.Tasks; -namespace BlazingPizza.ComponentsLibrary +namespace BlazingPizza.ComponentsLibrary; + +public static class LocalStorage { - public static class LocalStorage - { - public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) + public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); - public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object 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) + public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key) => jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key); - } -} +} \ No newline at end of file diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/BlazingPizza.Server.csproj b/save-points/09-progressive-web-app/BlazingPizza.Server/BlazingPizza.Server.csproj index 6391d520..abd2317b 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -1,7 +1,8 @@  - net5.0 + $(TargetFrameworkVersion) + true diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/AddressEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/AddressEntityType.cs new file mode 100644 index 00000000..82db81b6 --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/AddressEntityType.cs @@ -0,0 +1,92 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class AddressEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Address", + typeof(Address), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Address).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var city = runtimeEntityType.AddProperty( + "City", + typeof(string), + propertyInfo: typeof(Address).GetProperty("City", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var line1 = runtimeEntityType.AddProperty( + "Line1", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line1", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var line2 = runtimeEntityType.AddProperty( + "Line2", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Line2", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var postalCode = runtimeEntityType.AddProperty( + "PostalCode", + typeof(string), + propertyInfo: typeof(Address).GetProperty("PostalCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var region = runtimeEntityType.AddProperty( + "Region", + typeof(string), + propertyInfo: typeof(Address).GetProperty("Region", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Address).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Address"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs new file mode 100644 index 00000000..1dd4563b --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/DeviceFlowCodesEntityType.cs @@ -0,0 +1,114 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class DeviceFlowCodesEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.DeviceFlowCodes", + typeof(DeviceFlowCodes), + baseEntityType); + + var userCode = runtimeEntityType.AddProperty( + "UserCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("UserCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var deviceCode = runtimeEntityType.AddProperty( + "DeviceCode", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("DeviceCode", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(DeviceFlowCodes).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(DeviceFlowCodes).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var key = runtimeEntityType.AddKey( + new[] { userCode }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deviceCode }, + unique: true); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "DeviceCodes"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs new file mode 100644 index 00000000..8946b261 --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityRoleClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRoleClaim", + typeof(IdentityRoleClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityRoleClaim).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRoleClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoleClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityRoleEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityRoleEntityType.cs new file mode 100644 index 00000000..2f1fec2b --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityRoleEntityType.cs @@ -0,0 +1,78 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityRoleEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityRole", + typeof(IdentityRole), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedName = runtimeEntityType.AddProperty( + "NormalizedName", + typeof(string), + propertyInfo: typeof(IdentityRole).GetProperty("NormalizedName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedName }, + unique: true); + index.AddAnnotation("Relational:Name", "RoleNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs new file mode 100644 index 00000000..55418a1e --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityUserClaimstringEntityType.cs @@ -0,0 +1,85 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserClaimstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserClaim", + typeof(IdentityUserClaim), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(IdentityUserClaim).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var claimType = runtimeEntityType.AddProperty( + "ClaimType", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var claimValue = runtimeEntityType.AddProperty( + "ClaimValue", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserClaim).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserClaim).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserClaims"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs new file mode 100644 index 00000000..3ca029bd --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityUserLoginstringEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserLoginstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserLogin", + typeof(IdentityUserLogin), + baseEntityType); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerKey = runtimeEntityType.AddProperty( + "ProviderKey", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderKey", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var providerDisplayName = runtimeEntityType.AddProperty( + "ProviderDisplayName", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("ProviderDisplayName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserLogin).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserLogin).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { loginProvider, providerKey }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { userId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserLogins"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs new file mode 100644 index 00000000..70078d7a --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityUserRolestringEntityType.cs @@ -0,0 +1,82 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserRolestringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserRole", + typeof(IdentityUserRole), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var roleId = runtimeEntityType.AddProperty( + "RoleId", + typeof(string), + propertyInfo: typeof(IdentityUserRole).GetProperty("RoleId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserRole).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { userId, roleId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { roleId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RoleId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserRoles"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs new file mode 100644 index 00000000..93ba6d31 --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/IdentityUserTokenstringEntityType.cs @@ -0,0 +1,84 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class IdentityUserTokenstringEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Microsoft.AspNetCore.Identity.IdentityUserToken", + typeof(IdentityUserToken), + baseEntityType); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var loginProvider = runtimeEntityType.AddProperty( + "LoginProvider", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 128); + + var value = runtimeEntityType.AddProperty( + "Value", + typeof(string), + propertyInfo: typeof(IdentityUserToken).GetProperty("Value", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUserToken).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { userId, loginProvider, name }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("UserId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUserTokens"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/KeyEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/KeyEntityType.cs new file mode 100644 index 00000000..f6c6b4c7 --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/KeyEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class KeyEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.Key", + typeof(Key), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var algorithm = runtimeEntityType.AddProperty( + "Algorithm", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Algorithm", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 100); + + var created = runtimeEntityType.AddProperty( + "Created", + typeof(DateTime), + propertyInfo: typeof(Key).GetProperty("Created", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var dataProtected = runtimeEntityType.AddProperty( + "DataProtected", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("DataProtected", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var isX509Certificate = runtimeEntityType.AddProperty( + "IsX509Certificate", + typeof(bool), + propertyInfo: typeof(Key).GetProperty("IsX509Certificate", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var use = runtimeEntityType.AddProperty( + "Use", + typeof(string), + propertyInfo: typeof(Key).GetProperty("Use", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var version = runtimeEntityType.AddProperty( + "Version", + typeof(int), + propertyInfo: typeof(Key).GetProperty("Version", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Key).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { use }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Keys"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/LatLongEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/LatLongEntityType.cs new file mode 100644 index 00000000..3fd254bd --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/LatLongEntityType.cs @@ -0,0 +1,80 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class LatLongEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.LatLong", + typeof(LatLong), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var latitude = runtimeEntityType.AddProperty( + "Latitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Latitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var longitude = runtimeEntityType.AddProperty( + "Longitude", + typeof(double), + propertyInfo: typeof(LatLong).GetProperty("Longitude", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(LatLong).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + unique: true, + required: true, + ownership: true); + + var deliveryLocation = principalEntityType.AddNavigation("DeliveryLocation", + runtimeForeignKey, + onDependent: false, + typeof(LatLong), + propertyInfo: typeof(Order).GetProperty("DeliveryLocation", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + eagerLoaded: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs new file mode 100644 index 00000000..db236e4c --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/NotificationSubscriptionEntityType.cs @@ -0,0 +1,77 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class NotificationSubscriptionEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.NotificationSubscription", + typeof(NotificationSubscription), + baseEntityType); + + var notificationSubscriptionId = runtimeEntityType.AddProperty( + "NotificationSubscriptionId", + typeof(int), + propertyInfo: typeof(NotificationSubscription).GetProperty("NotificationSubscriptionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var auth = runtimeEntityType.AddProperty( + "Auth", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Auth", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var p256dh = runtimeEntityType.AddProperty( + "P256dh", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("P256dh", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var url = runtimeEntityType.AddProperty( + "Url", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("Url", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(NotificationSubscription).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(NotificationSubscription).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { notificationSubscriptionId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "NotificationSubscriptions"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/OrderEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/OrderEntityType.cs new file mode 100644 index 00000000..9d9ec6fd --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/OrderEntityType.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class OrderEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Order", + typeof(Order), + baseEntityType); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Order).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var createdTime = runtimeEntityType.AddProperty( + "CreatedTime", + typeof(DateTime), + propertyInfo: typeof(Order).GetProperty("CreatedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var deliveryAddressId = runtimeEntityType.AddProperty( + "DeliveryAddressId", + typeof(int?), + nullable: true); + + var userId = runtimeEntityType.AddProperty( + "UserId", + typeof(string), + propertyInfo: typeof(Order).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { orderId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { deliveryAddressId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("DeliveryAddressId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType); + + var deliveryAddress = declaringEntityType.AddNavigation("DeliveryAddress", + runtimeForeignKey, + onDependent: true, + typeof(Address), + propertyInfo: typeof(Order).GetProperty("DeliveryAddress", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Orders"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PersistedGrantEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PersistedGrantEntityType.cs new file mode 100644 index 00000000..842d53a5 --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PersistedGrantEntityType.cs @@ -0,0 +1,127 @@ +// +using System; +using System.Reflection; +using Duende.IdentityServer.EntityFramework.Entities; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PersistedGrantEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Duende.IdentityServer.EntityFramework.Entities.PersistedGrant", + typeof(PersistedGrant), + baseEntityType); + + var key = runtimeEntityType.AddProperty( + "Key", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Key", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 200); + + var clientId = runtimeEntityType.AddProperty( + "ClientId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("ClientId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 200); + + var consumedTime = runtimeEntityType.AddProperty( + "ConsumedTime", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("ConsumedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var creationTime = runtimeEntityType.AddProperty( + "CreationTime", + typeof(DateTime), + propertyInfo: typeof(PersistedGrant).GetProperty("CreationTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var data = runtimeEntityType.AddProperty( + "Data", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50000); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var expiration = runtimeEntityType.AddProperty( + "Expiration", + typeof(DateTime?), + propertyInfo: typeof(PersistedGrant).GetProperty("Expiration", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var sessionId = runtimeEntityType.AddProperty( + "SessionId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SessionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 100); + + var subjectId = runtimeEntityType.AddProperty( + "SubjectId", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("SubjectId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 200); + + var type = runtimeEntityType.AddProperty( + "Type", + typeof(string), + propertyInfo: typeof(PersistedGrant).GetProperty("Type", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PersistedGrant).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 50); + + var key0 = runtimeEntityType.AddKey( + new[] { key }); + runtimeEntityType.SetPrimaryKey(key0); + + var index = runtimeEntityType.AddIndex( + new[] { consumedTime }); + + var index0 = runtimeEntityType.AddIndex( + new[] { expiration }); + + var index1 = runtimeEntityType.AddIndex( + new[] { subjectId, clientId, type }); + + var index2 = runtimeEntityType.AddIndex( + new[] { subjectId, sessionId, type }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PersistedGrants"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaEntityType.cs new file mode 100644 index 00000000..3a124e63 --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaEntityType.cs @@ -0,0 +1,111 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Pizza", + typeof(Pizza), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var orderId = runtimeEntityType.AddProperty( + "OrderId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var size = runtimeEntityType.AddProperty( + "Size", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("Size", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var specialId = runtimeEntityType.AddProperty( + "SpecialId", + typeof(int), + propertyInfo: typeof(Pizza).GetProperty("SpecialId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { orderId }); + + var index0 = runtimeEntityType.AddIndex( + new[] { specialId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("OrderId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("OrderId") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var pizzas = principalEntityType.AddNavigation("Pizzas", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Order).GetProperty("Pizzas", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Order).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("SpecialId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var special = declaringEntityType.AddNavigation("Special", + runtimeForeignKey, + onDependent: true, + typeof(PizzaSpecial), + propertyInfo: typeof(Pizza).GetProperty("Special", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Pizzas"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs new file mode 100644 index 00000000..e86b0f50 --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaSpecialEntityType.cs @@ -0,0 +1,76 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaSpecialEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaSpecial", + typeof(PizzaSpecial), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(PizzaSpecial).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var basePrice = runtimeEntityType.AddProperty( + "BasePrice", + typeof(decimal), + propertyInfo: typeof(PizzaSpecial).GetProperty("BasePrice", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var description = runtimeEntityType.AddProperty( + "Description", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var imageUrl = runtimeEntityType.AddProperty( + "ImageUrl", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("ImageUrl", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(PizzaSpecial).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaSpecial).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Specials"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaStoreContextModel.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaStoreContextModel.cs new file mode 100644 index 00000000..8b516a68 --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaStoreContextModel.cs @@ -0,0 +1,28 @@ +// +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + [DbContext(typeof(PizzaStoreContext))] + public partial class PizzaStoreContextModel : RuntimeModel + { + static PizzaStoreContextModel() + { + var model = new PizzaStoreContextModel(); + model.Initialize(); + model.Customize(); + _instance = model; + } + + private static PizzaStoreContextModel _instance; + public static IModel Instance => _instance; + + partial void Initialize(); + + partial void Customize(); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs new file mode 100644 index 00000000..d46f50f4 --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaStoreContextModelBuilder.cs @@ -0,0 +1,69 @@ +// +using System; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + public partial class PizzaStoreContextModel + { + partial void Initialize() + { + var address = AddressEntityType.Create(this); + var latLong = LatLongEntityType.Create(this); + var notificationSubscription = NotificationSubscriptionEntityType.Create(this); + var order = OrderEntityType.Create(this); + var pizza = PizzaEntityType.Create(this); + var pizzaSpecial = PizzaSpecialEntityType.Create(this); + var pizzaTopping = PizzaToppingEntityType.Create(this); + var pizzaStoreUser = PizzaStoreUserEntityType.Create(this); + var topping = ToppingEntityType.Create(this); + var deviceFlowCodes = DeviceFlowCodesEntityType.Create(this); + var key = KeyEntityType.Create(this); + var persistedGrant = PersistedGrantEntityType.Create(this); + var identityRole = IdentityRoleEntityType.Create(this); + var identityRoleClaimstring = IdentityRoleClaimstringEntityType.Create(this); + var identityUserClaimstring = IdentityUserClaimstringEntityType.Create(this); + var identityUserLoginstring = IdentityUserLoginstringEntityType.Create(this); + var identityUserRolestring = IdentityUserRolestringEntityType.Create(this); + var identityUserTokenstring = IdentityUserTokenstringEntityType.Create(this); + + LatLongEntityType.CreateForeignKey1(latLong, order); + OrderEntityType.CreateForeignKey1(order, address); + PizzaEntityType.CreateForeignKey1(pizza, order); + PizzaEntityType.CreateForeignKey2(pizza, pizzaSpecial); + PizzaToppingEntityType.CreateForeignKey1(pizzaTopping, pizza); + PizzaToppingEntityType.CreateForeignKey2(pizzaTopping, topping); + IdentityRoleClaimstringEntityType.CreateForeignKey1(identityRoleClaimstring, identityRole); + IdentityUserClaimstringEntityType.CreateForeignKey1(identityUserClaimstring, pizzaStoreUser); + IdentityUserLoginstringEntityType.CreateForeignKey1(identityUserLoginstring, pizzaStoreUser); + IdentityUserRolestringEntityType.CreateForeignKey1(identityUserRolestring, identityRole); + IdentityUserRolestringEntityType.CreateForeignKey2(identityUserRolestring, pizzaStoreUser); + IdentityUserTokenstringEntityType.CreateForeignKey1(identityUserTokenstring, pizzaStoreUser); + + AddressEntityType.CreateAnnotations(address); + LatLongEntityType.CreateAnnotations(latLong); + NotificationSubscriptionEntityType.CreateAnnotations(notificationSubscription); + OrderEntityType.CreateAnnotations(order); + PizzaEntityType.CreateAnnotations(pizza); + PizzaSpecialEntityType.CreateAnnotations(pizzaSpecial); + PizzaToppingEntityType.CreateAnnotations(pizzaTopping); + PizzaStoreUserEntityType.CreateAnnotations(pizzaStoreUser); + ToppingEntityType.CreateAnnotations(topping); + DeviceFlowCodesEntityType.CreateAnnotations(deviceFlowCodes); + KeyEntityType.CreateAnnotations(key); + PersistedGrantEntityType.CreateAnnotations(persistedGrant); + IdentityRoleEntityType.CreateAnnotations(identityRole); + IdentityRoleClaimstringEntityType.CreateAnnotations(identityRoleClaimstring); + IdentityUserClaimstringEntityType.CreateAnnotations(identityUserClaimstring); + IdentityUserLoginstringEntityType.CreateAnnotations(identityUserLoginstring); + IdentityUserRolestringEntityType.CreateAnnotations(identityUserRolestring); + IdentityUserTokenstringEntityType.CreateAnnotations(identityUserTokenstring); + + AddAnnotation("ProductVersion", "6.0.0"); + } + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs new file mode 100644 index 00000000..18b2d96d --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaStoreUserEntityType.cs @@ -0,0 +1,156 @@ +// +using System; +using System.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaStoreUserEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Server.PizzaStoreUser", + typeof(PizzaStoreUser), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var accessFailedCount = runtimeEntityType.AddProperty( + "AccessFailedCount", + typeof(int), + propertyInfo: typeof(IdentityUser).GetProperty("AccessFailedCount", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var concurrencyStamp = runtimeEntityType.AddProperty( + "ConcurrencyStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + concurrencyToken: true); + + var email = runtimeEntityType.AddProperty( + "Email", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("Email", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var emailConfirmed = runtimeEntityType.AddProperty( + "EmailConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("EmailConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnabled = runtimeEntityType.AddProperty( + "LockoutEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var lockoutEnd = runtimeEntityType.AddProperty( + "LockoutEnd", + typeof(DateTimeOffset?), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnd", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var normalizedEmail = runtimeEntityType.AddProperty( + "NormalizedEmail", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedEmail", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var normalizedUserName = runtimeEntityType.AddProperty( + "NormalizedUserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedUserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var passwordHash = runtimeEntityType.AddProperty( + "PasswordHash", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PasswordHash", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumber = runtimeEntityType.AddProperty( + "PhoneNumber", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumber", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var phoneNumberConfirmed = runtimeEntityType.AddProperty( + "PhoneNumberConfirmed", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumberConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var securityStamp = runtimeEntityType.AddProperty( + "SecurityStamp", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("SecurityStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var twoFactorEnabled = runtimeEntityType.AddProperty( + "TwoFactorEnabled", + typeof(bool), + propertyInfo: typeof(IdentityUser).GetProperty("TwoFactorEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var userName = runtimeEntityType.AddProperty( + "UserName", + typeof(string), + propertyInfo: typeof(IdentityUser).GetProperty("UserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 256); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { normalizedEmail }); + index.AddAnnotation("Relational:Name", "EmailIndex"); + + var index0 = runtimeEntityType.AddIndex( + new[] { normalizedUserName }, + unique: true); + index0.AddAnnotation("Relational:Name", "UserNameIndex"); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "AspNetUsers"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaToppingEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaToppingEntityType.cs new file mode 100644 index 00000000..b97d2a24 --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/PizzaToppingEntityType.cs @@ -0,0 +1,96 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class PizzaToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.PizzaTopping", + typeof(PizzaTopping), + baseEntityType); + + var pizzaId = runtimeEntityType.AddProperty( + "PizzaId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("PizzaId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var toppingId = runtimeEntityType.AddProperty( + "ToppingId", + typeof(int), + propertyInfo: typeof(PizzaTopping).GetProperty("ToppingId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { pizzaId, toppingId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { toppingId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("PizzaId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var toppings = principalEntityType.AddNavigation("Toppings", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(Pizza).GetProperty("Toppings", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Pizza).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("ToppingId") }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }), + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var topping = declaringEntityType.AddNavigation("Topping", + runtimeForeignKey, + onDependent: true, + typeof(Topping), + propertyInfo: typeof(PizzaTopping).GetProperty("Topping", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(PizzaTopping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PizzaTopping"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Models/ToppingEntityType.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/ToppingEntityType.cs new file mode 100644 index 00000000..9295f9bf --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Models/ToppingEntityType.cs @@ -0,0 +1,62 @@ +// +using System; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable disable + +namespace BlazingPizza.Server.Models +{ + internal partial class ToppingEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "BlazingPizza.Topping", + typeof(Topping), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(Topping).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var name = runtimeEntityType.AddProperty( + "Name", + typeof(string), + propertyInfo: typeof(Topping).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var price = runtimeEntityType.AddProperty( + "Price", + typeof(decimal), + propertyInfo: typeof(Topping).GetProperty("Price", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Topping).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Toppings"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/OidcConfigurationController.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/OidcConfigurationController.cs index c074debf..1431697e 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Server/OidcConfigurationController.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/OidcConfigurationController.cs @@ -1,26 +1,21 @@ using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class OidcConfigurationController : Controller { - public class OidcConfigurationController : Controller + public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) { - public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) - { - ClientRequestParametersProvider = clientRequestParametersProvider; - } + ClientRequestParametersProvider = clientRequestParametersProvider; + } - public IClientRequestParametersProvider ClientRequestParametersProvider { get; } + public IClientRequestParametersProvider ClientRequestParametersProvider { get; } - [HttpGet("_configuration/{clientId}")] - public IActionResult GetClientRequestParameters([FromRoute]string clientId) - { - var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); - return Ok(parameters); - } + [HttpGet("_configuration/{clientId}")] + public IActionResult GetClientRequestParameters([FromRoute] string clientId) + { + var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); + return Ok(parameters); } } diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/OrdersController.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/OrdersController.cs index bab775e4..3d2ba63f 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Server/OrdersController.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/OrdersController.cs @@ -1,32 +1,28 @@ -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; + private readonly PizzaStoreContext _db; - public OrdersController(PizzaStoreContext db) - { - _db = db; - } + public OrdersController(PizzaStoreContext db) + { + _db = db; + } - [HttpGet] - public async Task>> GetOrders() - { - var orders = await _db.Orders + [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) @@ -34,13 +30,13 @@ public async Task>> GetOrders() .OrderByDescending(o => o.CreatedTime) .ToListAsync(); - return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); - } + return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); + } - [HttpGet("{orderId}")] - public async Task> GetOrderWithStatus(int orderId) - { - var order = await _db.Orders + [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) @@ -48,88 +44,87 @@ public async Task> GetOrderWithStatus(int orderId) .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) .SingleOrDefaultAsync(); - if (order == null) - { - return NotFound(); - } - - return OrderWithStatus.FromOrder(order); + if (order == null) + { + return NotFound(); } - [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; - } - } + return OrderWithStatus.FromOrder(order); + } - _db.Orders.Attach(order); - await _db.SaveChangesAsync(); + [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; - // In the background, send push notifications if possible - var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); - if (subscription != null) + foreach (var topping in pizza.Toppings) { - _ = TrackAndSendNotificationsAsync(order, subscription); + topping.ToppingId = topping.Topping.Id; + topping.Topping = null; } - - return order.OrderId; } - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } + _db.Orders.Attach(order); + await _db.SaveChangesAsync(); - private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription subscription) + // In the background, send push notifications if possible + var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); + if (subscription != null) { - // 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!"); + _ = TrackAndSendNotificationsAsync(order, subscription); } - private static async Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) + 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 { - // 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 { - 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); - } + message, + url = $"myorders/{order.OrderId}", + }); + await webPushClient.SendNotificationAsync(pushSubscription, payload, vapidDetails); + } + catch (Exception ex) + { + Console.Error.WriteLine("Error sending push notification: " + ex.Message); } } } diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/PizzaApiExtensions.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/PizzaApiExtensions.cs new file mode 100644 index 00000000..524ca759 --- /dev/null +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/PizzaApiExtensions.cs @@ -0,0 +1,57 @@ +using System.Security.Claims; +using Microsoft.AspNetCore.Authorization; +using Microsoft.EntityFrameworkCore; + +namespace BlazingPizza.Server; + +public static class PizzaApiExtensions +{ + + public static WebApplication MapPizzaApi(this WebApplication app) + { + + // Subscribe to notifications + app.MapPut("/notifications/subscribe", [Authorize] async ( + HttpContext context, + PizzaStoreContext db, + NotificationSubscription subscription) => { + + // We're storing at most one subscription per user, so delete old ones. + // Alternatively, you could let the user register multiple subscriptions from different browsers/devices. + var userId = GetUserId(context); + var oldSubscriptions = db.NotificationSubscriptions.Where(e => e.UserId == userId); + db.NotificationSubscriptions.RemoveRange(oldSubscriptions); + + // Store new subscription + subscription.UserId = userId; + db.NotificationSubscriptions.Attach(subscription); + + await db.SaveChangesAsync(); + return Results.Ok(subscription); + + }); + + // Specials + app.MapGet("/specials", async (PizzaStoreContext db) => { + + var specials = await db.Specials.ToListAsync(); + return Results.Ok(specials); + + }); + + // Toppings + app.MapGet("/toppings", async (PizzaStoreContext db) => { + var toppings = await db.Toppings.OrderBy(t => t.Name).ToListAsync(); + return Results.Ok(toppings); + }); + + return app; + + } + + private static string GetUserId(HttpContext context) + { + return context.User.FindFirstValue(ClaimTypes.NameIdentifier); + } + +} \ No newline at end of file diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/PizzaStoreContext.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/PizzaStoreContext.cs index f79c1c66..50ac87e4 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Server/PizzaStoreContext.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/PizzaStoreContext.cs @@ -1,39 +1,38 @@ -using IdentityServer4.EntityFramework.Options; +using Duende.IdentityServer.EntityFramework.Options; using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class PizzaStoreContext : ApiAuthorizationDbContext { - public class PizzaStoreContext : ApiAuthorizationDbContext - { - public PizzaStoreContext( + 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/09-progressive-web-app/BlazingPizza.Server/PizzaStoreUser.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/PizzaStoreUser.cs index 171ce83d..7ab40235 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Server/PizzaStoreUser.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/PizzaStoreUser.cs @@ -1,8 +1,5 @@ using Microsoft.AspNetCore.Identity; -namespace BlazingPizza.Server -{ - public class PizzaStoreUser : IdentityUser - { - } -} \ No newline at end of file +namespace BlazingPizza.Server; + +public class PizzaStoreUser : IdentityUser { } \ No newline at end of file diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/PizzasController.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/PizzasController.cs deleted file mode 100644 index c082552c..00000000 --- a/save-points/09-progressive-web-app/BlazingPizza.Server/PizzasController.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace BlazingPizza.Server -{ - [Route("pizzas")] - [ApiController] - public class PizzasController : Controller - { - private readonly PizzaStoreContext _db; - - public PizzasController(PizzaStoreContext db) - { - _db = db; - } - } -} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Program.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Program.cs index 40a47641..b83debb4 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Server/Program.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/Program.cs @@ -1,33 +1,67 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; +using BlazingPizza.Server; +using Microsoft.AspNetCore.Authentication; +using Microsoft.EntityFrameworkCore; -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()) { - public class Program + var db = scope.ServiceProvider.GetRequiredService(); + if (db.Database.EnsureCreated()) { - 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(); - }); + SeedData.Initialize(db); } } + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + 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.MapPizzaApi(); + +app.MapRazorPages(); +app.MapControllers(); +app.MapFallbackToFile("index.html"); + +app.Run(); \ No newline at end of file diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/SeedData.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/SeedData.cs index 7c86a5b2..f02e2b77 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Server/SeedData.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Server/SeedData.cs @@ -1,193 +1,192 @@ -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public static class SeedData { - public static class SeedData + public static void Initialize(PizzaStoreContext db) { - public static void Initialize(PizzaStoreContext db) + var toppings = new Topping[] { - var toppings = new Topping[] + new Topping() { - new Topping() - { Name = "Extra cheese", Price = 2.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "American bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "British bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Canadian bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Tea and crumpets", Price = 5.00m - }, - new Topping() - { + }, + new Topping() + { Name = "Fresh-baked scones", Price = 4.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Bell peppers", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Onions", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Mushrooms", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Pepperoni", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Duck sausage", Price = 3.20m, - }, - new Topping() - { + }, + new Topping() + { Name = "Venison meatballs", Price = 2.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Served on a silver platter", Price = 250.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Lobster on top", Price = 64.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Sturgeon caviar", Price = 101.75m, - }, - new Topping() - { + }, + new Topping() + { Name = "Artichoke hearts", Price = 3.40m, - }, - new Topping() - { + }, + new Topping() + { Name = "Fresh tomatoes", Price = 1.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Basil", Price = 1.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Steak (medium-rare)", Price = 8.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Blazing hot peppers", Price = 4.20m, - }, - new Topping() - { + }, + new Topping() + { Name = "Buffalo chicken", Price = 5.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Blue cheese", Price = 2.50m, - }, - }; + }, + }; - var specials = new PizzaSpecial[] + var specials = new PizzaSpecial[] + { + 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() - { + }, + new PizzaSpecial() + { Id = 2, Name = "The Baconatorizor", Description = "It has EVERY kind of bacon", BasePrice = 11.99m, ImageUrl = "img/pizzas/bacon.jpg", - }, - new PizzaSpecial() - { + }, + 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() - { + }, + 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() - { + }, + 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() - { + }, + new PizzaSpecial() + { Id = 6, Name = "The Brit", Description = "When in London...", BasePrice = 10.25m, ImageUrl = "img/pizzas/brit.jpg", - }, - new PizzaSpecial() - { + }, + 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() - { + }, + new PizzaSpecial() + { Id = 8, Name = "Margherita", Description = "Traditional Italian pizza with tomatoes and basil", BasePrice = 9.99m, ImageUrl = "img/pizzas/margherita.jpg", - }, - }; + }, + }; - db.Toppings.AddRange(toppings); - db.Specials.AddRange(specials); - db.SaveChanges(); - } + db.Toppings.AddRange(toppings); + db.Specials.AddRange(specials); + db.SaveChanges(); } -} +} \ No newline at end of file diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/SpecialsController.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/SpecialsController.cs deleted file mode 100644 index a176844c..00000000 --- a/save-points/09-progressive-web-app/BlazingPizza.Server/SpecialsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("specials")] - [ApiController] - public class SpecialsController : Controller - { - private readonly PizzaStoreContext _db; - - public SpecialsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetSpecials() - { - return (await _db.Specials.ToListAsync()).OrderByDescending(s => s.BasePrice).ToList(); - } - } -} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/Startup.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/Startup.cs deleted file mode 100644 index 3d59708b..00000000 --- a/save-points/09-progressive-web-app/BlazingPizza.Server/Startup.cs +++ /dev/null @@ -1,70 +0,0 @@ -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace BlazingPizza.Server -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - public void ConfigureServices(IServiceCollection services) - { - services.AddControllersWithViews(); - services.AddRazorPages(); - - services.AddDbContext(options => - options.UseSqlite("Data Source=pizza.db")); - - services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) - .AddEntityFrameworkStores(); - - services.AddIdentityServer() - .AddApiAuthorization(); - - services.AddAuthentication() - .AddIdentityServerJwt(); - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - app.UseWebAssemblyDebugging(); - } - else - { - app.UseExceptionHandler("/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); - } - - app.UseHttpsRedirection(); - app.UseBlazorFrameworkFiles(); - app.UseStaticFiles(); - - app.UseRouting(); - - app.UseAuthentication(); - app.UseIdentityServer(); - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - endpoints.MapRazorPages(); - endpoints.MapFallbackToFile("index.html"); - }); - } - } -} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Server/ToppingsController.cs b/save-points/09-progressive-web-app/BlazingPizza.Server/ToppingsController.cs deleted file mode 100644 index 6a677639..00000000 --- a/save-points/09-progressive-web-app/BlazingPizza.Server/ToppingsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace BlazingPizza.Server -{ - [Route("toppings")] - [ApiController] - public class ToppingsController : Controller - { - private readonly PizzaStoreContext _db; - - public ToppingsController(PizzaStoreContext db) - { - _db = db; - } - - [HttpGet] - public async Task>> GetToppings() - { - return await _db.Toppings.OrderBy(t => t.Name).ToListAsync(); - } - } -} diff --git a/save-points/09-progressive-web-app/BlazingPizza.Shared/Address.cs b/save-points/09-progressive-web-app/BlazingPizza.Shared/Address.cs index d76bc52a..a671359a 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Shared/Address.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Shared/Address.cs @@ -1,27 +1,24 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class Address { - public class Address - { - public int Id { get; set; } + public int Id { get; set; } - [Required, MaxLength(100)] - public string Name { get; set; } + [Required, MaxLength(100)] + public string Name { get; set; } - [Required, MaxLength(100)] - public string Line1 { get; set; } + [Required, MaxLength(100)] + public string Line1 { get; set; } - [MaxLength(100)] - public string Line2 { get; set; } + [MaxLength(100)] + public string Line2 { get; set; } - [Required, MaxLength(50)] - public string City { get; set; } + [Required, MaxLength(50)] + public string City { get; set; } - [Required, MaxLength(20)] - public string Region { get; set; } + [Required, MaxLength(20)] + public string Region { get; set; } - [Required, MaxLength(20)] - public string PostalCode { get; set; } - } + [Required, MaxLength(20)] + public string PostalCode { get; set; } } diff --git a/save-points/09-progressive-web-app/BlazingPizza.Shared/BlazingPizza.Shared.csproj b/save-points/09-progressive-web-app/BlazingPizza.Shared/BlazingPizza.Shared.csproj index 911c57c5..fb17e53b 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/save-points/09-progressive-web-app/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -1,10 +1,15 @@  - net5.0 + $(TargetFrameworkVersion) BlazingPizza + true + + + + diff --git a/save-points/09-progressive-web-app/BlazingPizza.Shared/LatLong.cs b/save-points/09-progressive-web-app/BlazingPizza.Shared/LatLong.cs index 9b8c3811..a65971f8 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Shared/LatLong.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Shared/LatLong.cs @@ -1,27 +1,26 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class LatLong { - public class LatLong + public LatLong() { - public LatLong() - { - } + } - public LatLong(double latitude, double longitude) : this() - { - Latitude = latitude; - Longitude = longitude; - } + public LatLong(double latitude, double longitude) : this() + { + Latitude = latitude; + Longitude = longitude; + } - public double Latitude { get; set; } + public double Latitude { get; set; } - public double Longitude { get; set; } + public double Longitude { get; set; } - public static LatLong Interpolate(LatLong start, LatLong end, double proportion) - { - // The Earth is flat, right? So no need for spherical interpolation. - return new LatLong( + public static LatLong Interpolate(LatLong start, LatLong end, double proportion) + { + // The Earth is flat, right? So no need for spherical interpolation. + return new LatLong( start.Latitude + (end.Latitude - start.Latitude) * proportion, start.Longitude + (end.Longitude - start.Longitude) * proportion); - } } -} +} \ No newline at end of file diff --git a/save-points/09-progressive-web-app/BlazingPizza.Shared/NotificationSubscription.cs b/save-points/09-progressive-web-app/BlazingPizza.Shared/NotificationSubscription.cs index 04259c2f..5c99e3f4 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Shared/NotificationSubscription.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Shared/NotificationSubscription.cs @@ -1,17 +1,14 @@ -using System.ComponentModel.DataAnnotations; +namespace BlazingPizza; -namespace BlazingPizza +public class NotificationSubscription { - public class NotificationSubscription - { - public int NotificationSubscriptionId { get; set; } + public int NotificationSubscriptionId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public string Url { get; set; } + public string Url { get; set; } - public string P256dh { get; set; } + public string P256dh { get; set; } - public string Auth { get; set; } - } + public string Auth { get; set; } } diff --git a/save-points/09-progressive-web-app/BlazingPizza.Shared/Order.cs b/save-points/09-progressive-web-app/BlazingPizza.Shared/Order.cs index fb003bd6..b47efad0 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Shared/Order.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Shared/Order.cs @@ -1,25 +1,32 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +public class Order { - public class Order - { - public int OrderId { get; set; } + public int OrderId { get; set; } - public string UserId { get; set; } + public string UserId { get; set; } - public DateTime CreatedTime { get; set; } + public DateTime CreatedTime { get; set; } - public Address DeliveryAddress { get; set; } = new Address(); + public Address DeliveryAddress { get; set; } = new Address(); - public LatLong DeliveryLocation { get; set; } + public LatLong DeliveryLocation { get; set; } - public List Pizzas { get; set; } = new List(); + public List Pizzas { get; set; } = new List(); - public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); + public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice()); - public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); - } + public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00"); } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Default, PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] +[JsonSerializable(typeof(Order))] +[JsonSerializable(typeof(OrderWithStatus))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Pizza))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(Topping))] +public partial class OrderContext : JsonSerializerContext { } \ No newline at end of file diff --git a/save-points/09-progressive-web-app/BlazingPizza.Shared/OrderWithStatus.cs b/save-points/09-progressive-web-app/BlazingPizza.Shared/OrderWithStatus.cs index 021de78c..fbfac7af 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Shared/OrderWithStatus.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Shared/OrderWithStatus.cs @@ -1,79 +1,78 @@ -using BlazingPizza.ComponentsLibrary.Map; -using System; -using System.Collections.Generic; +using System.Text.Json.Serialization; +using BlazingPizza.ComponentsLibrary.Map; -namespace BlazingPizza -{ - 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 Order Order { get; set; } +namespace BlazingPizza; - public string StatusText { get; set; } +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 bool IsDelivered => StatusText == "Delivered"; + public Order Order { get; set; } - public List MapMarkers { get; set; } + public string StatusText { 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 bool IsDelivered => StatusText == "Delivered"; - 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"; + public List MapMarkers { get; set; } - 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), - }; - } + 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); - return new OrderWithStatus - { - Order = order, - StatusText = statusText, - MapMarkers = mapMarkers, - }; + 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"; - private static LatLong ComputeStartPosition(Order order) + 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 { - // 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); + statusText = "Delivered"; + mapMarkers = new List + { + ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), + }; } - static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) - => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; + 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); + } + + static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) + => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; +} \ No newline at end of file diff --git a/save-points/09-progressive-web-app/BlazingPizza.Shared/Pizza.cs b/save-points/09-progressive-web-app/BlazingPizza.Shared/Pizza.cs index ec1108a9..2a7a1c29 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Shared/Pizza.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Shared/Pizza.cs @@ -1,42 +1,44 @@ -using System.Collections.Generic; -using System.Linq; +using System.Text.Json.Serialization; -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// /// Represents a customized pizza as part of an order +/// +public class Pizza { - /// - /// Represents a customized pizza as part of an order - /// - public class Pizza - { - public const int DefaultSize = 12; - public const int MinimumSize = 9; - public const int MaximumSize = 17; + public const int DefaultSize = 12; + public const int MinimumSize = 9; + public const int MaximumSize = 17; - public int Id { get; set; } + public int Id { get; set; } - public int OrderId { get; set; } + public int OrderId { get; set; } - public PizzaSpecial Special { get; set; } + public PizzaSpecial Special { get; set; } - public int SpecialId { get; set; } + public int SpecialId { get; set; } - public int Size { get; set; } + public int Size { get; set; } - public List Toppings { get; set; } + public List Toppings { get; set; } - public decimal GetBasePrice() - { - return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; - } + public decimal GetBasePrice() + { + return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice; + } - public decimal GetTotalPrice() - { - return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); - } + public decimal GetTotalPrice() + { + return GetBasePrice() + Toppings.Sum(t => t.Topping.Price); + } - public string GetFormattedTotalPrice() - { - return GetTotalPrice().ToString("0.00"); - } + public string GetFormattedTotalPrice() + { + return GetTotalPrice().ToString("0.00"); } } + +[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Serialization)] +[JsonSerializable(typeof(Pizza))] +public partial class PizzaContext : JsonSerializerContext { } \ No newline at end of file diff --git a/save-points/09-progressive-web-app/BlazingPizza.Shared/PizzaSpecial.cs b/save-points/09-progressive-web-app/BlazingPizza.Shared/PizzaSpecial.cs index 2f2b3383..1fd9006a 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Shared/PizzaSpecial.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Shared/PizzaSpecial.cs @@ -1,20 +1,19 @@ -namespace BlazingPizza +namespace BlazingPizza; + +/// +/// Represents a pre-configured template for a pizza a user can order +/// +public class PizzaSpecial { - /// - /// Represents a pre-configured template for a pizza a user can order - /// - public class PizzaSpecial - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public decimal BasePrice { get; set; } + public decimal BasePrice { get; set; } - public string Description { get; set; } + public string Description { get; set; } - public string ImageUrl { get; set; } + public string ImageUrl { get; set; } - public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); - } -} + public string GetFormattedBasePrice() => BasePrice.ToString("0.00"); +} \ No newline at end of file diff --git a/save-points/09-progressive-web-app/BlazingPizza.Shared/PizzaTopping.cs b/save-points/09-progressive-web-app/BlazingPizza.Shared/PizzaTopping.cs index f5a6c1ac..1c062732 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Shared/PizzaTopping.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Shared/PizzaTopping.cs @@ -1,11 +1,11 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class PizzaTopping { - public class PizzaTopping - { - public Topping Topping { get; set; } - - public int ToppingId { get; set; } - - public int PizzaId { get; set; } - } -} + public Topping Topping { get; set; } + + public int ToppingId { get; set; } + + public int PizzaId { get; set; } + +} \ No newline at end of file diff --git a/save-points/09-progressive-web-app/BlazingPizza.Shared/Topping.cs b/save-points/09-progressive-web-app/BlazingPizza.Shared/Topping.cs index 61bdeb92..4eb67ae9 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Shared/Topping.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Shared/Topping.cs @@ -1,13 +1,13 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class Topping { - public class Topping - { - public int Id { get; set; } + public int Id { get; set; } + + public string Name { get; set; } - public string Name { get; set; } + public decimal Price { get; set; } - public decimal Price { get; set; } + public string GetFormattedPrice() => Price.ToString("0.00"); - public string GetFormattedPrice() => Price.ToString("0.00"); - } -} +} \ No newline at end of file diff --git a/save-points/09-progressive-web-app/BlazingPizza.Shared/UserInfo.cs b/save-points/09-progressive-web-app/BlazingPizza.Shared/UserInfo.cs index 4996ef80..babb4315 100644 --- a/save-points/09-progressive-web-app/BlazingPizza.Shared/UserInfo.cs +++ b/save-points/09-progressive-web-app/BlazingPizza.Shared/UserInfo.cs @@ -1,9 +1,9 @@ -namespace BlazingPizza +namespace BlazingPizza; + +public class UserInfo { - public class UserInfo - { - public bool IsAuthenticated { get; set; } + public bool IsAuthenticated { get; set; } + + public string Name { get; set; } - public string Name { get; set; } - } -} +} \ No newline at end of file diff --git a/src/BlazingComponents/BlazingComponents.csproj b/src/BlazingComponents/BlazingComponents.csproj index 6325ad64..e0a4b76a 100644 --- a/src/BlazingComponents/BlazingComponents.csproj +++ b/src/BlazingComponents/BlazingComponents.csproj @@ -1,7 +1,7 @@  - net5.0 + $(TargetFrameworkVersion) diff --git a/src/BlazingPizza.Client/BlazingPizza.Client.csproj b/src/BlazingPizza.Client/BlazingPizza.Client.csproj index 5014247d..44802d79 100644 --- a/src/BlazingPizza.Client/BlazingPizza.Client.csproj +++ b/src/BlazingPizza.Client/BlazingPizza.Client.csproj @@ -1,7 +1,8 @@  - net5.0 + $(TargetFrameworkVersion) + true diff --git a/src/BlazingPizza.Client/JSRuntimeExtensions.cs b/src/BlazingPizza.Client/JSRuntimeExtensions.cs index 89da520c..ef171321 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) { - public static ValueTask Confirm(this IJSRuntime jsRuntime, string message) - { - return jsRuntime.InvokeAsync("confirm", message); - } + return jsRuntime.InvokeAsync("confirm", message); } } diff --git a/src/BlazingPizza.Client/OrderState.cs b/src/BlazingPizza.Client/OrderState.cs index 5265ae39..00dd3627 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 bool ShowingConfigureDialog { get; private set; } - public Pizza ConfiguringPizza { get; private set; } + public Pizza ConfiguringPizza { get; private set; } - public Order Order { get; private set; } = new Order(); + 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() + public void ShowConfigurePizzaDialog(PizzaSpecial special) + { + ConfiguringPizza = new Pizza() { - ConfiguringPizza = null; - ShowingConfigureDialog = false; - } + Special = special, + SpecialId = special.Id, + Size = Pizza.DefaultSize, + Toppings = new List(), + }; - public void ConfirmConfigurePizzaDialog() - { - Order.Pizzas.Add(ConfiguringPizza); - ConfiguringPizza = null; + ShowingConfigureDialog = true; + } - ShowingConfigureDialog = false; - } + public void CancelConfigurePizzaDialog() + { + ConfiguringPizza = null; + ShowingConfigureDialog = false; + } - public void RemoveConfiguredPizza(Pizza pizza) - { - Order.Pizzas.Remove(pizza); - } + public void ConfirmConfigurePizzaDialog() + { + Order.Pizzas.Add(ConfiguringPizza); + ConfiguringPizza = null; - public void ResetOrder() - { - Order = new Order(); - } + ShowingConfigureDialog = false; + } - public void ReplaceOrder(Order order) - { - Order = order; - } + 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..b4a08f1e 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/Checkout.razor b/src/BlazingPizza.Client/Pages/Checkout.razor index 611f152c..c78cacd1 100644 --- a/src/BlazingPizza.Client/Pages/Checkout.razor +++ b/src/BlazingPizza.Client/Pages/Checkout.razor @@ -5,6 +5,8 @@ @inject NavigationManager NavigationManager @inject IJSRuntime JSRuntime +Blazing Pizza - Checkout +
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/Pages/MyOrders.razor b/src/BlazingPizza.Client/Pages/MyOrders.razor index 39e23e20..ad99fb4f 100644 --- a/src/BlazingPizza.Client/Pages/MyOrders.razor +++ b/src/BlazingPizza.Client/Pages/MyOrders.razor @@ -2,6 +2,8 @@ @attribute [Authorize] @inject OrdersClient OrdersClient +Blazing Pizza - My Orders +
Loading... diff --git a/src/BlazingPizza.Client/Pages/OrderDetails.razor b/src/BlazingPizza.Client/Pages/OrderDetails.razor index 29693df9..b9500427 100644 --- a/src/BlazingPizza.Client/Pages/OrderDetails.razor +++ b/src/BlazingPizza.Client/Pages/OrderDetails.razor @@ -4,6 +4,8 @@ @inject OrdersClient OrdersClient @implements IDisposable +Blazing Pizza - Order Details +
@if (invalidOrder) { diff --git a/src/BlazingPizza.Client/PizzaAuthenticationState.cs b/src/BlazingPizza.Client/PizzaAuthenticationState.cs index 3f295928..78627625 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..c2129f0b 100644 --- a/src/BlazingPizza.Client/Program.cs +++ b/src/BlazingPizza.Client/Program.cs @@ -1,31 +1,21 @@ -using Microsoft.AspNetCore.Components.WebAssembly.Authentication; +using BlazingPizza.Client; +using Microsoft.AspNetCore.Components.Web; +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; -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.RootComponents.Add("head::after"); - 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 5f51ee3c..cb996b1b 100644 --- a/src/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj +++ b/src/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj @@ -1,7 +1,8 @@  - net5.0 + $(TargetFrameworkVersion) + true diff --git a/src/BlazingPizza.ComponentsLibrary/LocalStorage.cs b/src/BlazingPizza.ComponentsLibrary/LocalStorage.cs index f36b098e..be8226ec 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) + public static ValueTask GetAsync(IJSRuntime jsRuntime, string key) => jsRuntime.InvokeAsync("blazorLocalStorage.get", key); - public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object 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) + 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..b067719c 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..34194163 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/.gitignore b/src/BlazingPizza.Server/.gitignore new file mode 100644 index 00000000..3323b0a7 --- /dev/null +++ b/src/BlazingPizza.Server/.gitignore @@ -0,0 +1,2 @@ +*.db-shm +*.db-wal \ No newline at end of file diff --git a/src/BlazingPizza.Server/BlazingPizza.Server.csproj b/src/BlazingPizza.Server/BlazingPizza.Server.csproj index 6391d520..abd2317b 100644 --- a/src/BlazingPizza.Server/BlazingPizza.Server.csproj +++ b/src/BlazingPizza.Server/BlazingPizza.Server.csproj @@ -1,7 +1,8 @@  - net5.0 + $(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..1431697e 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) { - public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) - { - ClientRequestParametersProvider = 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..3d2ba63f 100644 --- a/src/BlazingPizza.Server/OrdersController.cs +++ b/src/BlazingPizza.Server/OrdersController.cs @@ -1,32 +1,28 @@ -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; + private readonly PizzaStoreContext _db; - public OrdersController(PizzaStoreContext db) - { - _db = db; - } + public OrdersController(PizzaStoreContext db) + { + _db = db; + } - [HttpGet] - public async Task>> GetOrders() - { - var orders = await _db.Orders + [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) @@ -34,13 +30,13 @@ public async Task>> GetOrders() .OrderByDescending(o => o.CreatedTime) .ToListAsync(); - return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); - } + return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList(); + } - [HttpGet("{orderId}")] - public async Task> GetOrderWithStatus(int orderId) - { - var order = await _db.Orders + [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) @@ -48,88 +44,87 @@ public async Task> GetOrderWithStatus(int orderId) .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping) .SingleOrDefaultAsync(); - if (order == null) - { - return NotFound(); - } - - return OrderWithStatus.FromOrder(order); + if (order == null) + { + return NotFound(); } - [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; - } - } + return OrderWithStatus.FromOrder(order); + } - _db.Orders.Attach(order); - await _db.SaveChangesAsync(); + [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; - // In the background, send push notifications if possible - var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); - if (subscription != null) + foreach (var topping in pizza.Toppings) { - _ = TrackAndSendNotificationsAsync(order, subscription); + topping.ToppingId = topping.Topping.Id; + topping.Topping = null; } - - return order.OrderId; } - private string GetUserId() - { - return HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); - } + _db.Orders.Attach(order); + await _db.SaveChangesAsync(); - private static async Task TrackAndSendNotificationsAsync(Order order, NotificationSubscription subscription) + // In the background, send push notifications if possible + var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync(); + if (subscription != null) { - // 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!"); + _ = TrackAndSendNotificationsAsync(order, subscription); } - private static async Task SendNotificationAsync(Order order, NotificationSubscription subscription, string message) + 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 { - // 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 { - 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); - } + 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..524ca759 --- /dev/null +++ b/src/BlazingPizza.Server/PizzaApiExtensions.cs @@ -0,0 +1,57 @@ +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 51e96e1e..50ac87e4 100644 --- a/src/BlazingPizza.Server/PizzaStoreContext.cs +++ b/src/BlazingPizza.Server/PizzaStoreContext.cs @@ -1,39 +1,38 @@ -using IdentityServer4.EntityFramework.Options; +using Duende.IdentityServer.EntityFramework.Options; using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; -namespace BlazingPizza.Server +namespace BlazingPizza.Server; + +public class PizzaStoreContext : ApiAuthorizationDbContext { - public class PizzaStoreContext : ApiAuthorizationDbContext - { - public PizzaStoreContext( + 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..b83debb4 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 BlazingPizza.Server; +using Microsoft.AspNetCore.Authentication; +using Microsoft.EntityFrameworkCore; -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()) { - public class Program + var db = scope.ServiceProvider.GetRequiredService(); + if (db.Database.EnsureCreated()) { - 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(); - }); + SeedData.Initialize(db); } } + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + 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.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..f02e2b77 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) { - public static void Initialize(PizzaStoreContext db) + var toppings = new Topping[] { - var toppings = new Topping[] + new Topping() { - new Topping() - { Name = "Extra cheese", Price = 2.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "American bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "British bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Canadian bacon", Price = 2.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Tea and crumpets", Price = 5.00m - }, - new Topping() - { + }, + new Topping() + { Name = "Fresh-baked scones", Price = 4.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Bell peppers", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Onions", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Mushrooms", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Pepperoni", Price = 1.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Duck sausage", Price = 3.20m, - }, - new Topping() - { + }, + new Topping() + { Name = "Venison meatballs", Price = 2.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Served on a silver platter", Price = 250.99m, - }, - new Topping() - { + }, + new Topping() + { Name = "Lobster on top", Price = 64.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Sturgeon caviar", Price = 101.75m, - }, - new Topping() - { + }, + new Topping() + { Name = "Artichoke hearts", Price = 3.40m, - }, - new Topping() - { + }, + new Topping() + { Name = "Fresh tomatoes", Price = 1.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Basil", Price = 1.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Steak (medium-rare)", Price = 8.50m, - }, - new Topping() - { + }, + new Topping() + { Name = "Blazing hot peppers", Price = 4.20m, - }, - new Topping() - { + }, + new Topping() + { Name = "Buffalo chicken", Price = 5.00m, - }, - new Topping() - { + }, + new Topping() + { Name = "Blue cheese", Price = 2.50m, - }, - }; + }, + }; - var specials = new PizzaSpecial[] + var specials = new PizzaSpecial[] + { + 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() - { + }, + new PizzaSpecial() + { Id = 2, Name = "The Baconatorizor", Description = "It has EVERY kind of bacon", BasePrice = 11.99m, ImageUrl = "img/pizzas/bacon.jpg", - }, - new PizzaSpecial() - { + }, + 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() - { + }, + 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() - { + }, + 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() - { + }, + new PizzaSpecial() + { Id = 6, Name = "The Brit", Description = "When in London...", BasePrice = 10.25m, ImageUrl = "img/pizzas/brit.jpg", - }, - new PizzaSpecial() - { + }, + 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() - { + }, + 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 a176844c..00000000 --- a/src/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/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..a671359a 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 911c57c5..fb17e53b 100644 --- a/src/BlazingPizza.Shared/BlazingPizza.Shared.csproj +++ b/src/BlazingPizza.Shared/BlazingPizza.Shared.csproj @@ -1,10 +1,15 @@  - net5.0 + $(TargetFrameworkVersion) BlazingPizza + true + + + + diff --git a/src/BlazingPizza.Shared/LatLong.cs b/src/BlazingPizza.Shared/LatLong.cs index 9b8c3811..a65971f8 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( + 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..5c99e3f4 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..b47efad0 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..fbfac7af 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 -{ - 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 Order Order { get; set; } +namespace BlazingPizza; - public string StatusText { get; set; } +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 bool IsDelivered => StatusText == "Delivered"; + public Order Order { get; set; } - public List MapMarkers { get; set; } + public string StatusText { 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 bool IsDelivered => StatusText == "Delivered"; - 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"; + public List MapMarkers { get; set; } - 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), - }; - } + 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); - return new OrderWithStatus - { - Order = order, - StatusText = statusText, - MapMarkers = mapMarkers, - }; + 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"; - private static LatLong ComputeStartPosition(Order order) + 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 { - // 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); + statusText = "Delivered"; + mapMarkers = new List + { + ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true), + }; } - static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) - => new Marker { Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup }; + 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); + } + + 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..2a7a1c29 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..1fd9006a 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..1c062732 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 int ToppingId { get; set; } - - public int PizzaId { get; set; } - } -} + public Topping Topping { get; set; } + + public int ToppingId { 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..4eb67ae9 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..babb4315 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 diff --git a/src/BlazingPizza.sln b/src/BlazingPizza.sln index 1db6afe7..0f195a94 100644 --- a/src/BlazingPizza.sln +++ b/src/BlazingPizza.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.28902.138 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32317.152 MinimumVisualStudioVersion = 15.0.26124.0 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazingPizza.Server", "BlazingPizza.Server\BlazingPizza.Server.csproj", "{29F85A53-A43B-4B5F-8C11-4FC62CDF19D6}" EndProject @@ -10,7 +10,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazingPizza.Shared", "Blaz EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazingPizza.ComponentsLibrary", "BlazingPizza.ComponentsLibrary\BlazingPizza.ComponentsLibrary.csproj", "{0C421DC9-9F9A-4C97-9BC5-D959E8840864}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazingComponents", "BlazingComponents\BlazingComponents.csproj", "{4C4132E7-D096-42DA-9C3D-C444B42C3889}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazingComponents", "BlazingComponents\BlazingComponents.csproj", "{4C4132E7-D096-42DA-9C3D-C444B42C3889}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F9424A4A-0D8F-4320-8063-4D835522DDA5}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution