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" -
-
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}"
+
+
+
+
Ajouter une recherche
-quotes) + public async Task saveQuoteJson(Listquotes) { 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