From 45fde3b28f9a0aa5feb93cdb0d79773ea1082404 Mon Sep 17 00:00:00 2001 From: "maxence.guitard" Date: Tue, 9 Jan 2024 15:42:25 +0100 Subject: [PATCH] fix : ajouter questions remarche --- Blazor/Blazor/Models/QuestionModel.cs | 2 +- Blazor/Blazor/Pages/Questions/AddQuestion.razor.cs | 14 +++----------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/Blazor/Blazor/Models/QuestionModel.cs b/Blazor/Blazor/Models/QuestionModel.cs index 586a456..4089498 100644 --- a/Blazor/Blazor/Models/QuestionModel.cs +++ b/Blazor/Blazor/Models/QuestionModel.cs @@ -3,7 +3,7 @@ public class QuestionModel { public int Id { get; set; } - public required string Content { get; set; } + public string Content { get; set; } public int IdChapter { get; set; } public int IdAnswerGood { get; set; } public int Difficulty { get; set; } diff --git a/Blazor/Blazor/Pages/Questions/AddQuestion.razor.cs b/Blazor/Blazor/Pages/Questions/AddQuestion.razor.cs index b67ed9d..551d1fd 100644 --- a/Blazor/Blazor/Pages/Questions/AddQuestion.razor.cs +++ b/Blazor/Blazor/Pages/Questions/AddQuestion.razor.cs @@ -9,7 +9,7 @@ namespace Blazor.Pages.Questions { public partial class AddQuestion { - private QuestionModel? questionModel; + private QuestionModel questionModel = new(); public List chapters = new(); @@ -39,8 +39,8 @@ namespace Blazor.Pages.Questions protected override async Task OnInitializedAsync() { var response = Http.GetFromJsonAsync(API.API_URL + "chapters/" + API.TOKEN).Result; - - chapters = new List(response); + if (response == null) chapters = new List(); + else chapters = new List(response); answerModels = new(); checkboxs = new(); @@ -50,13 +50,6 @@ namespace Blazor.Pages.Questions checkboxs.Add(new Checkbox(i)); } } - - protected override async Task OnInitializedAsync() - { - var response = Http.GetFromJsonAsync(API.API_URL + "chapters/" + API.TOKEN).Result; - if (response == null) chapters = new List(); - else chapters = new List(response); - } private async Task HandleValidSubmit() { if (questionModel != null) @@ -79,7 +72,6 @@ namespace Blazor.Pages.Questions formData.Add(new KeyValuePair("idanswergood", idgood.ToString())); } } - var formContent = new FormUrlEncodedContent(formData);