diff --git a/WF-WebAdmin/WF-WebAdmin/Model/LoggerSaveStub.cs b/WF-WebAdmin/WF-WebAdmin/Model/LoggerSaveStub.cs index e4b7df8..5001367 100644 --- a/WF-WebAdmin/WF-WebAdmin/Model/LoggerSaveStub.cs +++ b/WF-WebAdmin/WF-WebAdmin/Model/LoggerSaveStub.cs @@ -12,7 +12,7 @@ namespace WF_WebAdmin.Model { public static partial class LoggerSaveStub { - public static void Log(ILogger logs, LogLevel logLevel, string message, params object[] args) + public static void Log(ILogger? logs, LogLevel logLevel, string message, params object[] args) { ILogsService logsService = new LogsServiceStub(); logsService.addLogs(new Logs(logLevel, string.Format(message, args))); diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/AddQuiz.razor b/WF-WebAdmin/WF-WebAdmin/Pages/AddQuiz.razor index 5505f94..74d9b25 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/AddQuiz.razor +++ b/WF-WebAdmin/WF-WebAdmin/Pages/AddQuiz.razor @@ -5,52 +5,52 @@

@Localizer["TitleAddQuiz"]

- +

diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/AddQuiz.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/AddQuiz.razor.cs index c88d921..cea1420 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/AddQuiz.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/AddQuiz.razor.cs @@ -13,18 +13,18 @@ namespace WF_WebAdmin.Pages public partial class AddQuiz { [Inject] - public ILogger Logger { get; set; } + public ILogger? Logger { get; set; } [Inject] - public IStringLocalizer Localizer { get; set; } + public IStringLocalizer? Localizer { get; set; } [Inject] - private IQuizService quizService { get; set; } + private IQuizService? QuizService { get; set; } [Inject] - public NavigationManager NavigationManager { get; set; } + public NavigationManager? NavigationManager { get; set; } - private QuizModel QuizModel = new(); + private readonly QuizModel _quizModel = new(); /// /// Handles the valid submission of a quiz form. @@ -39,21 +39,21 @@ namespace WF_WebAdmin.Pages int id; // Get the current number of quizzes from the quiz service. - id = await quizService.getNbQuiz(); + id = await QuizService.getNbQuiz(); // Increment the quiz ID for the new quiz. id++; // Create a new quiz and add it using the quiz service. - LoggerSaveStub.Log(Logger, LogLevel.Information, $"Creation of the {QuizModel.Question} question"); - await quizService.addQuiz(new Quiz( + LoggerSaveStub.Log(Logger, LogLevel.Information, $"Creation of the {_quizModel.Question} question"); + await QuizService.addQuiz(new Quiz( id, // New quiz ID - validateInformation(QuizModel.Question), // Validated question - validateInformation(QuizModel.AnswerA), // Validated answer A - validateInformation(QuizModel.AnswerB), // Validated answer B - validateInformation(QuizModel.AnswerC), // Validated answer C - validateInformation(QuizModel.AnswerD), // Validated answer D - validateReponse(QuizModel.CAnswer) // Validated correct answer + ValidateInformation(_quizModel.Question), // Validated question + ValidateInformation(_quizModel.AnswerA), // Validated answer A + ValidateInformation(_quizModel.AnswerB), // Validated answer B + ValidateInformation(_quizModel.AnswerC), // Validated answer C + ValidateInformation(_quizModel.AnswerD), // Validated answer D + ValidateReponse(_quizModel.CAnswer) // Validated correct answer )); // Navigate to the "modifquiz" page after adding the quiz. @@ -69,10 +69,10 @@ namespace WF_WebAdmin.Pages /// /// The selected answer that will be marked as the correct answer. /// The value of the selected option, typically used for validation or additional logic. - private void OnCAwnserChange(string item, object checkedValue) + private void OnCAwnserChange(string item) { // Update the correct answer in the QuizModel with the selected answer. - QuizModel.CAnswer = item; + _quizModel.CAnswer = item; } @@ -84,9 +84,9 @@ namespace WF_WebAdmin.Pages /// /// Returns the input string as it is for now. The validation logic is yet to be implemented. /// - private static string validateInformation(string item) + private string ValidateInformation(string? item) { - return item; // VALIDATION A FAIRE + return string.IsNullOrWhiteSpace(item) ? "Valeur par défaut" : item; } /// @@ -98,43 +98,31 @@ namespace WF_WebAdmin.Pages /// /// Returns the input item if valid (A, B, C, or D). If the item is invalid or null, it returns a default value ("A"). /// - private static string validateReponse(string item) + private static string ValidateReponse(string item) { - try + // Check if the item is null or empty + if (string.IsNullOrEmpty(item)) { - // Check if the item is not null or empty - if (!string.IsNullOrEmpty(item)) - { - // Validate that the item is one of the allowed values: A, B, C, or D - switch (item) - { - case "A": - break; - case "B": - break; - case "C": - break; - case "D": - break; - default: - // Throw exception if the item is not one of the allowed answers - throw new InvalidDataException("Invalid item (validateReponse) : item must be A,B,C or D " + item + " given."); - } - } - else - { - // Throw exception if the item is null or empty - throw new ArgumentNullException("Invalid item (validateReponse): null given."); - } - - // Return the validated item - return item; + // Throw exception if the item is null or empty + throw new ArgumentNullException(nameof(item), "The item cannot be null or empty."); } - catch (Exception ex) + + // Validate that the item is one of the allowed values: A, B, C, or D + switch (item) { - // In case of an exception, return a default answer ("A") - return "A"; // Default Argument + case "A": + case "B": + case "C": + case "D": + // Valid values, no action needed + break; + default: + // Throw exception if the item is not one of the allowed answers + throw new InvalidDataException($"Invalid item '{item}' provided. Item must be one of: A, B, C, or D."); } + + // Return the validated item + return item; } } } diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs index 1eae8a6..a508c85 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs @@ -12,7 +12,7 @@ namespace WF_WebAdmin.Pages public partial class DeleteUser { [Inject] - public ILogger Logger { get; set; } + public ILogger? Logger { get; set; } private List users; diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor.cs index dad1e46..8a8c6a8 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor.cs @@ -11,7 +11,7 @@ namespace WF_WebAdmin.Pages public int Id { get; set; } [Inject] - public ILogger Logger { get; set; } + public ILogger? Logger { get; set; } [Inject] private IQuoteService quoteService { get; set; } diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuiz.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuiz.razor.cs index 1ac9887..3d1a351 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuiz.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuiz.razor.cs @@ -24,7 +24,7 @@ namespace WF_WebAdmin.Pages private int page = 1; [Inject] - public ILogger Logger { get; set; } + public ILogger? Logger { get; set; } [Inject] public IStringLocalizer Localizer { get; set; } diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor.cs index bafd81b..410f9be 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor.cs @@ -25,7 +25,7 @@ namespace WF_WebAdmin.Pages private int page = 1; [Inject] - public ILogger Logger { get; set; } + public ILogger? Logger { get; set; } [Inject] public IStringLocalizer Localizer { get; set; } diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuiz.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuiz.razor.cs index 4f4cd90..fe4b814 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuiz.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuiz.razor.cs @@ -10,10 +10,10 @@ namespace WF_WebAdmin.Pages { public partial class ValidQuiz { - private List quizzes; - [Inject] - public ILogger Logger { get; set; } - + private List quizzes; + [Inject] + public ILogger? Logger { get; set; } + [Inject] public IStringLocalizer Localizer { get; set; } @@ -26,74 +26,74 @@ namespace WF_WebAdmin.Pages [Inject] public IQuizService QuizService { get; set; } - - /// - /// Initializes the component asynchronously by fetching the quizzes that need validation. - /// This method retrieves a list of quizzes from the `QuizService` that are pending validation when the component is initialized. - /// + + /// + /// Initializes the component asynchronously by fetching the quizzes that need validation. + /// This method retrieves a list of quizzes from the `QuizService` that are pending validation when the component is initialized. + /// protected override async Task OnInitializedAsync() { - // Fetch quizzes that need validation + // Fetch quizzes that need validation quizzes = await QuizService.getQuizzesToValidate(); } - /// - /// Handles the event when the "Validate" button is clicked for a quiz. - /// This method calls the `ValidateQuiz` method, passing the specified quiz for validation. - /// - /// The quiz that is being validated. + /// + /// Handles the event when the "Validate" button is clicked for a quiz. + /// This method calls the `ValidateQuiz` method, passing the specified quiz for validation. + /// + /// The quiz that is being validated. private void OnValidButton(Quiz quiz) { - // Call the ValidateQuiz method to validate the quiz + // Call the ValidateQuiz method to validate the quiz ValidateQuiz(quiz); } - - /// - /// Validates the specified quiz by setting its `IsValid` property to true and updating its state in the service. - /// This method logs a message to the console indicating the quiz has been validated, then updates the quiz's validation status. - /// It then calls the `QuizService.updateQuiz` method to persist the changes. - /// - /// The quiz that is being validated. + + /// + /// Validates the specified quiz by setting its `IsValid` property to true and updating its state in the service. + /// This method logs a message to the console indicating the quiz has been validated, then updates the quiz's validation status. + /// It then calls the `QuizService.updateQuiz` method to persist the changes. + /// + /// The quiz that is being validated. private void ValidateQuiz(Quiz quiz) { - // Log the validation action to the console + // Log the validation action to the console LoggerSaveStub.Log(Logger, LogLevel.Information, $"Quiz {quiz.Id} validated!"); Console.WriteLine($"Quiz {quiz.Id} validated!"); - - // Create a new quiz instance (or modify the existing one) + + // Create a new quiz instance (or modify the existing one) Quiz newQuiz = quiz; newQuiz.IsValid = true; - // Update the quiz state in the QuizService + // Update the quiz state in the QuizService QuizService.updateQuiz(quiz); } - /// - /// Handles the event when the "Reject" button is clicked for a quiz. - /// This method calls the `RejectQuiz` method, passing the specified quiz to be rejected. - /// - /// The quiz that is being rejected. + /// + /// Handles the event when the "Reject" button is clicked for a quiz. + /// This method calls the `RejectQuiz` method, passing the specified quiz to be rejected. + /// + /// The quiz that is being rejected. private void OnRejectButton(Quiz quiz) { - // Call the RejectQuiz method to reject the quiz + // Call the RejectQuiz method to reject the quiz RejectQuiz(quiz); } - /// - /// Rejects the specified quiz by logging a rejection message and removing it from the QuizService. - /// This method logs a message to the console indicating the quiz has been rejected, and then calls the `QuizService.removeQuiz` - /// method to remove the quiz from the system. - /// - /// The quiz that is being rejected. + /// + /// Rejects the specified quiz by logging a rejection message and removing it from the QuizService. + /// This method logs a message to the console indicating the quiz has been rejected, and then calls the `QuizService.removeQuiz` + /// method to remove the quiz from the system. + /// + /// The quiz that is being rejected. private void RejectQuiz(Quiz quiz) { - // Log the rejection action to the console + // Log the rejection action to the console LoggerSaveStub.Log(Logger, LogLevel.Information, $"Quiz {quiz.Id} rejected"); Console.WriteLine($"Quiz {quiz.Id} rejected!"); - // Remove the rejected quiz from the QuizService + // Remove the rejected quiz from the QuizService QuizService.removeQuiz(quiz.Id); } }