Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making changes toward .NET 6 migration for fixing #320 #321

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,5 @@ ASALocalRun/

# Visual Studio Code folder
.vscode/
*.db-wal
*.db-shm
8 changes: 4 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project>
<PropertyGroup>
<AspNetCoreVersion>5.0.0</AspNetCoreVersion>
<BlazorVersion>5.0.0</BlazorVersion>
<EntityFrameworkVersion>5.0.0</EntityFrameworkVersion>
<SystemNetHttpJsonVersion>5.0.0</SystemNetHttpJsonVersion>
<AspNetCoreVersion>6.0.0-rc.1</AspNetCoreVersion>
<BlazorVersion>6.0.0-rc.1</BlazorVersion>
<EntityFrameworkVersion>6.0.0-rc.1</EntityFrameworkVersion>
<SystemNetHttpJsonVersion>6.0.0-rc.1</SystemNetHttpJsonVersion>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/BlazingComponents/BlazingComponents.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions src/BlazingPizza.Client/BlazingPizza.Client.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="$(BlazorVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="$(BlazorVersion)" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="$(BlazorVersion)" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="$(BlazorVersion)" />
<PackageReference Include="Microsoft.Extensions.Http" Version="$(SystemNetHttpJsonVersion)" />
<PackageReference Include="System.Net.Http.Json" Version="$(SystemNetHttpJsonVersion)" />
Expand Down
11 changes: 5 additions & 6 deletions src/BlazingPizza.Client/JSRuntimeExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using Microsoft.JSInterop;
using System.Threading.Tasks;

namespace BlazingPizza.Client
namespace BlazingPizza.Client;

public static class JSRuntimeExtensions
{
public static class JSRuntimeExtensions
public static ValueTask<bool> Confirm(this IJSRuntime jsRuntime, string message)
{
public static ValueTask<bool> Confirm(this IJSRuntime jsRuntime, string message)
{
return jsRuntime.InvokeAsync<bool>("confirm", message);
}
return jsRuntime.InvokeAsync<bool>("confirm", message);
}
}
81 changes: 40 additions & 41 deletions src/BlazingPizza.Client/OrderState.cs
Original file line number Diff line number Diff line change
@@ -1,55 +1,54 @@
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<PizzaTopping>(),
};

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<PizzaTopping>(),
};

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;
}
}
51 changes: 24 additions & 27 deletions src/BlazingPizza.Client/OrdersClient.cs
Original file line number Diff line number Diff line change
@@ -1,41 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading.Tasks;

namespace BlazingPizza.Client
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<IEnumerable<OrderWithStatus>> GetOrders() =>
await httpClient.GetFromJsonAsync<IEnumerable<OrderWithStatus>>("orders");
public async Task<IEnumerable<OrderWithStatus>> GetOrders() =>
await httpClient.GetFromJsonAsync<IEnumerable<OrderWithStatus>>("orders");


public async Task<OrderWithStatus> GetOrder(int orderId) =>
await httpClient.GetFromJsonAsync<OrderWithStatus>($"orders/{orderId}");
public async Task<OrderWithStatus> GetOrder(int orderId) =>
await httpClient.GetFromJsonAsync<OrderWithStatus>($"orders/{orderId}");


public async Task<int> PlaceOrder(Order order)
{
var response = await httpClient.PostAsJsonAsync("orders", order);
response.EnsureSuccessStatusCode();
var orderId = await response.Content.ReadFromJsonAsync<int>();
return orderId;
}
public async Task<int> PlaceOrder(Order order)
{
var response = await httpClient.PostAsJsonAsync("orders", order);
response.EnsureSuccessStatusCode();
var orderId = await response.Content.ReadFromJsonAsync<int>();
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();
}
}
9 changes: 4 additions & 5 deletions src/BlazingPizza.Client/PizzaAuthenticationState.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
40 changes: 14 additions & 26 deletions src/BlazingPizza.Client/Program.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using BlazingPizza.Client;
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>("#app");
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddHttpClient<OrdersClient>(client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress))
.AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>();
builder.Services.AddScoped<OrderState>();
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddHttpClient<OrdersClient>(client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress))
.AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>();
builder.Services.AddScoped<OrderState>();

// Add auth services
builder.Services.AddApiAuthorization<PizzaAuthenticationState>(options =>
{
options.AuthenticationPaths.LogOutSucceededPath = "";
});
// Add auth services
builder.Services.AddApiAuthorization<PizzaAuthenticationState>(options =>
{
options.AuthenticationPaths.LogOutSucceededPath = "";
});

await builder.Build().RunAsync();
}
}
}
await builder.Build().RunAsync();
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
19 changes: 9 additions & 10 deletions src/BlazingPizza.ComponentsLibrary/LocalStorage.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using Microsoft.JSInterop;
using System.Threading.Tasks;

namespace BlazingPizza.ComponentsLibrary
namespace BlazingPizza.ComponentsLibrary;

public static class LocalStorage
{
public static class LocalStorage
{
public static ValueTask<T> GetAsync<T>(IJSRuntime jsRuntime, string key)
=> jsRuntime.InvokeAsync<T>("blazorLocalStorage.get", key);
public static ValueTask<T> GetAsync<T>(IJSRuntime jsRuntime, string key)
=> jsRuntime.InvokeAsync<T>("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);
}
15 changes: 7 additions & 8 deletions src/BlazingPizza.ComponentsLibrary/Map/Marker.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
11 changes: 5 additions & 6 deletions src/BlazingPizza.ComponentsLibrary/Map/Point.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
3 changes: 2 additions & 1 deletion src/BlazingPizza.Server/BlazingPizza.Server.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading