fix : harmonisation ApiById

Multiplayer_Php
Jeremy DUCOURTHIAL 1 year ago
parent ca2f9f36a8
commit bf218310f3

@ -46,7 +46,7 @@ namespace Blazor.Pages.Questions
protected override async Task OnInitializedAsync()
{
var response = Http.GetFromJsonAsync<Chapter[]>(API.API_URL + "chapters/" + API.TOKEN).Result;
var response = Http.GetFromJsonAsync<Chapter[]>(API.API_URL + "all/chapters/" + API.TOKEN + "/1").Result;
if (response == null) chapters = new List<Chapter>();
else chapters = new List<Chapter>(response);

@ -22,7 +22,7 @@ namespace Blazor.Pages.Questions
protected override async Task OnInitializedAsync()
{
var response = Http.GetFromJsonAsync<Question[]>(API.API_URL + "questions/" + API.TOKEN).Result;
var response = Http.GetFromJsonAsync<Question[]>(API.API_URL + "questions/" + QuestionId + "/" + API.TOKEN).Result;
questions = new List<Question>(response);
question = questions.Find(q => q.Id == QuestionId);

@ -53,20 +53,18 @@ namespace Blazor.Pages.Questions
protected override async Task OnInitializedAsync()
{
var response = Http.GetFromJsonAsync<Chapter[]>(API.API_URL + "chapters/" + API.TOKEN).Result;
var response = Http.GetFromJsonAsync<Chapter[]>(API.API_URL + "all/chapters/" + API.TOKEN + "/1").Result;
if (response == null) chapters = new List<Chapter>();
else chapters = new List<Chapter>(response);
answers = new();
checkboxs = new();
var resp = Http.GetFromJsonAsync<Question[]>(API.API_URL + "questions/" + API.TOKEN).Result;
var resp = Http.GetFromJsonAsync<Question[]>(API.API_URL + "questions/" + Id + "/" + API.TOKEN).Result;
questions = new List<Question>(resp);
question = questions.Find(q => q.Id == Id);
IEnumerable<Question> foundQuestions = questions.Where(q => q.Id == Id);
foreach (var q in foundQuestions)
foreach (var q in questions)
{
answers.Add(new Answer(q.A_id, q.A_content, q.Id));
checkboxs.Add(new Checkbox(q.A_id,false));

@ -27,10 +27,8 @@ namespace Blazor.Services
public async Task<Chapter> GetById(int id)
{
// Get the current data
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);
var currentData = _http.GetFromJsonAsync<List<Chapter>>(API.API_URL + "chapters/" + id + "/" + API.TOKEN).Result;
var chapter = currentData[0];
// Check if chapter exist
if (chapter == null)
@ -134,10 +132,8 @@ namespace Blazor.Services
public async Task<Administrator> GetAdminById(int id)
{
// Get the current data
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);
var currentData = _http.GetFromJsonAsync<List<Administrator>>(API.API_URL + "administrators/" + id + "/" + API.TOKEN).Result;
var admin = currentData[0];
// Check if admin exist
if (admin == null)
@ -227,7 +223,7 @@ namespace Blazor.Services
public async Task<Question> GetQuestionById(int id)
{
// Get the current data
var currentData = _http.GetFromJsonAsync<List<Question>>(API.API_URL+"questions/"+API.TOKEN).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);
@ -336,10 +332,8 @@ namespace Blazor.Services
public async Task<Player> GetPlayerById(int id)
{
// Get the current data
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);
var currentData = _http.GetFromJsonAsync<List<Player>>(API.API_URL + "players/" + id + "/" + API.TOKEN).Result;
var player = currentData[0];
// Check if player exist
if (player == null)
@ -428,10 +422,7 @@ namespace Blazor.Services
public async Task<Answer> GetAnswerByIdQuestion(int id)
{
// Get the current data
var currentData = _http.GetFromJsonAsync<List<Answer>>(API.API_URL + "answer/" + API.TOKEN).Result;
// Get the question int the list
var answer = currentData.FirstOrDefault(w => w.Id == id);
var answer = _http.GetFromJsonAsync<Answer>(API.API_URL + "answer/" + id + "/" + API.TOKEN).Result;
// Check if question exist
if (answer == null)

Loading…
Cancel
Save