|
|
|
@ -4,6 +4,8 @@ using Microsoft.AspNetCore.Components;
|
|
|
|
|
using Blazor.Models;
|
|
|
|
|
using Blazor.Services;
|
|
|
|
|
using Blazor.Pages.Admins;
|
|
|
|
|
using Blazor.ViewClasses;
|
|
|
|
|
using static System.Net.WebRequestMethods;
|
|
|
|
|
|
|
|
|
|
namespace Blazor.Pages.Questions
|
|
|
|
|
{
|
|
|
|
@ -11,27 +13,72 @@ namespace Blazor.Pages.Questions
|
|
|
|
|
{
|
|
|
|
|
private QuestionModel questionModel = new();
|
|
|
|
|
|
|
|
|
|
public List<Chapter> chapters;
|
|
|
|
|
|
|
|
|
|
private List<AnswerModel> answerModels;
|
|
|
|
|
|
|
|
|
|
public List<Checkbox> checkboxs;
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
|
public IDataService DataService { get; set; }
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
|
public HttpClient Http { get; set; }
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
|
public NavigationManager NavigationManager { get; set; }
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
|
public ILogger<AddAdministrator> Logger { get; set; }
|
|
|
|
|
public class Checkbox
|
|
|
|
|
{
|
|
|
|
|
public int Id { get; set; }
|
|
|
|
|
public bool IsCorrect { get; set; }
|
|
|
|
|
|
|
|
|
|
public Checkbox(int id) { id = Id; IsCorrect = false; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
|
|
|
|
answerModels = new();
|
|
|
|
|
checkboxs = new();
|
|
|
|
|
for(int i = 0; i < 4; i++)
|
|
|
|
|
{
|
|
|
|
|
answerModels.Add(new AnswerModel(i));
|
|
|
|
|
checkboxs.Add(new Checkbox(i));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
chapters = new List<Chapter>(response);
|
|
|
|
|
}
|
|
|
|
|
private async void HandleValidSubmit()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
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>($"answercontent{i + 1}", answerModels[i].Content));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
formData.Add(new KeyValuePair<string, string>("idanswergood", questionModel.IdAnswerGood.ToString()));
|
|
|
|
|
|
|
|
|
|
var formContent = new FormUrlEncodedContent(formData);
|
|
|
|
|
|
|
|
|
|
string apiUri = "https://trusting-panini.87-106-126-109.plesk.page/api/add/administrator/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO";
|
|
|
|
|
string apiUri = "https://trusting-panini.87-106-126-109.plesk.page/api/add/question/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO";
|
|
|
|
|
|
|
|
|
|
using (var httpClient = new HttpClient())
|
|
|
|
|
{
|
|
|
|
@ -47,9 +94,7 @@ namespace Blazor.Pages.Questions
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logger.LogInformation("Admin '{administratorsModelName}' added", questionModel.Content);
|
|
|
|
|
|
|
|
|
|
NavigationManager.NavigateTo("administrators");
|
|
|
|
|
NavigationManager.NavigateTo("questions");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|