|
|
|
@ -10,7 +10,6 @@ using ChoETL;
|
|
|
|
|
using Microsoft.AspNetCore.Components.Forms;
|
|
|
|
|
using Blazor.Modals;
|
|
|
|
|
using Blazored.Modal;
|
|
|
|
|
using Blazor.Pages.Admins;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
|
|
|
|
namespace Blazor.Pages.Questions;
|
|
|
|
@ -43,7 +42,7 @@ public partial class Questions
|
|
|
|
|
private async void OnDelete(int id)
|
|
|
|
|
{
|
|
|
|
|
var parameters = new ModalParameters();
|
|
|
|
|
parameters.Add(nameof(Question.Id), id);
|
|
|
|
|
parameters.Add(nameof(Question.Q_id), id);
|
|
|
|
|
|
|
|
|
|
var modal = Modal.Show<DeleteConfirmation>("Delete Confirmation", parameters);
|
|
|
|
|
var result = await modal.Result;
|
|
|
|
@ -53,7 +52,7 @@ public partial class Questions
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string apiUri = "https://trusting-panini.87-106-126-109.plesk.page/api/delete/question/" + id + "/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO";
|
|
|
|
|
string apiUri = API.API_URL+"delete/question/" + id + "/" + API.TOKEN;
|
|
|
|
|
|
|
|
|
|
using (var httpClient = new HttpClient())
|
|
|
|
|
{
|
|
|
|
@ -69,22 +68,9 @@ public partial class Questions
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//await DataService.Delete(id);
|
|
|
|
|
|
|
|
|
|
// Reload the page
|
|
|
|
|
NavigationManager.NavigateTo("questions", true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
|
|
|
//{
|
|
|
|
|
// // Do not treat this action if is not the first render
|
|
|
|
|
// if (!firstRender)
|
|
|
|
|
// {
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
private async Task OnReadData(DataGridReadDataEventArgs<Question> e)
|
|
|
|
|
{
|
|
|
|
|
if (e.CancellationToken.IsCancellationRequested)
|
|
|
|
@ -92,30 +78,29 @@ public partial class Questions
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// When you use a real API, we use this follow code
|
|
|
|
|
//var response = await Http.GetJsonAsync<Item[]>( $"http://my-api/api/data?page={e.Page}&pageSize={e.PageSize}" );
|
|
|
|
|
var response = (await Http.GetFromJsonAsync<Question[]>($"{NavigationManager.BaseUri}fake-question.json")).Skip((e.Page - 1) * e.PageSize).Take(e.PageSize).ToList();
|
|
|
|
|
|
|
|
|
|
var response = Http.GetFromJsonAsync<Question[]>(API.API_URL+"questions/"+API.TOKEN).Result;
|
|
|
|
|
|
|
|
|
|
if (!e.CancellationToken.IsCancellationRequested)
|
|
|
|
|
{
|
|
|
|
|
totalQuestion = (await Http.GetFromJsonAsync<List<Question>>($"{NavigationManager.BaseUri}fake-question.json")).Count;
|
|
|
|
|
questions = new List<Question>(response); // an actual data for the current page
|
|
|
|
|
totalQuestion = questions.Count;
|
|
|
|
|
var currentData = await LocalStorage.GetItemAsync<Question[]>("data");
|
|
|
|
|
|
|
|
|
|
// Check if data exist in the local storage
|
|
|
|
|
if (currentData == null)
|
|
|
|
|
if (currentData == null || currentData.Length != questions.Count)
|
|
|
|
|
{
|
|
|
|
|
// this code add in the local storage the fake data (we load the data sync for initialize the data before load the OnReadData method)
|
|
|
|
|
var originalData = Http.GetFromJsonAsync<Question[]>($"https://trusting-panini.87-106-126-109.plesk.page/api/chapters/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO").Result;
|
|
|
|
|
var originalData = Http.GetFromJsonAsync<Question[]>(API.API_URL+"chapters/"+API.TOKEN).Result;
|
|
|
|
|
await LocalStorage.SetItemAsync("data", originalData);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void Export()
|
|
|
|
|
private async Task Export()
|
|
|
|
|
{
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
HttpResponseMessage response = await Http.GetAsync("https://trusting-panini.87-106-126-109.plesk.page/api/questionsExport/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO");
|
|
|
|
|
HttpResponseMessage response = await Http.GetAsync(API.API_URL+"questionsExport/"+API.TOKEN);
|
|
|
|
|
var json = await response.Content.ReadAsStringAsync();
|
|
|
|
|
using (var jsonFile = ChoJSONReader.LoadText(json))
|
|
|
|
|
{
|
|
|
|
@ -125,8 +110,7 @@ public partial class Questions
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var sentFile = new MemoryStream(Encoding.UTF8.GetBytes(sb.ToString()));
|
|
|
|
|
|
|
|
|
|
var sentFile = new MemoryStream(Encoding.Unicode.GetBytes(sb.ToString()));
|
|
|
|
|
using (var streamRef = new DotNetStreamReference(stream: sentFile))
|
|
|
|
|
{
|
|
|
|
|
await IJSRuntime.InvokeVoidAsync("downloadFileFromStream", "data.csv", streamRef);
|
|
|
|
@ -156,7 +140,7 @@ public partial class Questions
|
|
|
|
|
formData.Add(new KeyValuePair<string, string>("answerContent4", field[5]));
|
|
|
|
|
formData.Add(new KeyValuePair<string, string>("idanswergood", field[6]));
|
|
|
|
|
|
|
|
|
|
string apiUri = "https://trusting-panini.87-106-126-109.plesk.page/api/chapters/name/"+field[1] + "/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO";
|
|
|
|
|
string apiUri = API.API_URL+"chapters/name/"+field[1] + "/" + API.TOKEN;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var response = await Http.GetAsync(apiUri);
|
|
|
|
@ -175,7 +159,7 @@ public partial class Questions
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var formContent = new FormUrlEncodedContent(formData);
|
|
|
|
|
apiUri = "https://trusting-panini.87-106-126-109.plesk.page/api/add/questions/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO";
|
|
|
|
|
apiUri = API.API_URL+"add/questions/"+API.TOKEN;
|
|
|
|
|
|
|
|
|
|
response = await Http.PostAsync(apiUri, formContent);
|
|
|
|
|
|
|
|
|
|