feat : ajouter question

Multiplayer_Php
Maxence GUITARD 1 year ago
commit f846db17c1

3
.gitignore vendored

@ -819,8 +819,9 @@ replay_pid*
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
# config ignore to not stock password on the git (:
# config ignore to not stock password on the git (: neither the Token of the API
/Website/usages/Config_DB.php
/Blazor/Blazor/Pages/API.cs
### DotnetCore ###
# .NET Core build folders

@ -1,13 +0,0 @@
namespace Blazor.Data
{
public class WeatherForecast
{
public DateOnly Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string? Summary { get; set; }
}
}

@ -1,20 +0,0 @@
namespace Blazor.Data
{
public class WeatherForecastService
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
public Task<WeatherForecast[]> GetForecastAsync(DateOnly startDate)
{
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = startDate.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
}).ToArray());
}
}
}

@ -20,7 +20,7 @@ namespace Blazor.Modals
//private Chapter chapter = new Chapter();
//protected override async Task OnInitializedAsync()
//{
// // Get the chapter
// chapter = await DataService.GetById(Id);
//}

@ -0,0 +1,7 @@
namespace Blazor.Pages;
public static class API
{
public static string TOKEN = "qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO"; //ASK IF YOU WANT THOSE ACCESS
public static string API_URL = "https://trusting-panini.87-106-126-109.plesk.page/api/"; //ASK IF YOU WANT THOSE ACCESS
}

@ -1,6 +1,4 @@
using Blazored.LocalStorage;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components;
using Blazor.Models;
using Blazor.Services;
@ -20,19 +18,17 @@ namespace Blazor.Pages.Admins
public ILogger<AddAdministrator> Logger { get; set; }
private async void HandleValidSubmit()
private async Task HandleValidSubmit()
{
administratorModel.HashPassword(administratorModel.HashedPassword);
//await DataService.Add(administratorModel);
var formData = new List<KeyValuePair<string, string>>();
formData.Add(new KeyValuePair<string, string>("username", administratorModel.Username));
formData.Add(new KeyValuePair<string, string>("password", administratorModel.HashedPassword));
var formContent = new FormUrlEncodedContent(formData);
string apiUri = "https://trusting-panini.87-106-126-109.plesk.page/api/add/administrator/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO";
string apiUri = API.API_URL+"add/administrator/"+API.TOKEN;
using (var httpClient = new HttpClient())
{

@ -2,14 +2,10 @@
using Blazorise.DataGrid;
using Blazor.ViewClasses;
using Blazor.Modals;
using Blazor.Models;
using Blazored.LocalStorage;
using Blazored.Modal.Services;
using Blazor.Modals;
using Blazor.Services;
using Blazored.Modal;
using Blazored.Modal;
using Blazor.Pages.Chapters;
namespace Blazor.Pages.Admins;
@ -43,9 +39,7 @@ public partial class Administrators
return;
}
// When you use a real API, we use this follow code
//var response = await Http.GetFromJsonAsync<ChaptersModel[]>( $"https://trusting-panini.87-106-126-109.plesk.page/api/administrators?page={e.Page}&pageSize={e.PageSize}" );
var response = Http.GetFromJsonAsync<Administrator[]>($"https://trusting-panini.87-106-126-109.plesk.page/api/administrators/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO").Result;
var response = Http.GetFromJsonAsync<Administrator[]>(API.API_URL+"administrators/"+API.TOKEN).Result;
if (!e.CancellationToken.IsCancellationRequested)
{
@ -54,31 +48,12 @@ public partial class Administrators
var currentData = await LocalStorage.GetItemAsync<Administrator[]>("data");
if (currentData == null || currentData.Length != administrators.Count)
{
var originalData = Http.GetFromJsonAsync<Administrator[]>($"https://trusting-panini.87-106-126-109.plesk.page/api/administrators/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO").Result;
var originalData = Http.GetFromJsonAsync<Administrator[]>(API.API_URL + "administrators/" + API.TOKEN).Result;
await LocalStorage.SetItemAsync("data", originalData);
}
}
}
//protected override async Task OnAfterRenderAsync(bool firstRender)
//{
// // Do not treat this action if is not the first render
// if (!firstRender)
// {
// return;
// }
// var currentData = await LocalStorage.GetItemAsync<AdministratorModel[]>("data");
// // Check if data exist in the local storage
// if (currentData == null)
// {
// // 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<AdministratorModel[]>($"https://trusting-panini.87-106-126-109.plesk.page/api/administrators").Result;
// await LocalStorage.SetItemAsync("data", originalData);
// }
//}
private async void OnDelete(int id)
{
var parameters = new ModalParameters();
@ -92,7 +67,7 @@ public partial class Administrators
return;
}
string apiUri = "https://trusting-panini.87-106-126-109.plesk.page/api/delete/administrator/" + id + "/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO";
string apiUri = API.API_URL +"delete/administrator/" + id + "/" + API.TOKEN;
using (var httpClient = new HttpClient())
{
@ -107,9 +82,7 @@ public partial class Administrators
var errorResponse = await response.Content.ReadAsStringAsync();
}
}
//await DataService.Delete(id);
// Reload the page
NavigationManager.NavigateTo("administrators", true);
}
}

@ -31,7 +31,6 @@ namespace Blazor.Pages.Admins
var administrator = await DataService.GetAdminById(Id);
OldAdminName = administrator.Username;
// Set the model with the admin
administratorModel = new AdministratorModel
{
Id = administrator.Id,
@ -40,18 +39,17 @@ namespace Blazor.Pages.Admins
};
}
private async void HandleValidSubmit()
private async Task HandleValidSubmit()
{
administratorModel.HashPassword(administratorModel.HashedPassword);
//await DataService.Update(Id, administratorModel);
var formData = new List<KeyValuePair<string, string>>();
formData.Add(new KeyValuePair<string, string>("username", administratorModel.Username));
formData.Add(new KeyValuePair<string, string>("password", administratorModel.HashedPassword));
var formContent = new FormUrlEncodedContent(formData);
string apiUri = "https://trusting-panini.87-106-126-109.plesk.page/api/update/administrator/" + administratorModel.Id + "/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO";
string apiUri = API.API_URL+"update/administrator/" + administratorModel.Id + "/" + API.TOKEN;
using (var httpClient = new HttpClient())
{
@ -67,7 +65,6 @@ namespace Blazor.Pages.Admins
}
}
Logger.LogInformation("Admin '{OldAdminModelName}' edited in '{NewAdminModelName}'",OldAdminName,administratorModel.Username);
NavigationManager.NavigateTo("administrators");

@ -19,17 +19,15 @@ public partial class AddChapter
private async void HandleValidSubmit()
private async Task HandleValidSubmit()
{
//await DataService.Add(chapterModel);
var formData = new List<KeyValuePair<string, string>>();
formData.Add(new KeyValuePair<string, string>("name", chapterModel.Name));
var formContent = new FormUrlEncodedContent(formData);
string apiUri = "https://trusting-panini.87-106-126-109.plesk.page/api/add/chapter/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO";
string apiUri = API.API_URL+"add/chapter/"+API.TOKEN;
using (var httpClient = new HttpClient())
{

@ -2,18 +2,13 @@
using Blazor.Services;
using Blazored.Modal.Services;
using Blazor.ViewClasses;
using System.Text;
using Microsoft.JSInterop;
using Microsoft.AspNetCore.Components;
using Blazorise.DataGrid;
using ChoETL;
using Microsoft.AspNetCore.Components.Forms;
using Blazor.Modals;
using Blazored.Modal;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Blazor.Models;
namespace Blazor.Pages.Chapters;
public partial class Chapters
{
public List<Chapter> chapters;
@ -53,7 +48,7 @@ public partial class Chapters
return;
}
string apiUri = "https://trusting-panini.87-106-126-109.plesk.page/api/delete/chapter/" + id + "/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO";
string apiUri = API.API_URL+"delete/chapter/" + id + "/" + API.TOKEN;
using (var httpClient = new HttpClient())
{
@ -68,23 +63,9 @@ public partial class Chapters
var errorResponse = await response.Content.ReadAsStringAsync();
}
}
// /api/delete/player/ +chapterid
//await DataService.Delete(id);
// Reload the page
NavigationManager.NavigateTo("chapters", true);
}
//protected override async Task OnAfterRenderAsync(bool firstRender)
//{
// if (!firstRender)
// {
// return;
// }
//}
private async Task OnReadData(DataGridReadDataEventArgs<Chapter> e)
{
if (e.CancellationToken.IsCancellationRequested)
@ -92,7 +73,7 @@ public partial class Chapters
return;
}
var response = Http.GetFromJsonAsync<Chapter[]>($"https://trusting-panini.87-106-126-109.plesk.page/api/chapters/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO").Result;
var response = Http.GetFromJsonAsync<Chapter[]>(API.API_URL+"chapters/"+API.TOKEN).Result;
if (!e.CancellationToken.IsCancellationRequested)
{
@ -101,7 +82,7 @@ public partial class Chapters
var currentData = await LocalStorage.GetItemAsync<Chapter[]>("data");
if (currentData == null || currentData.Length != chapters.Count)
{
var originalData = Http.GetFromJsonAsync<Chapter[]>($"https://trusting-panini.87-106-126-109.plesk.page/api/chapters/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO").Result;
var originalData = Http.GetFromJsonAsync<Chapter[]>(API.API_URL+"chapters/"+API.TOKEN).Result;
await LocalStorage.SetItemAsync("data", originalData);
}
}

@ -30,7 +30,6 @@ public partial class EditChapter
var chapter = await DataService.GetById(Id);
OldChapterName = chapter.Name;
// Set the model with the chapter
chapterModel = new ChapterModel
{
Id = chapter.Id,
@ -38,9 +37,8 @@ public partial class EditChapter
};
}
private async void HandleValidSubmit()
private async Task HandleValidSubmit()
{
//await DataService.Update(Id, chapterModel);
var formData = new List<KeyValuePair<string, string>>();
formData.Add(new KeyValuePair<string, string>("name", chapterModel.Name));
@ -48,7 +46,7 @@ public partial class EditChapter
var formContent = new FormUrlEncodedContent(formData);
string apiUri = "https://trusting-panini.87-106-126-109.plesk.page/api/update/chapter/" + chapterModel.Id + "/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO";
string apiUri = API.API_URL+"update/chapter/" + chapterModel.Id + "/" + API.TOKEN;
using (var httpClient = new HttpClient())
{

@ -2,26 +2,19 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Diagnostics;
namespace Blazor.Pages
namespace Blazor.Pages;
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
public string? RequestId { get; set; }
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
private readonly ILogger<ErrorModel> _logger;
public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
}
public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}
}

@ -15,19 +15,17 @@ namespace Blazor.Pages.Players
public NavigationManager NavigationManager { get; set; }
private async void HandleValidSubmit()
private async Task HandleValidSubmit()
{
playerModel.HashPassword(playerModel.HashedPassword);
//await DataService.Add(playerModel);
var formData = new List<KeyValuePair<string, string>>();
formData.Add(new KeyValuePair<string, string>("nickname", playerModel.Nickname));
formData.Add(new KeyValuePair<string, string>("password", playerModel.HashedPassword));
var formContent = new FormUrlEncodedContent(formData);
string apiUri = "https://trusting-panini.87-106-126-109.plesk.page/api/add/player/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO";
string apiUri =API.API_URL+"add/player/"+API.TOKEN;
using (var httpClient = new HttpClient())
{

@ -1,8 +1,6 @@
using Blazor.Models;
using Blazor.Services;
using ChoETL;
using Microsoft.AspNetCore.Components;
using System.Runtime.InteropServices;
namespace Blazor.Pages.Players
{
@ -36,19 +34,17 @@ namespace Blazor.Pages.Players
};
}
private async void HandleValidSubmit()
private async Task HandleValidSubmit()
{
playerModel.HashPassword(playerModel.HashedPassword);
//await DataService.Update(Id, playerModel);
var formData = new List<KeyValuePair<string, string>>();
formData.Add(new KeyValuePair<string, string>("nickname", playerModel.Nickname));
formData.Add(new KeyValuePair<string, string>("password", playerModel.HashedPassword));
var formContent = new FormUrlEncodedContent(formData);
string apiUri = "https://trusting-panini.87-106-126-109.plesk.page/api/update/player/" + playerModel.Id + "/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO";
string apiUri = API.API_URL+"update/player/" + playerModel.Id + "/" + API.TOKEN;
using (var httpClient = new HttpClient())
{

@ -2,16 +2,11 @@
using Blazor.Services;
using Blazored.Modal.Services;
using Blazor.ViewClasses;
using System.Text;
using Microsoft.JSInterop;
using Microsoft.AspNetCore.Components;
using Blazorise.DataGrid;
using ChoETL;
using Microsoft.AspNetCore.Components.Forms;
using Blazor.Modals;
using Blazored.Modal;
using Blazor.Pages.Admins;
using Blazor.Pages.Chapters;
namespace Blazor.Pages.Players;
@ -53,7 +48,7 @@ public partial class Players
return;
}
string apiUri = "https://trusting-panini.87-106-126-109.plesk.page/api/delete/player/" + id + "/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO";
string apiUri = API.API_URL+"delete/player/" + id + "/" + API.TOKEN;
using (var httpClient = new HttpClient())
{
@ -68,23 +63,9 @@ public partial class Players
var errorResponse = await response.Content.ReadAsStringAsync();
}
}
//await DataService.Delete(id);
// Reload the page
NavigationManager.NavigateTo("Players", 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<Player> e)
{
if (e.CancellationToken.IsCancellationRequested)
@ -92,7 +73,7 @@ public partial class Players
return;
}
var response = Http.GetFromJsonAsync<Player[]>($"https://trusting-panini.87-106-126-109.plesk.page/api/players/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO").Result;
var response = Http.GetFromJsonAsync<Player[]>(API.API_URL+"players/"+API.TOKEN).Result;
if (!e.CancellationToken.IsCancellationRequested)
{
@ -101,7 +82,7 @@ public partial class Players
var currentData = await LocalStorage.GetItemAsync<Player[]>("data");
if (currentData == null || currentData.Length != players.Count)
{
var originalData = Http.GetFromJsonAsync<Player[]>($"https://trusting-panini.87-106-126-109.plesk.page/api/players/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO").Result;
var originalData = Http.GetFromJsonAsync<Player[]>(API.API_URL+"players/"+API.TOKEN).Result;
await LocalStorage.SetItemAsync("data", originalData);
}
}

@ -1,6 +1,4 @@
using Blazored.LocalStorage;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components;
using Blazor.Models;
using Blazor.Services;
using Blazor.Pages.Admins;
@ -78,7 +76,7 @@ namespace Blazor.Pages.Questions
var formContent = new FormUrlEncodedContent(formData);
string apiUri = "https://trusting-panini.87-106-126-109.plesk.page/api/add/question/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO";
string apiUri = API.API_URL+"add/administrator/"+API.TOKEN;
using (var httpClient = new HttpClient())
{

@ -26,7 +26,7 @@ namespace Blazor.Pages.Questions
public ILogger<EditQuestion> Logger { get; set; }
private async void HandleValidSubmit()
private async Task HandleValidSubmit()
{
await DataService.Update(Id, questionModel);
@ -35,7 +35,7 @@ namespace Blazor.Pages.Questions
var formContent = new FormUrlEncodedContent(formData);
string apiUri = "https://trusting-panini.87-106-126-109.plesk.page/api/update/questions/" + questionModel.Id + "/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO";
string apiUri = API.API_URL+"/update/questions/" + questionModel.Id + "/" + API.TOKEN;
using (var httpClient = new HttpClient())
{

@ -2,7 +2,7 @@
@using Blazor.ViewClasses;
@using Blazorise.DataGrid
@using Blazored.Modal;
<h3>Chapters</h3>
<h3>Questions</h3>
<div>
<NavLink class="btn btn-primary" href="addQuestion" Match="NavLinkMatch.All">
@ -21,13 +21,16 @@
PageSize="10"
ShowPager
Responsive>
<DataGridColumn TItem="Question" Field="@nameof(Question.Id)" Caption="#" />
<DataGridColumn TItem="Question" Field="@nameof(Question.Content)" Caption="Display content" />
<DataGridColumn TItem="Question" Field="@nameof(Question.Q_id)" Caption="#" />
<DataGridColumn TItem="Question" Field="@nameof(Question.Q_content)" Caption="Display content" />
<DataGridColumn TItem="Question" Field="@nameof(Question.Id)" Caption="Action">
<DataGridColumn TItem="Question" Field="@nameof(Question.Q_id)" Caption="Action">
<DisplayTemplate>
<a href="editQuestion/@(context.Id)" class="btn btn-primary"><i class="fa fa-edit"></i> Editer</a>
<button type="button" class="btn btn-primary" @onclick="() => OnDelete(context.Id)"><i class="fa fa-trash"></i> Supprimer</button>
<a href="editQuestion/@(context.Q_id)" class="btn btn-primary"><i class="fa fa-edit"></i> Editer</a>
<button type="button" class="btn btn-primary" @onclick="() => OnDelete(context.Q_id)"><i class="fa fa-trash"></i> Supprimer</button>
</DisplayTemplate>
</DataGridColumn>
</DataGrid>
<script src="Questions/Questions.razor.js"></script>

@ -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);

@ -6,6 +6,7 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Host</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="~/" />
@ -28,7 +29,7 @@
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
<script src="Pages/Chapters/Chapters.razor.js"></script>
<script src="Pages/Questions/Questions.razor.js"></script>
<script src="_framework/blazor.server.js"></script>
</body>
</html>

@ -1,12 +1,16 @@
<html>
<body>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Layout</title>
</head>
<body>
<link href="_content/Blazored.Modal/blazored-modal.css" rel="stylesheet" />
<script src="_content/Blazored.Modal/blazored.modal.js"></script>
<script src="_framework/blazor.server.js"></script>
<script src="Pages/Chapters/Chapters.razor.js"></script>
<script src="Pages/Questions/Questions.razor.js"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css">

@ -1,20 +1,16 @@
using Blazor.Data;
using Blazor.Services;
using Blazored.LocalStorage;
using Blazorise;
using Blazorise.Bootstrap;
using Blazorise.Icons.FontAwesome;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Blazored.Modal;
using Microsoft.Extensions.Logging;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddSingleton<WeatherForecastService>();
builder.Services.AddHttpClient();
builder.Services
@ -56,3 +52,4 @@ app.MapBlazorHub();
app.MapFallbackToPage("/_Host");
app.Run();

@ -1,4 +1,5 @@
using Blazor.Models;
using Blazor.Pages;
using Blazor.ViewClasses;
using Blazored.LocalStorage;
using Microsoft.AspNetCore.Components;
@ -12,24 +13,21 @@ namespace Blazor.Services
private readonly HttpClient _http;
private readonly ILocalStorageService _localStorage;
private readonly NavigationManager _navigationManager;
private readonly IWebHostEnvironment _webHostEnvironment;
public DataLocalService(
ILocalStorageService localStorage,
HttpClient http,
IWebHostEnvironment webHostEnvironment,
NavigationManager navigationManager)
{
_localStorage = localStorage;
_http = http;
_webHostEnvironment = webHostEnvironment;
_navigationManager = navigationManager;
}
public async Task<Chapter> GetById(int id)
{
// Get the current data
var currentData = _http.GetFromJsonAsync<List<Chapter>>($"https://trusting-panini.87-106-126-109.plesk.page/api/chapters/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO").Result;
var currentData = _http.GetFromJsonAsync<List<Chapter>>(API.API_URL+"chapters/"+API.TOKEN).Result;
// Get the chapter int the list
var chapter = currentData.FirstOrDefault(w => w.Id == id);
@ -89,7 +87,7 @@ namespace Blazor.Services
{
// Get the current data
//var currentData = await _localStorage.GetItemAsync<List<Chapter>>("data");
var currentData = _http.GetFromJsonAsync<List<Chapter>>($"https://trusting-panini.87-106-126-109.plesk.page/api/chapters/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO").Result;
var currentData = _http.GetFromJsonAsync<List<Chapter>>(API.API_URL+"chapters/"+API.TOKEN).Result;
// Get the chapter int the list
var chapter = currentData.FirstOrDefault(w => w.Id == id);
@ -136,7 +134,7 @@ namespace Blazor.Services
public async Task<Administrator> GetAdminById(int id)
{
// Get the current data
var currentData = _http.GetFromJsonAsync<List<Administrator>>($"https://trusting-panini.87-106-126-109.plesk.page/api/administrators/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO").Result;
var currentData = _http.GetFromJsonAsync<List<Administrator>>(API.API_URL+"administrators/"+API.TOKEN).Result;
// Get the admin int the list
var admin = currentData.FirstOrDefault(w => w.Id == id);
@ -229,10 +227,10 @@ namespace Blazor.Services
public async Task<Question> GetQuestionById(int id)
{
// Get the current data
var currentData = _http.GetFromJsonAsync<List<Question>>($"https://trusting-panini.87-106-126-109.plesk.page/api/questions/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO").Result;
var currentData = _http.GetFromJsonAsync<List<Question>>(API.API_URL+"questions/"+API.TOKEN).Result;
// Get the question int the list
var question = currentData.FirstOrDefault(w => w.Id == id);
var question = currentData.FirstOrDefault(w => w.Q_id == id);
// Check if question exist
if (question == null)
@ -249,7 +247,7 @@ namespace Blazor.Services
var currentData = await _localStorage.GetItemAsync<List<Question>>("data");
// Get the admin int the list
var question = currentData.FirstOrDefault(w => w.Id == id);
var question = currentData.FirstOrDefault(w => w.Q_id == id);
// Check if admin exist
if (question == null)
@ -258,7 +256,7 @@ namespace Blazor.Services
}
// Modify the content of the adminnistrator
question.Content = model.Content;
question.Q_content = model.Content;
// Save the data
await _localStorage.SetItemAsync("data", currentData);
@ -270,13 +268,13 @@ namespace Blazor.Services
var currentData = await _localStorage.GetItemAsync<List<Question>>("data");
// Simulate the Id
model.Id = currentData.Max(s => s.Id) + 1;
model.Id = currentData.Max(s => s.Q_id) + 1;
// Add the admin to the current data
currentData.Add(new Question
{
Id = model.Id,
Content = model.Content
Q_id = model.Id,
Q_content = model.Content
});
@ -321,7 +319,7 @@ namespace Blazor.Services
public async Task<Player> GetPlayerById(int id)
{
// Get the current data
var currentData = _http.GetFromJsonAsync<List<Player>>($"https://trusting-panini.87-106-126-109.plesk.page/api/players/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO").Result;
var currentData = _http.GetFromJsonAsync<List<Player>>(API.API_URL+"players/"+API.TOKEN).Result;
// Get the player in the list
var player = currentData.FirstOrDefault(w => w.Id == id);

@ -2,8 +2,8 @@
public class Question
{
public int Id { get; set; }
public string Content { get; set; }
public int Q_id { get; set; }
public string Q_content { get; set; }
public int IdChapter { get; set; }
public int IdAnswerGood { get; set; }
public int Difficulty { get; set; }

Loading…
Cancel
Save