Skip to content

Commit b1b02e4

Browse files
committed
Upgraded finished project to .NET 6 with C# 10 features
1 parent 9153460 commit b1b02e4

35 files changed

+791
-937
lines changed
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<configuration>
3-
<packageSources>
4-
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
5-
<clear />
6-
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
7-
</packageSources>
8-
</configuration>
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
5+
<clear />
6+
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
7+
</packageSources>
8+
</configuration>

src/BlazingPizza.Client/BlazingPizza.Client.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>$(TargetFrameworkVersion)</TargetFramework>
5+
<ImplicitUsings>true</ImplicitUsings>
56
</PropertyGroup>
67

78
<ItemGroup>
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
using Microsoft.JSInterop;
2-
using System.Threading.Tasks;
32

4-
namespace BlazingPizza.Client
3+
namespace BlazingPizza.Client;
4+
5+
public static class JSRuntimeExtensions
56
{
6-
public static class JSRuntimeExtensions
7-
{
8-
public static ValueTask<bool> Confirm(this IJSRuntime jsRuntime, string message)
9-
{
10-
return jsRuntime.InvokeAsync<bool>("confirm", message);
11-
}
12-
}
7+
public static ValueTask<bool> Confirm(this IJSRuntime jsRuntime, string message)
8+
{
9+
return jsRuntime.InvokeAsync<bool>("confirm", message);
10+
}
1311
}

src/BlazingPizza.Client/OrderState.cs

Lines changed: 49 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,52 @@
1-
using System.Collections.Generic;
1+
namespace BlazingPizza.Client;
22

3-
namespace BlazingPizza.Client
3+
public class OrderState
44
{
5-
public class OrderState
6-
{
7-
public bool ShowingConfigureDialog { get; private set; }
8-
9-
public Pizza ConfiguringPizza { get; private set; }
10-
11-
public Order Order { get; private set; } = new Order();
12-
13-
public void ShowConfigurePizzaDialog(PizzaSpecial special)
14-
{
15-
ConfiguringPizza = new Pizza()
16-
{
17-
Special = special,
18-
SpecialId = special.Id,
19-
Size = Pizza.DefaultSize,
20-
Toppings = new List<PizzaTopping>(),
21-
};
22-
23-
ShowingConfigureDialog = true;
24-
}
25-
26-
public void CancelConfigurePizzaDialog()
27-
{
28-
ConfiguringPizza = null;
29-
ShowingConfigureDialog = false;
30-
}
31-
32-
public void ConfirmConfigurePizzaDialog()
33-
{
34-
Order.Pizzas.Add(ConfiguringPizza);
35-
ConfiguringPizza = null;
36-
37-
ShowingConfigureDialog = false;
38-
}
39-
40-
public void RemoveConfiguredPizza(Pizza pizza)
41-
{
42-
Order.Pizzas.Remove(pizza);
43-
}
44-
45-
public void ResetOrder()
46-
{
47-
Order = new Order();
48-
}
49-
50-
public void ReplaceOrder(Order order)
51-
{
52-
Order = order;
53-
}
54-
}
5+
public bool ShowingConfigureDialog { get; private set; }
6+
7+
public Pizza ConfiguringPizza { get; private set; }
8+
9+
public Order Order { get; private set; } = new Order();
10+
11+
public void ShowConfigurePizzaDialog(PizzaSpecial special)
12+
{
13+
ConfiguringPizza = new Pizza()
14+
{
15+
Special = special,
16+
SpecialId = special.Id,
17+
Size = Pizza.DefaultSize,
18+
Toppings = new List<PizzaTopping>(),
19+
};
20+
21+
ShowingConfigureDialog = true;
22+
}
23+
24+
public void CancelConfigurePizzaDialog()
25+
{
26+
ConfiguringPizza = null;
27+
ShowingConfigureDialog = false;
28+
}
29+
30+
public void ConfirmConfigurePizzaDialog()
31+
{
32+
Order.Pizzas.Add(ConfiguringPizza);
33+
ConfiguringPizza = null;
34+
35+
ShowingConfigureDialog = false;
36+
}
37+
38+
public void RemoveConfiguredPizza(Pizza pizza)
39+
{
40+
Order.Pizzas.Remove(pizza);
41+
}
42+
43+
public void ResetOrder()
44+
{
45+
Order = new Order();
46+
}
47+
48+
public void ReplaceOrder(Order order)
49+
{
50+
Order = order;
51+
}
5552
}
Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,35 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Net.Http;
5-
using System.Net.Http.Json;
6-
using System.Threading.Tasks;
7-
8-
namespace BlazingPizza.Client
1+
using System.Net.Http.Json;
2+
3+
namespace BlazingPizza.Client;
4+
5+
public class OrdersClient
96
{
10-
public class OrdersClient
11-
{
12-
private readonly HttpClient httpClient;
7+
private readonly HttpClient httpClient;
138

14-
public OrdersClient(HttpClient httpClient)
15-
{
16-
this.httpClient = httpClient;
17-
}
9+
public OrdersClient(HttpClient httpClient)
10+
{
11+
this.httpClient = httpClient;
12+
}
1813

19-
public async Task<IEnumerable<OrderWithStatus>> GetOrders() =>
20-
await httpClient.GetFromJsonAsync<IEnumerable<OrderWithStatus>>("orders");
14+
public async Task<IEnumerable<OrderWithStatus>> GetOrders() =>
15+
await httpClient.GetFromJsonAsync<IEnumerable<OrderWithStatus>>("orders");
2116

2217

23-
public async Task<OrderWithStatus> GetOrder(int orderId) =>
24-
await httpClient.GetFromJsonAsync<OrderWithStatus>($"orders/{orderId}");
18+
public async Task<OrderWithStatus> GetOrder(int orderId) =>
19+
await httpClient.GetFromJsonAsync<OrderWithStatus>($"orders/{orderId}");
2520

2621

27-
public async Task<int> PlaceOrder(Order order)
28-
{
29-
var response = await httpClient.PostAsJsonAsync("orders", order);
30-
response.EnsureSuccessStatusCode();
31-
var orderId = await response.Content.ReadFromJsonAsync<int>();
32-
return orderId;
33-
}
22+
public async Task<int> PlaceOrder(Order order)
23+
{
24+
var response = await httpClient.PostAsJsonAsync("orders", order);
25+
response.EnsureSuccessStatusCode();
26+
var orderId = await response.Content.ReadFromJsonAsync<int>();
27+
return orderId;
28+
}
3429

35-
public async Task SubscribeToNotifications(NotificationSubscription subscription)
36-
{
37-
var response = await httpClient.PutAsJsonAsync("notifications/subscribe", subscription);
38-
response.EnsureSuccessStatusCode();
39-
}
40-
}
30+
public async Task SubscribeToNotifications(NotificationSubscription subscription)
31+
{
32+
var response = await httpClient.PutAsJsonAsync("notifications/subscribe", subscription);
33+
response.EnsureSuccessStatusCode();
34+
}
4135
}
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
22

3-
namespace BlazingPizza.Client
3+
namespace BlazingPizza.Client;
4+
5+
public class PizzaAuthenticationState : RemoteAuthenticationState
46
{
5-
public class PizzaAuthenticationState : RemoteAuthenticationState
6-
{
7-
public Order Order { get; set; }
8-
}
7+
public Order Order { get; set; }
98
}

src/BlazingPizza.Client/Program.cs

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,20 @@
11
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
22
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
33
using Microsoft.Extensions.DependencyInjection;
4-
using System;
5-
using System.Net.Http;
6-
using System.Threading.Tasks;
4+
using BlazingPizza.client
75

8-
namespace BlazingPizza.Client
9-
{
10-
public class Program
11-
{
12-
public static async Task Main(string[] args)
13-
{
14-
var builder = WebAssemblyHostBuilder.CreateDefault(args);
15-
builder.RootComponents.Add<App>("#app");
6+
var builder = WebAssemblyHostBuilder.CreateDefault(args);
7+
builder.RootComponents.Add<App>("#app");
168

17-
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
18-
builder.Services.AddHttpClient<OrdersClient>(client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress))
19-
.AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>();
20-
builder.Services.AddScoped<OrderState>();
9+
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
10+
builder.Services.AddHttpClient<OrdersClient>(client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress))
11+
.AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>();
12+
builder.Services.AddScoped<OrderState>();
2113

22-
// Add auth services
23-
builder.Services.AddApiAuthorization<PizzaAuthenticationState>(options =>
24-
{
25-
options.AuthenticationPaths.LogOutSucceededPath = "";
26-
});
14+
// Add auth services
15+
builder.Services.AddApiAuthorization<PizzaAuthenticationState>(options =>
16+
{
17+
options.AuthenticationPaths.LogOutSucceededPath = "";
18+
});
2719

28-
await builder.Build().RunAsync();
29-
}
30-
}
31-
}
20+
await builder.Build().RunAsync();

src/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>$(TargetFrameworkVersion)</TargetFramework>
5+
<ImplicitUsings>true</ImplicitUsings>
56
</PropertyGroup>
67

78
<ItemGroup>
Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
using Microsoft.JSInterop;
2-
using System.Threading.Tasks;
32

4-
namespace BlazingPizza.ComponentsLibrary
3+
namespace BlazingPizza.ComponentsLibrary;
4+
5+
public static class LocalStorage
56
{
6-
public static class LocalStorage
7-
{
8-
public static ValueTask<T> GetAsync<T>(IJSRuntime jsRuntime, string key)
9-
=> jsRuntime.InvokeAsync<T>("blazorLocalStorage.get", key);
7+
public static ValueTask<T> GetAsync<T>(IJSRuntime jsRuntime, string key)
8+
=> jsRuntime.InvokeAsync<T>("blazorLocalStorage.get", key);
109

11-
public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object value)
12-
=> jsRuntime.InvokeVoidAsync("blazorLocalStorage.set", key, value);
10+
public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object value)
11+
=> jsRuntime.InvokeVoidAsync("blazorLocalStorage.set", key, value);
1312

14-
public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key)
15-
=> jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key);
16-
}
17-
}
13+
public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key)
14+
=> jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key);
15+
}
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
namespace BlazingPizza.ComponentsLibrary.Map
1+
namespace BlazingPizza.ComponentsLibrary.Map;
2+
3+
public class Marker
24
{
3-
public class Marker
4-
{
5-
public string Description { get; set; }
5+
public string Description { get; set; }
66

7-
public double X { get; set; }
7+
public double X { get; set; }
88

9-
public double Y { get; set; }
9+
public double Y { get; set; }
1010

11-
public bool ShowPopup { get; set; }
12-
}
11+
public bool ShowPopup { get; set; }
1312
}

0 commit comments

Comments
 (0)