diff --git a/WF-WebAdmin/WF-WebAdmin/Model/Character.cs b/WF-WebAdmin/WF-WebAdmin/Model/Character.cs new file mode 100644 index 0000000..a5e1d87 --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Model/Character.cs @@ -0,0 +1,8 @@ +namespace WF_WebAdmin.Model +{ + public class Character + { + public int id_caracter { get; set; } + public string caracter { get; set; } + } +} diff --git a/WF-WebAdmin/WF-WebAdmin/Model/Quiz.cs b/WF-WebAdmin/WF-WebAdmin/Model/Quiz.cs index 2357f7c..a72be08 100644 --- a/WF-WebAdmin/WF-WebAdmin/Model/Quiz.cs +++ b/WF-WebAdmin/WF-WebAdmin/Model/Quiz.cs @@ -38,5 +38,7 @@ namespace WF_WebAdmin.Model UserProposition = "Admin"; } + public Quiz() {} + } } \ No newline at end of file diff --git a/WF-WebAdmin/WF-WebAdmin/Model/Source.cs b/WF-WebAdmin/WF-WebAdmin/Model/Source.cs new file mode 100644 index 0000000..99c390a --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Model/Source.cs @@ -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; } + } +} diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/AddQuiz.razor b/WF-WebAdmin/WF-WebAdmin/Pages/AddQuiz.razor index e3ba5e5..d577939 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/AddQuiz.razor +++ b/WF-WebAdmin/WF-WebAdmin/Pages/AddQuiz.razor @@ -2,7 +2,7 @@ @page "/add" -

Ajouter un quiz

+

Ajouter une Question

@@ -32,25 +32,25 @@

-

diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/AddQuiz.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/AddQuiz.razor.cs index 65a727f..36de693 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/AddQuiz.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/AddQuiz.razor.cs @@ -1,6 +1,8 @@ using Microsoft.AspNetCore.Components; using WF_WebAdmin.Service; using WF_WebAdmin.Model; +using Microsoft.AspNetCore.Mvc; +using System.Text.RegularExpressions; namespace WF_WebAdmin.Pages @@ -10,27 +12,69 @@ namespace WF_WebAdmin.Pages [Inject] private IQuizService quizService { get; set; } + [Inject] + public NavigationManager NavigationManager { get; set; } + private QuizModel QuizModel = new(); private async void HandleValidSubmit() { + int id; id = await quizService.getNbQuiz(); id++; await quizService.addQuiz(new Quiz( id, - QuizModel.Question, - QuizModel.AnswerA, - QuizModel.AnswerB, - QuizModel.AnswerC, - QuizModel.AnswerD, - QuizModel.CAnswer + validateInformation(QuizModel.Question), + validateInformation(QuizModel.AnswerA), + validateInformation(QuizModel.AnswerB), + validateInformation(QuizModel.AnswerC), + validateInformation(QuizModel.AnswerD), + validateReponse(QuizModel.CAnswer) )); + NavigationManager.NavigateTo("modifquiz"); } private void OnCAwnserChange(string item, object checkedValue) { 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 + } + } } } diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor b/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor index 5f59560..edb3822 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor +++ b/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor @@ -1,5 +1,48 @@ -@page "/edit/{Id:int}" +@using WF_WebAdmin.Model +@page "/edit/{Id:int}"

Editer

-
My parameter: @Id
\ No newline at end of file + + + + +

+ +

+ +

+ +

+ +

+ +

+ +

+ +

+ + +
\ No newline at end of file diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor.cs index 4d09214..71bb9f0 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Components; using WF_WebAdmin.Model; +using WF_WebAdmin.Service; namespace WF_WebAdmin.Pages { @@ -8,6 +9,57 @@ namespace WF_WebAdmin.Pages [Parameter] 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 List charac = new List(); + + private List src = new List(); + + 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; + } + } + + + + } } diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuiz.razor b/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuiz.razor index 1a5e55b..60d2264 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuiz.razor +++ b/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuiz.razor @@ -1,7 +1,7 @@ @using WF_WebAdmin.Model @page "/modifquiz" -Gestion des quiz +Gestion des question

Gestion des quiz

diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor b/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor index 25e14d8..a04a0fd 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor +++ b/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor @@ -5,8 +5,6 @@

Correction des citations

-

Ajouter une recherche

- > getSomeQuoteInvalid(int nb, int page); public Task getNbQuote(); + + public Task> getChar(); + + public Task> getSrc(); } } diff --git a/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceLocal.cs b/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceLocal.cs index 6f9a9b8..4417c5b 100644 --- a/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceLocal.cs +++ b/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceLocal.cs @@ -137,5 +137,15 @@ namespace WF_WebAdmin.Service { throw new NotImplementedException(); } + + public Task> getChar() + { + throw new NotImplementedException(); + } + + public Task> getSrc() + { + throw new NotImplementedException(); + } } } diff --git a/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceStub.cs b/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceStub.cs index bc2dea4..fcf6102 100644 --- a/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceStub.cs +++ b/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceStub.cs @@ -6,8 +6,10 @@ namespace WF_WebAdmin.Service; public class QuoteServiceStub : IQuoteService { 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 quotes) + public async Task saveQuoteJson(List quotes) { var json = JsonSerializer.Serialize(quotes, new JsonSerializerOptions { WriteIndented = true }); await File.WriteAllTextAsync(_jsonFilePath, json); @@ -97,12 +99,23 @@ namespace WF_WebAdmin.Service; public async Task> getAllQuoteInvalid() { - throw new NotImplementedException(); + var quotes = await getAllQuote(); + quotes = quotes.Where(q => q.IsValid == false).ToList(); + return quotes; } public async Task> 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 getNbQuote() @@ -110,5 +123,29 @@ namespace WF_WebAdmin.Service; var data = await getAllQuote(); return data.Count; } + + public async Task> getChar() + { + if (!File.Exists(_char)) + { + Console.Out.WriteLine($"{_char} not found"); + return new List(); + } + + var json = await File.ReadAllTextAsync(_char); + return JsonSerializer.Deserialize>(json) ?? new List(); + } + + public async Task> getSrc() + { + if (!File.Exists(_src)) + { + Console.Out.WriteLine($"{_src} not found"); + return new List(); + } + + var json = await File.ReadAllTextAsync(_src); + return JsonSerializer.Deserialize>(json) ?? new List(); + } } \ No newline at end of file diff --git a/WF-WebAdmin/WF-WebAdmin/Shared/NavMenu.razor b/WF-WebAdmin/WF-WebAdmin/Shared/NavMenu.razor index 5dfc260..83deca9 100644 --- a/WF-WebAdmin/WF-WebAdmin/Shared/NavMenu.razor +++ b/WF-WebAdmin/WF-WebAdmin/Shared/NavMenu.razor @@ -45,7 +45,7 @@ diff --git a/WF-WebAdmin/WF-WebAdmin/wwwroot/fake-dataQuote.json b/WF-WebAdmin/WF-WebAdmin/wwwroot/fake-dataQuote.json index 6d48018..a81ebeb 100644 --- a/WF-WebAdmin/WF-WebAdmin/wwwroot/fake-dataQuote.json +++ b/WF-WebAdmin/WF-WebAdmin/wwwroot/fake-dataQuote.json @@ -3,10 +3,10 @@ "Id": 1, "Content": "Que la force soit avec toi.", "Like": 150, - "Langue": "fr", - "Charac": "test", + "Langue": "en", + "Charac": "Drago Malefoy", "ImgPath": "http://starwars.com", - "TitleSrc": "Star Wars", + "TitleSrc": "L\u00E0-haut", "DateSrc": "2025-01-21T00:00:00", "UserProposition": "user1", "IsValid": false diff --git a/WF-WebAdmin/WF-WebAdmin/wwwroot/fake_data_quiz.json b/WF-WebAdmin/WF-WebAdmin/wwwroot/fake_data_quiz.json index 4569231..ef41eeb 100644 --- a/WF-WebAdmin/WF-WebAdmin/wwwroot/fake_data_quiz.json +++ b/WF-WebAdmin/WF-WebAdmin/wwwroot/fake_data_quiz.json @@ -42,5 +42,38 @@ "CAnswer": "D", "IsValid": false, "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" } ] \ No newline at end of file