diff --git a/src/BlazorAdmin/BlazorAdmin.csproj b/src/BlazorAdmin/BlazorAdmin.csproj index 7300c65..84a9a38 100644 --- a/src/BlazorAdmin/BlazorAdmin.csproj +++ b/src/BlazorAdmin/BlazorAdmin.csproj @@ -18,7 +18,6 @@ - diff --git a/src/BlazorAdmin/Constants.cs b/src/BlazorAdmin/Constants.cs index 0ff40f7..ae930e5 100644 --- a/src/BlazorAdmin/Constants.cs +++ b/src/BlazorAdmin/Constants.cs @@ -3,5 +3,10 @@ public class Constants { public const string API_URL = "https://localhost:5099/api/"; + + public static class Roles + { + public const string ADMINISTRATORS = "Administrators"; + } } } diff --git a/src/BlazorAdmin/CustomAuthStateProvider.cs b/src/BlazorAdmin/CustomAuthStateProvider.cs index 6e68d69..bdf4dd5 100644 --- a/src/BlazorAdmin/CustomAuthStateProvider.cs +++ b/src/BlazorAdmin/CustomAuthStateProvider.cs @@ -1,13 +1,8 @@ using System; -using System.Net.Http; -using System.Net.Http.Json; using BlazorAdmin.Services; -using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Components.Authorization; using System.Security.Claims; using System.Threading.Tasks; -using Microsoft.AspNetCore.Components; -using Microsoft.eShopWeb; using Microsoft.Extensions.Logging; using Shared.Authorization; diff --git a/src/BlazorAdmin/Network/SecureHttpClient.cs b/src/BlazorAdmin/Network/SecureHttpClient.cs deleted file mode 100644 index bd01fdb..0000000 --- a/src/BlazorAdmin/Network/SecureHttpClient.cs +++ /dev/null @@ -1,37 +0,0 @@ -using Microsoft.AspNetCore.Components.WebAssembly.Authentication; -using System.Collections.Generic; -using System.Net.Http; -using System.Net.Http.Json; -using System.Threading.Tasks; -using BlazorAdmin.Services.CatalogBrandService; - -namespace BlazorAdmin.Network -{ - public class SecureHttpClient - { - private readonly HttpClient client; - - public SecureHttpClient(HttpClient client) - { - this.client = client; - - this.client.DefaultRequestHeaders.Add("Authorization", $"Bearer "); - } - - public async Task> GetCatalogBrandsAsync() - { - var brands = new List(); - - try - { - brands = (await client.GetFromJsonAsync($"{Constants.API_URL}catalog-brands")).CatalogBrands; - } - catch (AccessTokenNotAvailableException exception) - { - exception.Redirect(); - } - - return brands; - } - } -} diff --git a/src/BlazorAdmin/Pages/CatalogItemPage/Create.razor b/src/BlazorAdmin/Pages/CatalogItemPage/Create.razor index de09858..7c86680 100644 --- a/src/BlazorAdmin/Pages/CatalogItemPage/Create.razor +++ b/src/BlazorAdmin/Pages/CatalogItemPage/Create.razor @@ -5,82 +5,102 @@ @namespace BlazorAdmin.Pages.CatalogItemPage -

Create

-
- - -
- -
- - -
-
- -
- -
- - -
-
- -
- -
- - @foreach (var brand in Brands) +
+ + +@if (_showCreateModal) +{ + +} + @code { [Parameter] @@ -91,21 +111,35 @@ [Parameter] public EventCallback OnCloseClick { get; set; } + private string _modalDisplay = "none;"; + private string _modalClass = ""; + private bool _showCreateModal = false; private readonly CreateCatalogItemRequest _item = new CreateCatalogItemRequest(); - protected override async Task OnAfterRenderAsync(bool firstRender) + private async Task CreateClick() + { + await new BlazorAdmin.Services.CatalogItemService.Create(Auth).HandleAsync(_item); + await OnCloseClick.InvokeAsync(null); + Close(); + } + + public void Open() { Logger.LogInformation("Now loading... /Catalog/Create"); _item.CatalogTypeId = Types.First().Id; _item.CatalogBrandId = Brands.First().Id; - await base.OnAfterRenderAsync(firstRender); + _modalDisplay = "block;"; + _modalClass = "Show"; + _showCreateModal = true; } - private async Task CreateClick() + public void Close() { - await new BlazorAdmin.Services.CatalogItemService.Create(Auth).HandleAsync(_item); - await OnCloseClick.InvokeAsync(null); + _modalDisplay = "none"; + _modalClass = ""; + _showCreateModal = false; + OnCloseClick.InvokeAsync(null); } } diff --git a/src/BlazorAdmin/Pages/CatalogItemPage/Delete.razor b/src/BlazorAdmin/Pages/CatalogItemPage/Delete.razor index 8637d03..82bb464 100644 --- a/src/BlazorAdmin/Pages/CatalogItemPage/Delete.razor +++ b/src/BlazorAdmin/Pages/CatalogItemPage/Delete.razor @@ -5,66 +5,89 @@ @namespace BlazorAdmin.Pages.CatalogItemPage -
-
- + + +@if (_showDeleteModal) +{ + +} + @code { - [Parameter] - public int Id { get; set; } [Parameter] public IEnumerable Brands { get; set; } [Parameter] @@ -73,23 +96,37 @@ [Parameter] public EventCallback OnCloseClick { get; set; } + private string _modalDisplay = "none;"; + private string _modalClass = ""; + private bool _showDeleteModal = false; private CatalogItem _item = new CatalogItem(); - protected override async Task OnInitializedAsync() - { - Logger.LogInformation("Now loading... /Catalog/Delete/{Id}", Id); - - _item = await new GetById(Auth).HandleAsync(Id); - - await base.OnInitializedAsync(); - } - - private async Task DeleteClick() + private async Task DeleteClick(int id) { // TODO: Add some kind of "are you sure" check before this - await new BlazorAdmin.Services.CatalogItemService.Delete(Auth).HandleAsync(Id); + await new BlazorAdmin.Services.CatalogItemService.Delete(Auth).HandleAsync(id); await OnCloseClick.InvokeAsync(null); + Close(); + } + + public async Task Open(int id) + { + Logger.LogInformation("Now loading... /Catalog/Delete/{Id}", id); + + _item = await new GetById(Auth).HandleAsync(id); + + _modalDisplay = "block;"; + _modalClass = "Show"; + _showDeleteModal = true; + } + + public void Close() + { + _modalDisplay = "none"; + _modalClass = ""; + _showDeleteModal = false; + OnCloseClick.InvokeAsync(null); } } diff --git a/src/BlazorAdmin/Pages/CatalogItemPage/Details.razor b/src/BlazorAdmin/Pages/CatalogItemPage/Details.razor index 673494f..12c8956 100644 --- a/src/BlazorAdmin/Pages/CatalogItemPage/Details.razor +++ b/src/BlazorAdmin/Pages/CatalogItemPage/Details.razor @@ -5,95 +5,127 @@ @namespace BlazorAdmin.Pages.CatalogItemPage -@if (_item == null) -{ -

Loading...

-} -else -{ -

Details

-
-
- -
-
- Name -
+
+
+ +
+ } + +
+
- - -
+
+ +@if (_showDetailsModal) +{ + } + @code { - [Parameter] - public int Id { get; set; } [Parameter] public IEnumerable Brands { get; set; } [Parameter] public IEnumerable Types { get; set; } - [Parameter] - public EventCallback OnCloseClick { get; set; } [Parameter] public EventCallback OnEditClick { get; set; } + private string _modalDisplay = "none;"; + private string _modalClass = ""; + private bool _showDetailsModal = false; private CatalogItem _item = new CatalogItem(); - protected override async Task OnInitializedAsync() + public void EditClick() { - Logger.LogInformation("Now loading... /Catalog/Details/{Id}", Id); + OnEditClick.InvokeAsync(_item.Id); + Close(); + } - _item = await new GetById(Auth).HandleAsync(Id); - StateHasChanged(); + public async Task Open(int id) + { + Logger.LogInformation("Now loading... /Catalog/Details/{Id}", id); - await base.OnInitializedAsync(); + _item = await new GetById(Auth).HandleAsync(id); + + _modalDisplay = "block;"; + _modalClass = "Show"; + _showDetailsModal = true; + } + + public void Close() + { + _modalDisplay = "none"; + _modalClass = ""; + _showDetailsModal = false; } } diff --git a/src/BlazorAdmin/Pages/CatalogItemPage/Edit.razor b/src/BlazorAdmin/Pages/CatalogItemPage/Edit.razor index 77f5ca0..4a193ee 100644 --- a/src/BlazorAdmin/Pages/CatalogItemPage/Edit.razor +++ b/src/BlazorAdmin/Pages/CatalogItemPage/Edit.razor @@ -5,85 +5,104 @@ @namespace BlazorAdmin.Pages.CatalogItemPage -

Edit

-
- - -
- -
- - -
-
+