feat : ajouter question

Multiplayer_Php
Maxence GUITARD 1 year ago
parent f846db17c1
commit 30f2da7a7b

@ -6,8 +6,6 @@ public class AnswerModel
public int Id { get; set; }
public string Content { get; set; }
public int IdQuestion { get; set; }
public AnswerModel() { }
public AnswerModel(int id)
{
Id = id;

@ -26,7 +26,6 @@
</InputSelect>
</label>
</p>
<p>Taille de answerModels avant la boucle : @answerModels.Count</p>
@foreach (var index in Enumerable.Range(0, answerModels.Count))
{
@ -38,10 +37,9 @@
<InputText id="@($"answer{answerModel.Id}")" @bind-Value="answerModel.Content" />
</label>
<label for="@($"checkbox{checkbox.Id}")">
<InputCheckbox id="@($"checkbox{checkbox.Id}")" @bind-Value="checkbox.IsCorrect" @onchange="() => SetCorrectAnswer(answerModel.Id)" /> Correcte
<InputCheckbox id="@($"checkbox{checkbox.Id}")" @bind-Value="checkbox.IsCorrect" /> Correcte
</label>
</p>
}
<button type="submit">Submit</button>
</EditForm>

@ -47,11 +47,6 @@ namespace Blazor.Pages.Questions
}
}
private void SetCorrectAnswer(int Id)
{
questionModel.IdAnswerGood = Id;
}
protected override async Task OnInitializedAsync()
{
var response = Http.GetFromJsonAsync<Chapter[]>($"https://trusting-panini.87-106-126-109.plesk.page/api/chapters/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO").Result;
@ -64,19 +59,25 @@ namespace Blazor.Pages.Questions
await DataService.Add(questionModel);
var formData = new List<KeyValuePair<string, string>>();
formData.Add(new KeyValuePair<string, string>("content", questionModel.Content));
formData.Add(new KeyValuePair<string, string>("chapter", questionModel.IdChapter.ToString()));
for (int i = 0; i < answerModels.Count; i++)
formData.Add(new KeyValuePair<string, string>("idchapter", questionModel.IdChapter.ToString()));
foreach (var answerModel in answerModels)
{
formData.Add(new KeyValuePair<string, string>($"answercontent{i + 1}", answerModels[i].Content));
formData.Add(new KeyValuePair<string, string>($"answercontent{answerModel.Id+1}", answerModel.Content));
}
formData.Add(new KeyValuePair<string, string>("idanswergood", questionModel.IdAnswerGood.ToString()));
foreach (var checkbox in checkboxs)
{
if (checkbox.IsCorrect == true)
{
var idgood = checkbox.Id + 1;
formData.Add(new KeyValuePair<string, string>("idanswergood", idgood.ToString()));
}
}
var formContent = new FormUrlEncodedContent(formData);
string apiUri = API.API_URL+"add/administrator/"+API.TOKEN;
string apiUri = API.API_URL+"add/question/"+API.TOKEN;
using (var httpClient = new HttpClient())
{

@ -3,7 +3,7 @@
public class Answer
{
public int Id { get; set; }
public string Content { get; set; }
public string? Content { get; set; }
public int IdQuestion { get; set; }
}

Loading…
Cancel
Save