Page gestion quiz + ajout quiz admin (ne pas aller sur les page elle font planter le site pour l'instant)
parent
bfc54acd19
commit
2f32bb42ee
@ -0,0 +1,58 @@
|
||||
@using WF_WebAdmin.Model;
|
||||
|
||||
@page "/add"
|
||||
|
||||
<h3>Ajouter un quiz</h3>
|
||||
|
||||
|
||||
<EditForm Model="@QuizModel" OnValidSubmit="@HandleValidSubmit">
|
||||
<DataAnnotationsValidator />
|
||||
<ValidationSummary />
|
||||
|
||||
<p>
|
||||
<label for="display-quest">
|
||||
Question:
|
||||
<InputText id="display-quest" @bind-Value="QuizModel.Question" />
|
||||
</label>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="display-a">
|
||||
Réponse A:
|
||||
<InputText id="display-a" @bind-Value="QuizModel.AnswerA" />
|
||||
</label>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="display-b">
|
||||
Réponse B:
|
||||
<InputText id="display-b" @bind-Value="QuizModel.AnswerB" />
|
||||
</label>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="display-c">
|
||||
Réponse B:
|
||||
<InputText id="display-c" @bind-Value="QuizModel.AnswerB" />
|
||||
</label>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="display-d">
|
||||
Réponse B:
|
||||
<InputText id="display-d" @bind-Value="QuizModel.AnswerB" />
|
||||
</label>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="ra">
|
||||
Bonne réponse:
|
||||
<input type="radio" @onchange="@(e => OnCAwnserChange("A", e.Value))" /> A
|
||||
<input type="radio" @onchange="@(e => OnCAwnserChange("B", e.Value))" /> B
|
||||
<input type="radio" @onchange="@(e => OnCAwnserChange("C", e.Value))" /> C
|
||||
<input type="radio" @onchange="@(e => OnCAwnserChange("D", e.Value))" /> D
|
||||
</label>
|
||||
</p>
|
||||
|
||||
<button type="submit">Submit</button>
|
||||
</EditForm>
|
@ -0,0 +1,69 @@
|
||||
@using WF_WebAdmin.Model
|
||||
@page "/modifquiz"
|
||||
|
||||
<PageTitle>Gestion des quiz</PageTitle>
|
||||
|
||||
<h3>Gestion des quiz</h3>
|
||||
|
||||
<div>
|
||||
<NavLink class="btn btn-primary" href="Add" Match="NavLinkMatch.All">
|
||||
<i class="fa fa-plus"></i> Ajouter
|
||||
</NavLink>
|
||||
</div>
|
||||
|
||||
<DataGrid TItem="Quiz"
|
||||
Data="@quiz"
|
||||
PageSize="@MaxValue"
|
||||
ReadData="@OnReadData"
|
||||
TotalItems="@totalItem"
|
||||
ShowPager
|
||||
Responsive>
|
||||
|
||||
<DataGridColumn TItem="Quiz" Field="@nameof(Quiz.Id)" Caption="Id"/>
|
||||
<DataGridColumn TItem="Quiz" Field="@nameof(Quiz.Question)" Caption="Rep A" />
|
||||
<DataGridColumn TItem="Quiz" Field="@nameof(Quiz.AnswerA)" Caption="Rep A" />
|
||||
<DataGridColumn TItem="Quiz" Field="@nameof(Quiz.AnswerB)" Caption="Rep B" />
|
||||
<DataGridColumn TItem="Quiz" Field="@nameof(Quiz.AnswerC)" Caption="Rep C" />
|
||||
<DataGridColumn TItem="Quiz" Field="@nameof(Quiz.AnswerD)" Caption="Rep D" />
|
||||
<DataGridColumn TItem="Quiz" Field="@nameof(Quiz.CAnswer)" Caption="Bonne Rep" />
|
||||
<DataGridColumn TItem="Quiz" Field="@nameof(Quiz.Id)" Caption="Action">
|
||||
<DisplayTemplate>
|
||||
<button type="button" class="btn btn-primary" @onclick="() => OnEditButtonClicked(context)"><i class="fa fa-edit"></i> Editer</button>
|
||||
<button type="button" class="btn btn-primary" @onclick="() => OnDelete(context)"><i class="fa fa-trash"></i> Supprimer</button>
|
||||
</DisplayTemplate>
|
||||
</DataGridColumn>
|
||||
</DataGrid>
|
||||
|
||||
@if (showEditQuiz && selectedQuiz != null)
|
||||
{
|
||||
<div class="divPopup">
|
||||
<div class="contentPopup">
|
||||
<p>Modifier les informations de l'utilisateur :</p>
|
||||
<label>Question:</label>
|
||||
<input type="text" @bind="selectedQuiz.Question"/>
|
||||
<label>Rep A:</label>
|
||||
<input type="text" @bind="selectedQuiz.AnswerA" />
|
||||
<label>Rep B:</label>
|
||||
<input type="text" @bind="selectedQuiz.AnswerB" />
|
||||
<label>Rep C:</label>
|
||||
<input type="text" @bind="selectedQuiz.AnswerC" />
|
||||
<label>Rep D:</label>
|
||||
<input type="text" @bind="selectedQuiz.AnswerD" />
|
||||
<label>Bonne Rep:</label>
|
||||
<input type="text" @bind="selectedQuiz.CAnswer" />
|
||||
<button @onclick="EditQuiz">Sauvegarder </button>
|
||||
<button @onclick="ClosePopup">Annuler</button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (showPopupDelete)
|
||||
{
|
||||
<div class="divPopup">
|
||||
<div class="contentPopup">
|
||||
<p>Êtes-vous sûr de vouloir supprimer ce quiz ?</p>
|
||||
<button @onclick="RemoveQuote">Confirmer</button>
|
||||
<button @onclick="ClosePopup">Annuler</button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
using Blazorise.DataGrid;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using WF_WebAdmin.Model;
|
||||
using WF_WebAdmin.Service;
|
||||
|
||||
namespace WF_WebAdmin.Pages
|
||||
{
|
||||
public partial class ModifQuiz
|
||||
{
|
||||
private Quiz[] quiz;
|
||||
|
||||
private int MaxValue = 5;
|
||||
|
||||
private int totalItem;
|
||||
|
||||
private bool showEditQuiz = false;
|
||||
|
||||
private Quiz? selectedQuiz;
|
||||
|
||||
private bool showPopupDelete = false;
|
||||
|
||||
private int page = 1;
|
||||
|
||||
[Inject]
|
||||
public IQuizService QuizService { get; set; }
|
||||
|
||||
private async Task OnReadData(DataGridReadDataEventArgs<Quiz> e)
|
||||
{
|
||||
if (e.CancellationToken.IsCancellationRequested)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var response = await QuizService.getSommeQuiz(e.PageSize, e.Page);
|
||||
|
||||
if (!e.CancellationToken.IsCancellationRequested)
|
||||
{
|
||||
totalItem = await QuizService.getNbQuiz();
|
||||
quiz = response.ToArray();
|
||||
page = e.Page;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEditButtonClicked(Quiz quiz)
|
||||
{
|
||||
if (quiz == null) return;
|
||||
selectedQuiz = quiz;
|
||||
showEditQuiz = true;
|
||||
}
|
||||
|
||||
private void ClosePopup()
|
||||
{
|
||||
showEditQuiz = false;
|
||||
showPopupDelete = false;
|
||||
selectedQuiz = null;
|
||||
}
|
||||
|
||||
private async Task EditQuiz()
|
||||
{
|
||||
await QuizService.updateQuiz(selectedQuiz);
|
||||
selectedQuiz = null;
|
||||
ClosePopup();
|
||||
}
|
||||
|
||||
private void OnDelete(Quiz q)
|
||||
{
|
||||
selectedQuiz = q;
|
||||
showPopupDelete = true;
|
||||
}
|
||||
|
||||
private async void RemoveQuote()
|
||||
{
|
||||
if (selectedQuiz != null)
|
||||
{
|
||||
await QuizService.removeQuiz(selectedQuiz.Id);
|
||||
selectedQuiz = null;
|
||||
var response = await QuizService.getSommeQuiz(MaxValue, page);
|
||||
quiz = response.ToArray();
|
||||
}
|
||||
showPopupDelete= false;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue