fix : ajouter question

Multiplayer_Php
Maxence GUITARD 1 year ago
parent a73a649c9a
commit 7a13284a0b

@ -31,7 +31,6 @@
{ {
var answerModel = answerModels[index]; var answerModel = answerModels[index];
var checkbox = checkboxs[index]; var checkbox = checkboxs[index];
var idgoodLocal = checkbox.Id+1;
<p> <p>
<label for="@($"answer{answerModel.Id}")"> <label for="@($"answer{answerModel.Id}")">
@ -39,11 +38,9 @@
<InputText id="@($"answer{answerModel.Id}")" @bind-Value="answerModel.Content" /> <InputText id="@($"answer{answerModel.Id}")" @bind-Value="answerModel.Content" />
</label> </label>
<label for="@($"checkbox{checkbox.Id}")"> <label for="@($"checkbox{checkbox.Id}")">
@idgoodLocal
<InputCheckbox id="@($"checkbox{checkbox.Id}")" @bind-Value="checkbox.IsCorrect" /> Correcte <InputCheckbox id="@($"checkbox{checkbox.Id}")" @bind-Value="checkbox.IsCorrect" /> Correcte
</label> </label>
</p> </p>
} }
<button type="submit">Submit</button> <button type="submit">Submit</button>
</EditForm> </EditForm>

@ -36,8 +36,12 @@ namespace Blazor.Pages.Questions
public Checkbox(int id) { Id = id; IsCorrect = false; } public Checkbox(int id) { Id = id; IsCorrect = false; }
} }
protected override void OnInitialized() protected override async Task OnInitializedAsync()
{ {
var response = Http.GetFromJsonAsync<Chapter[]>(API.API_URL + "chapters/" + API.TOKEN).Result;
chapters = new List<Chapter>(response);
answerModels = new(); answerModels = new();
checkboxs = new(); checkboxs = new();
for(int i = 0; i < 4; i++) for(int i = 0; i < 4; i++)
@ -46,13 +50,6 @@ namespace Blazor.Pages.Questions
checkboxs.Add(new Checkbox(i)); checkboxs.Add(new Checkbox(i));
} }
} }
protected override async Task OnInitializedAsync()
{
var response = Http.GetFromJsonAsync<Chapter[]>(API.API_URL + "chapters/" + API.TOKEN).Result;
chapters = new List<Chapter>(response);
}
private async void HandleValidSubmit() private async void HandleValidSubmit()
{ {

@ -1,6 +1,7 @@
using Blazor.Models; using Blazor.Models;
using Blazor.Services; using Blazor.Services;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using static Blazor.Pages.Questions.AddQuestion;
namespace Blazor.Pages.Questions namespace Blazor.Pages.Questions
{ {
@ -24,13 +25,36 @@ namespace Blazor.Pages.Questions
[Inject] [Inject]
public required ILogger<EditQuestion> Logger { get; set; } public required ILogger<EditQuestion> Logger { get; set; }
protected override async Task OnInitializedAsync()
{
var question = await DataService.GetQuestionById(Id);
questionModel = new QuestionModel
{
Id = question.Id,
Content = question.Content
};
}
private async Task HandleValidSubmit() private async Task HandleValidSubmit()
{ {
await DataService.Update(Id, questionModel); await DataService.Update(Id, questionModel);
var formData = new List<KeyValuePair<string, string>>(); var formData = new List<KeyValuePair<string, string>>();
formData.Add(new KeyValuePair<string, string>("content", questionModel.Content)); formData.Add(new KeyValuePair<string, string>("content", questionModel.Content));
formData.Add(new KeyValuePair<string, string>("idchapter", questionModel.IdChapter.ToString()));
//foreach (var answerModel in answerModels)
//{
// var answercontent = $"answerContent{answerModel.Id + 1}";
// formData.Add(new KeyValuePair<string, string>(answercontent, answerModel.Content));
//}
//foreach (var checkbox in checkboxs)
//{
// if (checkbox.IsCorrect != false)
// {
// var idgood = checkbox.Id + 1;
// formData.Add(new KeyValuePair<string, string>("idanswergood", idgood.ToString()));
// }
//}
var formContent = new FormUrlEncodedContent(formData); var formContent = new FormUrlEncodedContent(formData);

Loading…
Cancel
Save