fix : ajouter question

Multiplayer_Php
Maxence GUITARD 1 year ago
parent a73a649c9a
commit 7a13284a0b

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

@ -35,9 +35,13 @@ namespace Blazor.Pages.Questions
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();
checkboxs = new();
for(int i = 0; i < 4; i++)
@ -46,13 +50,6 @@ namespace Blazor.Pages.Questions
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()
{

@ -1,6 +1,7 @@
using Blazor.Models;
using Blazor.Services;
using Microsoft.AspNetCore.Components;
using static Blazor.Pages.Questions.AddQuestion;
namespace Blazor.Pages.Questions
{
@ -24,13 +25,36 @@ namespace Blazor.Pages.Questions
[Inject]
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()
{
await DataService.Update(Id, questionModel);
var formData = new List<KeyValuePair<string, string>>();
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);

Loading…
Cancel
Save