feat : edit admin

pull/38/head
Maxence GUITARD 1 year ago
commit 06c15130a6

@ -25,6 +25,7 @@
<PackageReference Include="Blazorise.Icons.FontAwesome" Version="1.4.0" /> <PackageReference Include="Blazorise.Icons.FontAwesome" Version="1.4.0" />
<PackageReference Include="ChoETL.JSON.NETStandard" Version="1.2.1.64" /> <PackageReference Include="ChoETL.JSON.NETStandard" Version="1.2.1.64" />
<PackageReference Include="ChoETL.NETStandard" Version="1.2.1.64" /> <PackageReference Include="ChoETL.NETStandard" Version="1.2.1.64" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="8.0.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" /> <PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" /> <PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
</ItemGroup> </ItemGroup>

@ -16,6 +16,9 @@ namespace Blazor.Pages.Admins
[Inject] [Inject]
public NavigationManager NavigationManager { get; set; } public NavigationManager NavigationManager { get; set; }
[Inject]
public ILogger<AddAdministrator> Logger { get; set; }
private async void HandleValidSubmit() private async void HandleValidSubmit()
{ {
@ -45,6 +48,8 @@ namespace Blazor.Pages.Admins
} }
} }
Logger.LogInformation("Admin '{administratorsModelName}' added", administratorModel.Username);
NavigationManager.NavigateTo("administrators"); NavigationManager.NavigateTo("administrators");
} }
} }

@ -1,4 +1,5 @@
using Blazor.Models; using Blazor.Models;
using Blazor.Pages.Chapters;
using Blazor.Services; using Blazor.Services;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
@ -21,6 +22,9 @@ namespace Blazor.Pages.Admins
[Inject] [Inject]
public IWebHostEnvironment WebHostEnvironment { get; set; } public IWebHostEnvironment WebHostEnvironment { get; set; }
[Inject]
public ILogger<EditAdministrator> Logger { get; set; }
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
var administrator = await DataService.GetAdminById(Id); var administrator = await DataService.GetAdminById(Id);
@ -61,6 +65,9 @@ namespace Blazor.Pages.Admins
} }
} }
Logger.LogInformation("Chapter '{administratorsModelName}' edited", administratorsModel.Username);
NavigationManager.NavigateTo("administrators"); NavigationManager.NavigateTo("administrators");
} }
} }

@ -14,6 +14,10 @@ public partial class AddChapter
[Inject] [Inject]
public NavigationManager NavigationManager { get; set; } public NavigationManager NavigationManager { get; set; }
[Inject]
public ILogger<AddChapter> Logger { get; set; }
private async void HandleValidSubmit() private async void HandleValidSubmit()
{ {
@ -40,6 +44,9 @@ public partial class AddChapter
var errorResponse = await response.Content.ReadAsStringAsync(); var errorResponse = await response.Content.ReadAsStringAsync();
} }
} }
Logger.LogInformation("Chapter '{chapterModelName}' added",chapterModel.Name);
NavigationManager.NavigateTo("chapters"); NavigationManager.NavigateTo("chapters");
} }

@ -20,9 +20,15 @@ public partial class EditChapter
[Inject] [Inject]
public IWebHostEnvironment WebHostEnvironment { get; set; } public IWebHostEnvironment WebHostEnvironment { get; set; }
[Inject]
public ILogger<EditChapter> Logger { get; set; }
private string oldChapterName { get; set; }
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
var chapter = await DataService.GetById(Id); var chapter = await DataService.GetById(Id);
oldChapterName = chapter.Name;
// Set the model with the chapter // Set the model with the chapter
chapterModel = new ChapterModel chapterModel = new ChapterModel
@ -35,6 +41,7 @@ public partial class EditChapter
private async void HandleValidSubmit() private async void HandleValidSubmit()
{ {
await DataService.Update(Id, chapterModel); await DataService.Update(Id, chapterModel);
var formData = new List<KeyValuePair<string, string>>(); var formData = new List<KeyValuePair<string, string>>();
formData.Add(new KeyValuePair<string, string>("name", chapterModel.Name)); formData.Add(new KeyValuePair<string, string>("name", chapterModel.Name));
@ -47,6 +54,9 @@ public partial class EditChapter
{ {
var response = await httpClient.PostAsync(apiUri, formContent); var response = await httpClient.PostAsync(apiUri, formContent);
Logger.LogInformation("Chapter '{OldChapterModelName}' edited in '{NewChapterModelName}'",oldChapterName,chapterModel.Name);
if (response.IsSuccessStatusCode) if (response.IsSuccessStatusCode)
{ {
var responseBody = await response.Content.ReadAsStringAsync(); var responseBody = await response.Content.ReadAsStringAsync();

@ -7,6 +7,7 @@ using Blazorise.Icons.FontAwesome;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.Web;
using Blazored.Modal; using Blazored.Modal;
using Microsoft.Extensions.Logging;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@ -36,6 +37,8 @@ builder.Services.AddBlazoredModal();
builder.Services.AddScoped<IDataService, DataLocalService>(); builder.Services.AddScoped<IDataService, DataLocalService>();
builder.Logging.AddConfiguration(builder.Configuration.GetSection("Logging"));
var app = builder.Build(); var app = builder.Build();
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.

@ -2,8 +2,8 @@
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Information", "Default": "Information",
"Microsoft.AspNetCore": "Warning" "Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
} }
}, }
"AllowedHosts": "*"
} }
Loading…
Cancel
Save