fin service

pull/26/head
Kevin MONDEJAR 3 months ago
parent 2f32bb42ee
commit 9d8eb2e5d5

@ -0,0 +1,8 @@
namespace WF_WebAdmin.Model
{
public class Character
{
public int id_caracter { get; set; }
public string caracter { get; set; }
}
}

@ -38,5 +38,7 @@ namespace WF_WebAdmin.Model
UserProposition = "Admin"; UserProposition = "Admin";
} }
public Quiz() {}
} }
} }

@ -0,0 +1,11 @@
namespace WF_WebAdmin.Model
{
public class Source
{
public int id_source { get; set; }
public string title { get; set; }
public int date { get; set; }
}
}

@ -2,7 +2,7 @@
@page "/add" @page "/add"
<h3>Ajouter un quiz</h3> <h3>Ajouter une Question</h3>
<EditForm Model="@QuizModel" OnValidSubmit="@HandleValidSubmit"> <EditForm Model="@QuizModel" OnValidSubmit="@HandleValidSubmit">
@ -32,25 +32,25 @@
<p> <p>
<label for="display-c"> <label for="display-c">
Réponse B: Réponse C:
<InputText id="display-c" @bind-Value="QuizModel.AnswerB" /> <InputText id="display-c" @bind-Value="QuizModel.AnswerC" />
</label> </label>
</p> </p>
<p> <p>
<label for="display-d"> <label for="display-d">
Réponse B: Réponse D:
<InputText id="display-d" @bind-Value="QuizModel.AnswerB" /> <InputText id="display-d" @bind-Value="QuizModel.AnswerD" />
</label> </label>
</p> </p>
<p> <p>
<label for="ra"> <label for="cA">
Bonne réponse: Bonne réponse:
<input type="radio" @onchange="@(e => OnCAwnserChange("A", e.Value))" /> A <input name="cA" type="radio" @onchange="@(e => OnCAwnserChange("A", e.Value))" /> A
<input type="radio" @onchange="@(e => OnCAwnserChange("B", e.Value))" /> B <input name="cA" type="radio" @onchange="@(e => OnCAwnserChange("B", e.Value))" /> B
<input type="radio" @onchange="@(e => OnCAwnserChange("C", e.Value))" /> C <input name="cA" type="radio" @onchange="@(e => OnCAwnserChange("C", e.Value))" /> C
<input type="radio" @onchange="@(e => OnCAwnserChange("D", e.Value))" /> D <input name="cA" type="radio" @onchange="@(e => OnCAwnserChange("D", e.Value))" /> D
</label> </label>
</p> </p>

@ -1,6 +1,8 @@
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using WF_WebAdmin.Service; using WF_WebAdmin.Service;
using WF_WebAdmin.Model; using WF_WebAdmin.Model;
using Microsoft.AspNetCore.Mvc;
using System.Text.RegularExpressions;
namespace WF_WebAdmin.Pages namespace WF_WebAdmin.Pages
@ -10,27 +12,69 @@ namespace WF_WebAdmin.Pages
[Inject] [Inject]
private IQuizService quizService { get; set; } private IQuizService quizService { get; set; }
[Inject]
public NavigationManager NavigationManager { get; set; }
private QuizModel QuizModel = new(); private QuizModel QuizModel = new();
private async void HandleValidSubmit() private async void HandleValidSubmit()
{ {
int id; int id;
id = await quizService.getNbQuiz(); id = await quizService.getNbQuiz();
id++; id++;
await quizService.addQuiz(new Quiz( await quizService.addQuiz(new Quiz(
id, id,
QuizModel.Question, validateInformation(QuizModel.Question),
QuizModel.AnswerA, validateInformation(QuizModel.AnswerA),
QuizModel.AnswerB, validateInformation(QuizModel.AnswerB),
QuizModel.AnswerC, validateInformation(QuizModel.AnswerC),
QuizModel.AnswerD, validateInformation(QuizModel.AnswerD),
QuizModel.CAnswer validateReponse(QuizModel.CAnswer)
)); ));
NavigationManager.NavigateTo("modifquiz");
} }
private void OnCAwnserChange(string item, object checkedValue) private void OnCAwnserChange(string item, object checkedValue)
{ {
QuizModel.CAnswer = item; QuizModel.CAnswer = item;
} }
private static string validateInformation(string item)
{
return item; // VALIDATION A FAIRE
}
private static string validateReponse(string item)
{
try
{
if (!string.IsNullOrEmpty(item))
{
switch (item)
{
case "A":
break;
case "B":
break;
case "C":
break;
case "D":
break;
default:
throw new InvalidDataException("Invalid item (validateReponse) : item must be A,B,C or D " + item + "give.");
}
}
else
{
throw new ArgumentNullException("Invalid item (validateReponse): null given.");
}
return item;
}
catch (Exception ex)
{
return "A"; //Default Argument
}
}
} }
} }

@ -1,5 +1,48 @@
@page "/edit/{Id:int}" @using WF_WebAdmin.Model
@page "/edit/{Id:int}"
<h3>Editer</h3> <h3>Editer</h3>
<div>My parameter: @Id</div> <EditForm Model="@quoteModel" OnValidSubmit="@HandleValidSubmit">
<DataAnnotationsValidator />
<ValidationSummary />
<p>
<label for="display-cit">
Citation:
<InputText id="display-cit" @bind-Value="quoteModel.Content" />
</label>
</p>
<p>
<label for="lang">
Langue:
<input name="lang" type="radio" @onchange="@(e => OnlangChange("fr", e.Value))" /> fr
<input name="lang" type="radio" @onchange="@(e => OnlangChange("en", e.Value))" /> en
</label>
</p>
<p>
<label for="charac">
<InputSelect id="charac" @bind-Value="quoteModel.Charac">
@foreach (Character display in charac)
{
<option value="@display.caracter">@display.caracter (ID: @display.id_caracter)</option>
}
</InputSelect>
</label>
</p>
<p>
<label for="src">
<InputSelect id="src" @bind-Value="quoteModel.TitleSrc">
@foreach (Source display in src)
{
<option value="@display.title">@display.title (ID: @display.id_source)</option>
}
</InputSelect>
</label>
</p>
<button type="submit">Submit</button>
</EditForm>

@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using WF_WebAdmin.Model; using WF_WebAdmin.Model;
using WF_WebAdmin.Service;
namespace WF_WebAdmin.Pages namespace WF_WebAdmin.Pages
{ {
@ -8,6 +9,57 @@ namespace WF_WebAdmin.Pages
[Parameter] [Parameter]
public int Id { get; set; } public int Id { get; set; }
[Inject]
private IQuoteService quoteService { get; set; }
[Inject]
public NavigationManager NavigationManager { get; set; }
private Quote q{ get; set; }
private QuoteModel quoteModel = new(); private QuoteModel quoteModel = new();
private List<Character> charac = new List<Character>();
private List<Source> src = new List<Source>();
protected override async Task OnInitializedAsync()
{
q = await quoteService.getOnequote(Id);
quoteModel.Content = q.Content;
quoteModel.Langue = q.Langue;
quoteModel.Charac = q.Charac;
quoteModel.TitleSrc = q.TitleSrc;
quoteModel.Id = q.Id;
quoteModel.Like = q.Like;
quoteModel.ImgPath = q.ImgPath;
quoteModel.DateSrc = q.DateSrc;
quoteModel.UserProposition = q.UserProposition;
quoteModel.IsValid = q.IsValid;
charac = await quoteService.getChar();
src = await quoteService.getSrc();
}
protected async void HandleValidSubmit()
{
q.Content = quoteModel.Content;
q.Langue = quoteModel.Langue;
q.TitleSrc = quoteModel.TitleSrc;
q.Charac = quoteModel.Charac;
await quoteService.updateQuote(q);
NavigationManager.NavigateTo("modifquote");
}
private void OnlangChange(string item, object checkedValue)
{
if(item == "fr" || item == "en")
{
quoteModel.Langue = item;
}
}
} }
} }

@ -1,7 +1,7 @@
@using WF_WebAdmin.Model @using WF_WebAdmin.Model
@page "/modifquiz" @page "/modifquiz"
<PageTitle>Gestion des quiz</PageTitle> <PageTitle>Gestion des question</PageTitle>
<h3>Gestion des quiz</h3> <h3>Gestion des quiz</h3>

@ -5,8 +5,6 @@
<h3>Correction des citations</h3> <h3>Correction des citations</h3>
<p>Ajouter une recherche</p>
<DataGrid TItem="Quote" <DataGrid TItem="Quote"
Data="@quotes" Data="@quotes"
PageSize="@MaxValue" PageSize="@MaxValue"

@ -25,5 +25,9 @@ namespace WF_WebAdmin.Service
public Task<List<Quote>> getSomeQuoteInvalid(int nb, int page); public Task<List<Quote>> getSomeQuoteInvalid(int nb, int page);
public Task<int> getNbQuote(); public Task<int> getNbQuote();
public Task<List<Character>> getChar();
public Task<List<Source>> getSrc();
} }
} }

@ -137,5 +137,15 @@ namespace WF_WebAdmin.Service
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<List<Character>> getChar()
{
throw new NotImplementedException();
}
public Task<List<Source>> getSrc()
{
throw new NotImplementedException();
}
} }
} }

@ -6,8 +6,10 @@ namespace WF_WebAdmin.Service;
public class QuoteServiceStub : IQuoteService public class QuoteServiceStub : IQuoteService
{ {
private readonly string _jsonFilePath = Path.Combine(Environment.CurrentDirectory, "wwwroot", "fake-dataQuote.json"); private readonly string _jsonFilePath = Path.Combine(Environment.CurrentDirectory, "wwwroot", "fake-dataQuote.json");
private readonly string _char = Path.Combine(Environment.CurrentDirectory, "wwwroot", "fake-dataCaracter.json");
private readonly string _src = Path.Combine(Environment.CurrentDirectory, "wwwroot", "fake-dataSource.json");
public async Task saveQuoteJson(List<Quote> quotes) public async Task saveQuoteJson(List<Quote> quotes)
{ {
var json = JsonSerializer.Serialize(quotes, new JsonSerializerOptions { WriteIndented = true }); var json = JsonSerializer.Serialize(quotes, new JsonSerializerOptions { WriteIndented = true });
await File.WriteAllTextAsync(_jsonFilePath, json); await File.WriteAllTextAsync(_jsonFilePath, json);
@ -97,12 +99,23 @@ namespace WF_WebAdmin.Service;
public async Task<List<Quote>> getAllQuoteInvalid() public async Task<List<Quote>> getAllQuoteInvalid()
{ {
throw new NotImplementedException(); var quotes = await getAllQuote();
quotes = quotes.Where(q => q.IsValid == false).ToList();
return quotes;
} }
public async Task<List<Quote>> getSomeQuoteInvalid(int nb, int page) public async Task<List<Quote>> getSomeQuoteInvalid(int nb, int page)
{ {
throw new NotImplementedException(); var quotes = await getAllQuoteInvalid();
if ((page - 1) * nb + nb > quotes.Count())
{
if (nb > quotes.Count())
{
return quotes.GetRange(0, quotes.Count());
}
return quotes.GetRange(quotes.Count() - nb, nb);
}
return quotes.GetRange((page - 1) * nb, nb);
} }
public async Task<int> getNbQuote() public async Task<int> getNbQuote()
@ -110,5 +123,29 @@ namespace WF_WebAdmin.Service;
var data = await getAllQuote(); var data = await getAllQuote();
return data.Count; return data.Count;
} }
public async Task<List<Character>> getChar()
{
if (!File.Exists(_char))
{
Console.Out.WriteLine($"{_char} not found");
return new List<Character>();
}
var json = await File.ReadAllTextAsync(_char);
return JsonSerializer.Deserialize<List<Character>>(json) ?? new List<Character>();
}
public async Task<List<Source>> getSrc()
{
if (!File.Exists(_src))
{
Console.Out.WriteLine($"{_src} not found");
return new List<Source>();
}
var json = await File.ReadAllTextAsync(_src);
return JsonSerializer.Deserialize<List<Source>>(json) ?? new List<Source>();
}
} }

@ -45,7 +45,7 @@
<div class="nav-item px-3"> <div class="nav-item px-3">
<NavLink class="nav-link" href="modifquiz"> <NavLink class="nav-link" href="modifquiz">
<span class="oi oi-list-rich" aria-hidden="true"></span> Gestion des Quiz <span class="oi oi-list-rich" aria-hidden="true"></span> Gestion des Question
</NavLink> </NavLink>
</div> </div>

@ -3,10 +3,10 @@
"Id": 1, "Id": 1,
"Content": "Que la force soit avec toi.", "Content": "Que la force soit avec toi.",
"Like": 150, "Like": 150,
"Langue": "fr", "Langue": "en",
"Charac": "test", "Charac": "Drago Malefoy",
"ImgPath": "http://starwars.com", "ImgPath": "http://starwars.com",
"TitleSrc": "Star Wars", "TitleSrc": "L\u00E0-haut",
"DateSrc": "2025-01-21T00:00:00", "DateSrc": "2025-01-21T00:00:00",
"UserProposition": "user1", "UserProposition": "user1",
"IsValid": false "IsValid": false

@ -42,5 +42,38 @@
"CAnswer": "D", "CAnswer": "D",
"IsValid": false, "IsValid": false,
"UserProposition": "Shields Roth" "UserProposition": "Shields Roth"
},
{
"Id": 13,
"Question": "test",
"AnswerA": "a",
"AnswerB": "b",
"AnswerC": "c",
"AnswerD": "d",
"CAnswer": "D",
"IsValid": true,
"UserProposition": "Admin"
},
{
"Id": 14,
"Question": "bonjour",
"AnswerA": "ca",
"AnswerB": "va",
"AnswerC": "marcher",
"AnswerD": "!",
"CAnswer": "A",
"IsValid": true,
"UserProposition": "Admin"
},
{
"Id": 15,
"Question": "test",
"AnswerA": "a",
"AnswerB": "b",
"AnswerC": "c",
"AnswerD": "d",
"CAnswer": "C",
"IsValid": true,
"UserProposition": "Admin"
} }
] ]
Loading…
Cancel
Save