Skip to content

Commit 1e7e5af

Browse files
Update to .NET 5
1 parent f43e3b8 commit 1e7e5af

36 files changed

+432
-243
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.30011.22
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31410.414
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorProducts.Client", "BlazorProducts.Client\BlazorProducts.Client.csproj", "{859DA53E-0638-4572-AE68-343E1FEECF1C}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorProducts.Client", "BlazorProducts.Client\BlazorProducts.Client.csproj", "{EE166BF0-8FAD-4D2C-8D1C-CB1EE11EEB6E}"
77
EndProject
8-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entities", "..\BlazorProducts.Server\Entities\Entities.csproj", "{5BC32412-B287-4741-9769-8B33BAFFF867}"
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entities", "..\BlazorProducts.Server\Entities\Entities.csproj", "{0ED77E16-F5D9-4364-8706-8998C6724EAA}"
99
EndProject
1010
Global
1111
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1212
Debug|Any CPU = Debug|Any CPU
1313
Release|Any CPU = Release|Any CPU
1414
EndGlobalSection
1515
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16-
{859DA53E-0638-4572-AE68-343E1FEECF1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17-
{859DA53E-0638-4572-AE68-343E1FEECF1C}.Debug|Any CPU.Build.0 = Debug|Any CPU
18-
{859DA53E-0638-4572-AE68-343E1FEECF1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
19-
{859DA53E-0638-4572-AE68-343E1FEECF1C}.Release|Any CPU.Build.0 = Release|Any CPU
20-
{5BC32412-B287-4741-9769-8B33BAFFF867}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21-
{5BC32412-B287-4741-9769-8B33BAFFF867}.Debug|Any CPU.Build.0 = Debug|Any CPU
22-
{5BC32412-B287-4741-9769-8B33BAFFF867}.Release|Any CPU.ActiveCfg = Release|Any CPU
23-
{5BC32412-B287-4741-9769-8B33BAFFF867}.Release|Any CPU.Build.0 = Release|Any CPU
16+
{EE166BF0-8FAD-4D2C-8D1C-CB1EE11EEB6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{EE166BF0-8FAD-4D2C-8D1C-CB1EE11EEB6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{EE166BF0-8FAD-4D2C-8D1C-CB1EE11EEB6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{EE166BF0-8FAD-4D2C-8D1C-CB1EE11EEB6E}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{0ED77E16-F5D9-4364-8706-8998C6724EAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{0ED77E16-F5D9-4364-8706-8998C6724EAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{0ED77E16-F5D9-4364-8706-8998C6724EAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{0ED77E16-F5D9-4364-8706-8998C6724EAA}.Release|Any CPU.Build.0 = Release|Any CPU
2424
EndGlobalSection
2525
GlobalSection(SolutionProperties) = preSolution
2626
HideSolutionNode = FALSE
2727
EndGlobalSection
2828
GlobalSection(ExtensibilityGlobals) = postSolution
29-
SolutionGuid = {89F0EFC5-EF30-4539-88C3-23B5873796CE}
29+
SolutionGuid = {623D0ADD-8341-4510-9D71-1A93562E0B47}
3030
EndGlobalSection
3131
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
@using BlazorProducts.Client.Pages
22

3-
<Router AppAssembly="@typeof(Program).Assembly">
4-
<Found Context="routeData">
5-
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
6-
<Authorizing>
7-
<text> Please wait, we are authorizing the user. </text>
8-
</Authorizing>
9-
<NotAuthorized>
10-
<text> You are not authorized to access this page. </text>
11-
</NotAuthorized>
12-
</AuthorizeRouteView>
13-
</Found>
14-
<NotFound>
15-
<CascadingAuthenticationState>
3+
<CascadingAuthenticationState>
4+
<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true">
5+
<Found Context="routeData">
6+
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
7+
<Authorizing>
8+
<text>Please wait, we are authorizint the user.</text>
9+
</Authorizing>
10+
<NotAuthorized>
11+
<text> You are not authorized to access this page. </text>
12+
</NotAuthorized>
13+
</AuthorizeRouteView>
14+
</Found>
15+
<NotFound>
1616
<LayoutView Layout="@typeof(MainLayout)">
1717
<CustomNotFound />
1818
</LayoutView>
19-
</CascadingAuthenticationState>
20-
</NotFound>
21-
</Router>
19+
</NotFound>
20+
</Router>
21+
</CascadingAuthenticationState>

BlazorProducts.Client/BlazorProducts.Client/AuthProviders/TestAuthStateProvider.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ public class TestAuthStateProvider : AuthenticationStateProvider
99
{
1010
public async override Task<AuthenticationState> GetAuthenticationStateAsync()
1111
{
12-
await Task.Delay(1500);
13-
var claims = new List<Claim>
14-
{
15-
new Claim(ClaimTypes.Name, "John Doe"),
16-
new Claim(ClaimTypes.Role, "Administrator")
17-
};
18-
var anonymous = new ClaimsIdentity();
12+
await Task.Delay(1500);
13+
var claims = new List<Claim>
14+
{
15+
new Claim(ClaimTypes.Name, "John Doe"),
16+
new Claim(ClaimTypes.Role, "Administrator")
17+
};
18+
var anonymous = new ClaimsIdentity();
1919
return await Task.FromResult(new AuthenticationState(new ClaimsPrincipal(anonymous)));
2020
}
2121
}
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.1</TargetFramework>
5-
<RazorLangVersion>3.0</RazorLangVersion>
4+
<TargetFramework>net5.0</TargetFramework>
65
</PropertyGroup>
76

87
<ItemGroup>
9-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.0" />
10-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="3.2.0" />
11-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.0" PrivateAssets="all" />
12-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.0" PrivateAssets="all" />
13-
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.2.0-preview3.20168.3" />
8+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.7" />
9+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="5.0.7" />
10+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.7" PrivateAssets="all" />
1411
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
15-
<PackageReference Include="Tewr.Blazor.FileReader" Version="2.0.0.20200" />
12+
<PackageReference Include="System.Net.Http.Json" Version="5.0.0" />
1613
</ItemGroup>
1714

1815
<ItemGroup>
1916
<ProjectReference Include="..\..\BlazorProducts.Server\Entities\Entities.csproj" />
2017
</ItemGroup>
18+
2119
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<h1>@Title</h1>
2+
3+
<p>Current count: @CurrentCount</p>
4+
5+
@code {
6+
[Parameter]
7+
public string Title { get; set; }
8+
[Parameter]
9+
public int CurrentCount { get; set; }
10+
11+
protected override void OnInitialized()
12+
{
13+
Console.WriteLine($"OnInitialized => Title: {Title}, CurrentCount: {CurrentCount}");
14+
}
15+
16+
protected override void OnParametersSet()
17+
{
18+
Console.WriteLine($"OnParameterSet => Title: {Title}, CurrentCount: {CurrentCount}");
19+
}
20+
21+
protected override void OnAfterRender(bool firstRender)
22+
{
23+
if(firstRender)
24+
{
25+
Console.WriteLine("This is the first render of the component");
26+
}
27+
}
28+
29+
protected override bool ShouldRender()
30+
{
31+
return true;
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
using Microsoft.AspNetCore.Components;
2-
using System;
32
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Threading.Tasks;
63

74
namespace BlazorProducts.Client.Components
85
{
9-
public partial class Home
10-
{
11-
[Parameter]
12-
public string Title { get; set; }
6+
public partial class Home
7+
{
8+
[Parameter]
9+
public string Title { get; set; }
1310

14-
[Parameter(CaptureUnmatchedValues = true)]
15-
public Dictionary<string, object> AdditionalAttributes { get; set; }
11+
[Parameter(CaptureUnmatchedValues = true)]
12+
public Dictionary<string, object> AdditionalAttributes { get; set; }
1613

17-
[CascadingParameter]
18-
public string Color { get; set; }
14+
[CascadingParameter(Name = "HeadingColor")]
15+
public string Color { get; set; }
1916

20-
[Parameter]
21-
public RenderFragment VisitShopContent { get; set; }
22-
}
17+
[Parameter]
18+
public RenderFragment VisitShopContent { get; set; }
19+
}
2320
}

BlazorProducts.Client/BlazorProducts.Client/Components/ProductTable/ProductTable.razor.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,28 @@
99

1010
namespace BlazorProducts.Client.Components.ProductTable
1111
{
12-
public partial class ProductTable
12+
public partial class ProductTable
1313
{
1414
[Parameter]
1515
public List<Product> Products { get; set; }
1616
[Parameter]
1717
public EventCallback<Guid> OnDeleted { get; set; }
18-
[Inject]
18+
[Inject]
1919
public NavigationManager NavigationManager { get; set; }
2020
[Inject]
2121
public IJSRuntime Js { get; set; }
2222

23-
private void RedirectToUpdate(Guid id)
24-
{
25-
var url = Path.Combine("/updateProduct/", id.ToString());
26-
NavigationManager.NavigateTo(url);
23+
private void RedirectToUpdate(Guid id)
24+
{
25+
var url = Path.Combine("/updateProduct/", id.ToString());
26+
NavigationManager.NavigateTo(url);
2727
}
2828

2929
private async Task Delete(Guid id)
3030
{
3131
var product = Products.FirstOrDefault(p => p.Id.Equals(id));
3232
var confirmed = await Js.InvokeAsync<bool>("confirm", $"Are you sure you want to delete {product.Name} product?");
33-
if(confirmed)
33+
if (confirmed)
3434
{
3535
await OnDeleted.InvokeAsync(id);
3636
}

BlazorProducts.Client/BlazorProducts.Client/HttpRepository/AuthenticationService.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,25 @@ namespace BlazorProducts.Client.HttpRepository
1212
public class AuthenticationService : IAuthenticationService
1313
{
1414
private readonly HttpClient _client;
15+
private readonly JsonSerializerOptions _options;
1516

1617
public AuthenticationService(HttpClient client)
1718
{
1819
_client = client;
20+
_options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
1921
}
2022

2123
public async Task<RegistrationResponseDto> RegisterUser(UserForRegistrationDto userForRegistration)
2224
{
2325
var content = JsonSerializer.Serialize(userForRegistration);
2426
var bodyContent = new StringContent(content, Encoding.UTF8, "application/json");
2527

26-
var registrationResult = await _client.PostAsync("https://localhost:5011/api/accounts/registration", bodyContent);
28+
var registrationResult = await _client.PostAsync("accounts/registration", bodyContent);
2729
var registrationContent = await registrationResult.Content.ReadAsStringAsync();
2830

2931
if (!registrationResult.IsSuccessStatusCode)
3032
{
31-
var result = JsonSerializer.Deserialize<RegistrationResponseDto>(registrationContent, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
33+
var result = JsonSerializer.Deserialize<RegistrationResponseDto>(registrationContent, _options);
3234
return result;
3335
}
3436

BlazorProducts.Client/BlazorProducts.Client/HttpRepository/ProductHttpRepository.cs

+27-27
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Entities.Models;
33
using Entities.RequestFeatures;
44
using Entities.RequestParameters;
5+
using Microsoft.AspNetCore.Components;
56
using Microsoft.AspNetCore.WebUtilities;
67
using System;
78
using System.Collections.Generic;
@@ -17,10 +18,12 @@ namespace BlazorProducts.Client.HttpRepository
1718
public class ProductHttpRepository : IProductHttpRepository
1819
{
1920
private readonly HttpClient _client;
21+
private readonly JsonSerializerOptions _options;
2022

2123
public ProductHttpRepository(HttpClient client)
2224
{
2325
_client = client;
26+
_options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
2427
}
2528

2629
public async Task<PagingResponse<Product>> GetProducts(ProductParameters productParameters)
@@ -31,42 +34,39 @@ public async Task<PagingResponse<Product>> GetProducts(ProductParameters product
3134
["searchTerm"] = productParameters.SearchTerm == null ? "" : productParameters.SearchTerm,
3235
["orderBy"] = productParameters.OrderBy
3336
};
34-
35-
var response = await _client.GetAsync(QueryHelpers.AddQueryString("https://localhost:5011/api/products", queryStringParam));
37+
var response = await _client.GetAsync(QueryHelpers.AddQueryString("products", queryStringParam));
3638
var content = await response.Content.ReadAsStringAsync();
3739
if (!response.IsSuccessStatusCode)
3840
{
3941
throw new ApplicationException(content);
4042
}
41-
4243
var pagingResponse = new PagingResponse<Product>
4344
{
44-
Items = JsonSerializer.Deserialize<List<Product>>(content, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }),
45-
MetaData = JsonSerializer.Deserialize<MetaData>(response.Headers.GetValues("X-Pagination").First(), new JsonSerializerOptions { PropertyNameCaseInsensitive = true})
45+
Items = JsonSerializer.Deserialize<List<Product>>(content, _options),
46+
MetaData = JsonSerializer.Deserialize<MetaData>(response.Headers.GetValues("X-Pagination").First(), _options)
4647
};
47-
48+
4849
return pagingResponse;
4950
}
5051

51-
public async Task CreateProduct(Product product)
52-
{
53-
var content = JsonSerializer.Serialize(product);
54-
var bodyContent = new StringContent(content, Encoding.UTF8, "application/json");
52+
public async Task CreateProduct(Product product)
53+
{
54+
var content = JsonSerializer.Serialize(product);
55+
var bodyContent = new StringContent(content, Encoding.UTF8, "application/json");
5556

56-
var postResult = await _client.PostAsync("https://localhost:5011/api/products", bodyContent);
57-
var postContent = await postResult.Content.ReadAsStringAsync();
57+
var postResult = await _client.PostAsync("products", bodyContent);
58+
var postContent = await postResult.Content.ReadAsStringAsync();
5859

59-
if(!postResult.IsSuccessStatusCode)
60-
{
61-
throw new ApplicationException(postContent);
62-
}
60+
if (!postResult.IsSuccessStatusCode)
61+
{
62+
throw new ApplicationException(postContent);
63+
}
6364
}
6465

6566
public async Task<string> UploadProductImage(MultipartFormDataContent content)
6667
{
67-
var postResult = await _client.PostAsync("https://localhost:5011/api/upload", content);
68+
var postResult = await _client.PostAsync("upload", content);
6869
var postContent = await postResult.Content.ReadAsStringAsync();
69-
7070
if (!postResult.IsSuccessStatusCode)
7171
{
7272
throw new ApplicationException(postContent);
@@ -80,7 +80,7 @@ public async Task<string> UploadProductImage(MultipartFormDataContent content)
8080

8181
public async Task<Product> GetProduct(string id)
8282
{
83-
var url = Path.Combine("https://localhost:5011/api/products/", id);
83+
var url = Path.Combine("products", id);
8484

8585
var response = await _client.GetAsync(url);
8686
var content = await response.Content.ReadAsStringAsync();
@@ -89,29 +89,29 @@ public async Task<Product> GetProduct(string id)
8989
throw new ApplicationException(content);
9090
}
9191

92-
var product = JsonSerializer.Deserialize<Product>(content, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
92+
var product = JsonSerializer.Deserialize<Product>(content, _options);
9393
return product;
9494
}
9595

9696
public async Task UpdateProduct(Product product)
9797
{
9898
var content = JsonSerializer.Serialize(product);
9999
var bodyContent = new StringContent(content, Encoding.UTF8, "application/json");
100-
var url = Path.Combine("https://localhost:5011/api/products/", product.Id.ToString());
100+
var url = Path.Combine("products", product.Id.ToString());
101101

102-
var putResult = await _client.PutAsync(url, bodyContent);
103-
var putContent = await putResult.Content.ReadAsStringAsync();
102+
var postResult = await _client.PutAsync(url, bodyContent);
103+
var postContent = await postResult.Content.ReadAsStringAsync();
104104

105-
if (!putResult.IsSuccessStatusCode)
105+
if (!postResult.IsSuccessStatusCode)
106106
{
107-
throw new ApplicationException(putContent);
107+
throw new ApplicationException(postContent);
108108
}
109109
}
110110

111111
public async Task DeleteProduct(Guid id)
112112
{
113-
var url = Path.Combine("https://localhost:5011/api/products", id.ToString());
114-
113+
var url = Path.Combine("products", id.ToString());
114+
115115
var deleteResult = await _client.DeleteAsync(url);
116116
var deleteContent = await deleteResult.Content.ReadAsStringAsync();
117117

0 commit comments

Comments
 (0)