refactor : variable name

Multiplayer_Php
Yvan CALATAYUD 1 year ago
parent 5401c208af
commit 54001d34db

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

@ -43,7 +43,7 @@ public partial class Questions
private async void OnDelete(int id) private async void OnDelete(int id)
{ {
var parameters = new ModalParameters(); 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 modal = Modal.Show<DeleteConfirmation>("Delete Confirmation", parameters);
var result = await modal.Result; var result = await modal.Result;
@ -92,21 +92,20 @@ public partial class Questions
return; 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 = Http.GetFromJsonAsync<Question[]>($"https://trusting-panini.87-106-126-109.plesk.page/api/questions/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO").Result;
var response = (await Http.GetFromJsonAsync<Question[]>($"{NavigationManager.BaseUri}fake-question.json")).Skip((e.Page - 1) * e.PageSize).Take(e.PageSize).ToList();
if (!e.CancellationToken.IsCancellationRequested) 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 questions = new List<Question>(response); // an actual data for the current page
totalQuestion = questions.Count;
var currentData = await LocalStorage.GetItemAsync<Question[]>("data"); var currentData = await LocalStorage.GetItemAsync<Question[]>("data");
// Check if data exist in the local storage // 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) // 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[]>($"https://trusting-panini.87-106-126-109.plesk.page/api/questions/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO").Result;
await LocalStorage.SetItemAsync("data", originalData); await LocalStorage.SetItemAsync("data", originalData);
} }
} }

@ -232,7 +232,7 @@ namespace Blazor.Services
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>>($"https://trusting-panini.87-106-126-109.plesk.page/api/questions/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO").Result;
// Get the question int the list // 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 // Check if question exist
if (question == null) if (question == null)
@ -249,7 +249,7 @@ namespace Blazor.Services
var currentData = await _localStorage.GetItemAsync<List<Question>>("data"); var currentData = await _localStorage.GetItemAsync<List<Question>>("data");
// Get the admin int the list // 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 // Check if admin exist
if (question == null) if (question == null)
@ -258,7 +258,7 @@ namespace Blazor.Services
} }
// Modify the content of the adminnistrator // Modify the content of the adminnistrator
question.Content = model.Content; question.Q_content = model.Content;
// Save the data // Save the data
await _localStorage.SetItemAsync("data", currentData); await _localStorage.SetItemAsync("data", currentData);
@ -270,13 +270,13 @@ namespace Blazor.Services
var currentData = await _localStorage.GetItemAsync<List<Question>>("data"); var currentData = await _localStorage.GetItemAsync<List<Question>>("data");
// Simulate the Id // 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 // Add the admin to the current data
currentData.Add(new Question currentData.Add(new Question
{ {
Id = model.Id, Q_id = model.Id,
Content = model.Content Q_content = model.Content
}); });

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

Loading…
Cancel
Save