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