|
|
|
@ -9,7 +9,7 @@ namespace Blazor.Pages.Questions
|
|
|
|
|
{
|
|
|
|
|
public partial class AddQuestion
|
|
|
|
|
{
|
|
|
|
|
private QuestionModel questionModel = new();
|
|
|
|
|
private QuestionModel? questionModel;
|
|
|
|
|
|
|
|
|
|
public List<Chapter> chapters = new();
|
|
|
|
|
|
|
|
|
@ -50,12 +50,13 @@ namespace Blazor.Pages.Questions
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
|
|
|
|
var response = Http.GetFromJsonAsync<Chapter[]>(API.API_URL + "chapters/" + API.TOKEN).Result;
|
|
|
|
|
|
|
|
|
|
chapters = new List<Chapter>(response);
|
|
|
|
|
if (response == null) chapters = new List<Chapter>();
|
|
|
|
|
else chapters = new List<Chapter>(response);
|
|
|
|
|
}
|
|
|
|
|
private async void HandleValidSubmit()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (questionModel != null)
|
|
|
|
|
{
|
|
|
|
|
await DataService.Add(questionModel);
|
|
|
|
|
|
|
|
|
|
var formData = new List<KeyValuePair<string, string>>();
|
|
|
|
@ -63,7 +64,7 @@ namespace Blazor.Pages.Questions
|
|
|
|
|
formData.Add(new KeyValuePair<string, string>("idchapter", questionModel.IdChapter.ToString()));
|
|
|
|
|
foreach (var answerModel in answerModels)
|
|
|
|
|
{
|
|
|
|
|
formData.Add(new KeyValuePair<string, string>($"answercontent{answerModel.Id+1}", answerModel.Content));
|
|
|
|
|
formData.Add(new KeyValuePair<string, string>($"answercontent{answerModel.Id + 1}", answerModel.Content));
|
|
|
|
|
}
|
|
|
|
|
foreach (var checkbox in checkboxs)
|
|
|
|
|
{
|
|
|
|
@ -77,7 +78,7 @@ namespace Blazor.Pages.Questions
|
|
|
|
|
|
|
|
|
|
var formContent = new FormUrlEncodedContent(formData);
|
|
|
|
|
|
|
|
|
|
string apiUri = API.API_URL+"add/question/"+API.TOKEN;
|
|
|
|
|
string apiUri = API.API_URL + "add/question/" + API.TOKEN;
|
|
|
|
|
|
|
|
|
|
using (var httpClient = new HttpClient())
|
|
|
|
|
{
|
|
|
|
@ -96,4 +97,5 @@ namespace Blazor.Pages.Questions
|
|
|
|
|
NavigationManager.NavigateTo("questions");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|