doc fait sur le code behind des pages
continuous-integration/drone/push Build is passing Details

pull/30/head^2
lebeaulato 3 months ago
parent 7ad7135804
commit f3b95d273d

@ -18,6 +18,12 @@ namespace WF_WebAdmin.Pages
[Inject]
public IStringLocalizer<Accueil> Localizer { get; set; }
/// <summary>
/// This method is called during the initialization of the Blazor component.
/// It is asynchronous and is used to load data or perform actions before the component is rendered.
/// </summary>
protected override async Task OnInitializedAsync()
{
Dailyquote = await Http.GetFromJsonAsync<Quote[]>($"{NavigationManager.BaseUri}fake-dataDailyQuote.json");

@ -22,40 +22,85 @@ namespace WF_WebAdmin.Pages
private QuizModel QuizModel = new();
/// <summary>
/// Handles the valid submission of a quiz form.
/// This method is triggered when the form is successfully validated and the user submits the quiz data.
/// It retrieves the current quiz count, increments it, and then adds a new quiz entry to the quiz service.
/// Finally, it navigates to the "modifquiz" page.
/// </summary>
private async void HandleValidSubmit()
{
// Declare a variable to hold the ID of the new quiz.
int id;
// Get the current number of quizzes from the quiz service.
id = await quizService.getNbQuiz();
// Increment the quiz ID for the new quiz.
id++;
// Create a new quiz and add it using the quiz service.
await quizService.addQuiz(new Quiz(
id,
validateInformation(QuizModel.Question),
validateInformation(QuizModel.AnswerA),
validateInformation(QuizModel.AnswerB),
validateInformation(QuizModel.AnswerC),
validateInformation(QuizModel.AnswerD),
validateReponse(QuizModel.CAnswer)
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
));
// Navigate to the "modifquiz" page after adding the quiz.
NavigationManager.NavigateTo("modifquiz");
}
/// <summary>
/// Handles the change of the correct answer for the quiz.
/// This method is triggered when the user selects or changes the correct answer for the quiz question.
/// It updates the QuizModel's Correct Answer property with the selected answer.
/// </summary>
/// <param name="item">The selected answer that will be marked as the correct answer.</param>
/// <param name="checkedValue">The value of the selected option, typically used for validation or additional logic.</param>
private void OnCAwnserChange(string item, object checkedValue)
{
// Update the correct answer in the QuizModel with the selected answer.
QuizModel.CAnswer = item;
}
/// <summary>
/// Validates the provided string item.
/// This method is used to validate input data, but the validation logic is not yet implemented.
/// </summary>
/// <param name="item">The string input to be validated.</param>
/// <returns>
/// Returns the input string as it is for now. The validation logic is yet to be implemented.
/// </returns>
private static string validateInformation(string item)
{
return item; // VALIDATION A FAIRE
}
private static string validateReponse(string item)
/// <summary>
/// Validates the provided answer item (A, B, C, or D) for the quiz.
/// This method ensures that the input corresponds to one of the allowed values for the correct answer.
/// If the input is invalid or null, it throws an exception and returns a default value ("A") in case of error.
/// </summary>
/// <param name="item">The answer item (A, B, C, or D) to be validated.</param>
/// <returns>
/// Returns the input item if valid (A, B, C, or D). If the item is invalid or null, it returns a default value ("A").
/// </returns>
private static string validateReponse(string item)
{
try
{
// 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":
@ -67,18 +112,23 @@ namespace WF_WebAdmin.Pages
case "D":
break;
default:
throw new InvalidDataException("Invalid item (validateReponse) : item must be A,B,C or D " + item + "give.");
// 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;
}
catch (Exception ex)
catch (Exception ex)
{
return "A"; //Default Argument
// In case of an exception, return a default answer ("A")
return "A"; // Default Argument
}
}
}

@ -34,96 +34,176 @@ namespace WF_WebAdmin.Pages
private IUserService userService { get; set; }
[Inject]
public IStringLocalizer<DeleteUser> Localizer { get; set; }
protected override async Task OnInitializedAsync()
{
users = await userService.getSomeUser(MaxValue, 1);
}
private async Task OnReadData(DataGridReadDataEventArgs<User> e)
{
if (e.CancellationToken.IsCancellationRequested)
{
return;
}
var response = await userService.getSomeUser(e.PageSize, e.Page);
if (!e.CancellationToken.IsCancellationRequested)
{
totalItem = await userService.getNbUser();
users = new List<User>(response.ToArray());
page = e.Page;
}
}
// ------- Popup remove user -------
private void ShowConfirmation(User user)
{
userToDelete = user;
showPopupDelete = true;
}
private void ShowModifyConfirmation(User user)
{
// Afficher la modale et mémoriser l'utilisateur à supprimer
selectedUser = user;
showModifyPopup = true;
}
private async Task RemoveUser()
{
if (userToDelete != null)
{
await userService.removeUser(userToDelete);
ClosePopup();
var response = await userService.getSomeUser(MaxValue, page);
users = new List<User>(response.ToArray());
}
}
private async Task ModifyUser()
{
await userService.updateUser(selectedUser);
ClosePopup();
}
private void ClosePopup()
{
showDeletePopup = false;
showModifyPopup = false;
showPopupDelete = false;
showPopupAdmin = false;
}
// ------- Popup admin -------
private void ShowConfirmationAdmin(User user)
{
userToAdmin = user;
showPopupAdmin = true;
}
private async Task setAdmin()
{
if (!userToAdmin.IsAdmin)
{
userToAdmin.IsAdmin = true;
await userService.updateUser(userToAdmin);
ClosePopup();
}
else
{
userToAdmin.IsAdmin = false;
await userService.updateUser(userToAdmin);
ClosePopup();
}
public IStringLocalizer<DeleteUser> Localizer { get; set; }
/// <summary>
/// This method is called when the component is initialized.
/// It is an asynchronous method that retrieves a list of users from the user service.
/// The method fetches a subset of users with a specified maximum value and page number (1 in this case).
/// </summary>
protected override async Task OnInitializedAsync()
{
// Retrieve a list of users using the user service. The number of users and page number are specified.
// MaxValue determines how many users to retrieve, and '1' refers to the first page of results.
users = await userService.getSomeUser(MaxValue, 1);
}
/// <summary>
/// Handles the event when data is read in the data grid.
/// This method is triggered during pagination or when data is loaded into the grid.
/// It asynchronously fetches a page of users based on the requested page size and page number,
/// and updates the list of users and total item count if the operation is not cancelled.
/// </summary>
/// <param name="e">The event arguments containing pagination details (page size and page number) and a cancellation token.</param>
private async Task OnReadData(DataGridReadDataEventArgs<User> e)
{
// If the cancellation token is requested, exit the method without processing the request.
if (e.CancellationToken.IsCancellationRequested)
{
return;
}
// Fetch a page of users from the user service using the page size and page number provided by the event arguments.
var response = await userService.getSomeUser(e.PageSize, e.Page);
// If the operation is not cancelled, update the total number of users and the list of users.
if (!e.CancellationToken.IsCancellationRequested)
{
totalItem = await userService.getNbUser(); // Get the total number of users
users = new List<User>(response.ToArray()); // Store the retrieved users in the users list
page = e.Page; // Update the current page number
}
}
// ------- Popup remove user -------
/// <summary>
/// Displays a confirmation popup to confirm the deletion of a user.
/// This method is triggered when the user intends to delete a user,
/// and it sets the user to be deleted and shows the confirmation popup.
/// </summary>
/// <param name="user">The user to be deleted, which is passed to the method for confirmation.</param>
private void ShowConfirmation(User user)
{
// Set the user to be deleted and show the confirmation popup.
userToDelete = user; // Store the user to be deleted in a variable
showPopupDelete = true; // Display the confirmation popup
}
/// <summary>
/// Displays a confirmation popup for modifying a user's information.
/// This method is triggered when the user intends to modify a specific user's data,
/// and it sets the selected user and shows the modification confirmation popup.
/// </summary>
/// <param name="user">The user whose information is to be modified, passed to the method for confirmation.</param>
private void ShowModifyConfirmation(User user)
{
// Set the selected user and show the modification confirmation popup.
selectedUser = user; // Store the user to be modified
showModifyPopup = true; // Display the confirmation popup for modification
}
/// <summary>
/// Removes the specified user from the system.
/// This method is triggered when the user confirms the deletion of a user.
/// It calls the user service to remove the user, closes the confirmation popup,
/// and then refreshes the list of users by fetching the updated data.
/// </summary>
private async Task RemoveUser()
{
// Check if there is a user to delete
if (userToDelete != null)
{
// Remove the selected user from the system using the user service
await userService.removeUser(userToDelete);
// Close the confirmation popup after the deletion
ClosePopup();
// Refresh the list of users by fetching the updated data from the user service
var response = await userService.getSomeUser(MaxValue, page);
// Update the users list with the latest data
users = new List<User>(response.ToArray());
}
}
/// <summary>
/// Modifies the selected user's information.
/// This method is triggered when the user confirms the modification of a user's details.
/// It calls the user service to update the user's information and then closes the modification popup.
/// </summary>
private async Task ModifyUser()
{
// Update the selected user's information using the user service
await userService.updateUser(selectedUser);
// Close the modification popup after the update is complete
ClosePopup();
}
/// <summary>
/// Closes all open popups in the UI by setting their visibility flags to false.
/// This method is typically called after an action (like deleting or modifying a user)
/// to hide any active popups and reset the UI state.
/// </summary>
private void ClosePopup()
{
// Set all popup visibility flags to false to hide the popups
showDeletePopup = false; // Close the delete confirmation popup
showModifyPopup = false; // Close the modify confirmation popup
showPopupDelete = false; // Close any additional delete popups
showPopupAdmin = false; // Close the admin-related popup (if any)
}
// ------- Popup admin -------
/// <summary>
/// Displays a confirmation popup to confirm the promotion of a user to admin status.
/// This method is triggered when the user intends to promote a specific user to admin.
/// It sets the selected user to be promoted and shows the confirmation popup for admin promotion.
/// </summary>
/// <param name="user">The user to be promoted to admin, passed to the method for confirmation.</param>
private void ShowConfirmationAdmin(User user)
{
// Set the user to be promoted to admin and show the confirmation popup.
userToAdmin = user; // Store the user to be promoted
showPopupAdmin = true; // Display the confirmation popup for admin promotion
}
/// <summary>
/// Toggles the admin status of the selected user.
/// This method checks the current admin status of the user, and if the user is not an admin,
/// it promotes them to admin. If the user is already an admin, it demotes them.
/// After the change, the user's information is updated, and the confirmation popup is closed.
/// </summary>
private async Task setAdmin()
{
// Check if the user is not already an admin
if (!userToAdmin.IsAdmin)
{
// Promote the user to admin
userToAdmin.IsAdmin = true;
await userService.updateUser(userToAdmin); // Update the user status in the service
ClosePopup(); // Close the confirmation popup
}
else
{
// Demote the user from admin to normal user
userToAdmin.IsAdmin = false;
await userService.updateUser(userToAdmin); // Update the user status in the service
ClosePopup(); // Close the confirmation popup
}
}
}

@ -23,9 +23,19 @@ namespace WF_WebAdmin.Pages
private List<Source> src = new List<Source>();
/// <summary>
/// Asynchronously initializes the component by loading data related to a quote.
/// This method fetches a specific quote based on the provided ID and populates the `quoteModel`
/// with the quote's content, language, character, source, and other associated data.
/// It also loads additional data such as character and source information for the quote.
/// </summary>
protected override async Task OnInitializedAsync()
{
// Fetch the quote data based on the provided ID.
q = await quoteService.getOnequote(Id);
// Populate the quoteModel with the data from the retrieved quote.
quoteModel.Content = q.Content;
quoteModel.Langue = q.Langue;
quoteModel.Charac = q.Charac;
@ -36,30 +46,50 @@ namespace WF_WebAdmin.Pages
quoteModel.DateSrc = q.DateSrc;
quoteModel.UserProposition = q.UserProposition;
quoteModel.IsValid = q.IsValid;
// Fetch additional data related to the quote, such as character and source.
charac = await quoteService.getChar();
src = await quoteService.getSrc();
}
/// <summary>
/// Handles the submission of a valid form for updating a quote.
/// This method takes the data from `quoteModel`, updates the selected quote (`q`) with the new values,
/// and then calls the `quoteService.updateQuote` method to persist the changes.
/// After updating, it navigates to the "modifquote" page.
/// </summary>
protected async void HandleValidSubmit()
{
// Update the properties of the selected quote (`q`) with the data from `quoteModel`.
q.Content = quoteModel.Content;
q.Langue = quoteModel.Langue;
q.TitleSrc = quoteModel.TitleSrc;
q.Charac = quoteModel.Charac;
// Call the quote service to update the quote in the data source.
await quoteService.updateQuote(q);
// Navigate to the "modifquote" page after updating the quote.
NavigationManager.NavigateTo("modifquote");
}
/// <summary>
/// Handles the language change event for the quote.
/// This method updates the `Langue` property of the `quoteModel` based on the selected language (`item`).
/// It only accepts "fr" (French) or "en" (English) as valid language options.
/// </summary>
/// <param name="item">The selected language ("fr" or "en") passed to the method.</param>
/// <param name="checkedValue">The checked value (unused in this method but may be used for other purposes).</param>
private void OnlangChange(string item, object checkedValue)
{
if(item == "fr" || item == "en")
// Check if the selected language is either "fr" or "en"
if (item == "fr" || item == "en")
{
// Update the Langue property of the quoteModel with the selected language
quoteModel.Langue = item;
}
}
}
}
}

@ -14,13 +14,26 @@ namespace WF_WebAdmin.Pages
private readonly ILogger<ErrorModel> _logger;
/// <summary>
/// Initializes a new instance of the <see cref="ErrorModel"/> class.
/// This constructor is used to inject the <see cref="ILogger{ErrorModel}"/> into the model for logging purposes.
/// </summary>
/// <param name="logger">An instance of the <see cref="ILogger{ErrorModel}"/> used for logging error-related information.</param>
public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
}
/// <summary>
/// Handles the GET request for the page or endpoint.
/// This method retrieves the request ID for tracing purposes, using the `Activity.Current?.Id`
/// if it's available, or the `HttpContext.TraceIdentifier` as a fallback if no current activity ID is present.
/// </summary>
public void OnGet()
{
// Retrieve the current request ID for tracing
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}

@ -26,45 +26,63 @@ namespace WF_WebAdmin.Pages
[Inject]
public NavigationManager NavigationManager { get; set; }
/// <summary>
/// Asynchronously initializes the component by loading user login data.
/// This method retrieves a list of user login information from a JSON file located at the specified URI
/// and populates the `usersConnexion` list with the data.
/// </summary>
protected override async Task OnInitializedAsync()
{
// Fetch user login data from the specified JSON file.
usersConnexion = await Http.GetFromJsonAsync<List<UserLogin>>($"{NavigationManager.BaseUri}fake-dataUserLogin.json");
}
/// <summary>
/// Validates the login credentials of the user.
/// This method checks if the provided username and password match any user in the `usersConnexion` list.
/// If the credentials are correct and the user is an admin, it stores the user details and navigates to the home page.
/// If the credentials are incorrect, an error message is set for display.
/// </summary>
public void validlogin()
{
// Check if both the username and password are provided
if (!string.IsNullOrEmpty(userLogin.Name) || !string.IsNullOrEmpty(userLogin.Mdp))
{
// Loop through the list of connected users to find a match
foreach (var user in usersConnexion)
{
if(userLogin.Name == user.Name && userLogin.Mdp == user.Mdp)
// Check if the username and password match the user credentials
if (userLogin.Name == user.Name && userLogin.Mdp == user.Mdp)
{
if(user.IsAdmin)
// Check if the user is an admin
if (user.IsAdmin)
{
// If the user is an admin, store their information and navigate to the home page
uLogin.Id = userLogin.Id;
uLogin.Name = user.Name;
uLogin.Image = user.Image;
// Redirect to the homepage
NavigationManager.NavigateTo(NavigationManager.BaseUri + "accueil");
return;
}
else
{
// If the user is not an admin, display an error message
ErrorConnexion = "Connexion échouée, le nom ou le mot de passe sont incorrectes";
}
}
else
{
// If credentials do not match, set the error message
ErrorConnexion = "Connexion échouée, le nom ou le mot de passe sont incorrectes";
}
}
}
}
}
}

@ -28,60 +28,129 @@ namespace WF_WebAdmin.Pages
[Inject]
public IQuizService QuizService { get; set; }
/// <summary>
/// Handles the data reading event for a data grid, fetching quiz data based on the specified page and page size.
/// This method makes an asynchronous call to retrieve a specific page of quizzes and updates the `quiz` list and pagination details.
/// If the cancellation token is requested, it exits early without making further calls or updates.
/// </summary>
/// <param name="e">The event arguments containing pagination details such as page size and page number.</param>
private async Task OnReadData(DataGridReadDataEventArgs<Quiz> e)
{
// Check if the cancellation token has been requested
if (e.CancellationToken.IsCancellationRequested)
{
return;
}
// Fetch the quiz data for the specified page and page size
var response = await QuizService.getSommeQuiz(e.PageSize, e.Page);
// If cancellation hasn't been requested, process the data
if (!e.CancellationToken.IsCancellationRequested)
{
// Get the total number of quizzes for pagination purposes
totalItem = await QuizService.getNbQuiz();
// Update the quiz data for the current page
quiz = response.ToArray();
// Update the current page number
page = e.Page;
}
}
/// <summary>
/// Handles the event when the "Edit" button is clicked for a quiz.
/// This method checks if a valid quiz is passed. If so, it sets the `selectedQuiz` to the clicked quiz and shows the quiz edit modal.
/// </summary>
/// <param name="quiz">The quiz object that was clicked for editing.</param>
private void OnEditButtonClicked(Quiz quiz)
{
// If the quiz is null, return early
if (quiz == null) return;
// Set the selected quiz to the one clicked by the user
selectedQuiz = quiz;
// Show the modal or UI for editing the quiz
showEditQuiz = true;
}
/// <summary>
/// Closes the open popups and resets any related states.
/// This method hides the quiz edit popup, the delete confirmation popup, and resets the selected quiz to `null`.
/// </summary>
private void ClosePopup()
{
// Hide the edit quiz popup
showEditQuiz = false;
// Hide the delete confirmation popup
showPopupDelete = false;
// Reset the selected quiz to null
selectedQuiz = null;
}
/// <summary>
/// Edits the selected quiz by updating it in the quiz service.
/// This method asynchronously sends the updated quiz data to the service for persistence.
/// After updating the quiz, it clears the selected quiz and closes any open popups.
/// </summary>
private async Task EditQuiz()
{
// Update the quiz in the service
await QuizService.updateQuiz(selectedQuiz);
// Clear the selected quiz after successful update
selectedQuiz = null;
// Close the popups after the edit operation
ClosePopup();
}
/// <summary>
/// Handles the event when the delete action is triggered for a quiz.
/// This method sets the selected quiz to the one passed as a parameter and shows the delete confirmation popup.
/// </summary>
/// <param name="q">The quiz to be deleted.</param>
private void OnDelete(Quiz q)
{
// Set the selected quiz to the one passed in
selectedQuiz = q;
// Show the delete confirmation popup
showPopupDelete = true;
}
/// <summary>
/// Removes the selected quiz from the quiz service and updates the quiz list.
/// This method first checks if a quiz is selected, and if so, it deletes the quiz by calling the service.
/// After removal, it clears the `selectedQuiz`, updates the quiz list, and closes the delete confirmation popup.
/// </summary>
private async void RemoveQuote()
{
// Check if a quiz is selected for deletion
if (selectedQuiz != null)
{
// Remove the selected quiz from the service by its ID
await QuizService.removeQuiz(selectedQuiz.Id);
// Clear the selected quiz after successful removal
selectedQuiz = null;
// Update the quiz list by fetching the latest data
var response = await QuizService.getSommeQuiz(MaxValue, page);
quiz = response.ToArray();
}
showPopupDelete= false;
// Close the delete confirmation popup
showPopupDelete = false;
}
}
}

@ -28,19 +28,34 @@ namespace WF_WebAdmin.Pages
[Inject]
public IQuoteService QuoteService { get; set; }
/// <summary>
/// Handles the data reading event for a data grid, fetching quote data based on the specified page and page size.
/// This method makes an asynchronous call to retrieve a specific page of quotes and updates the `quotes` list and pagination details.
/// If the cancellation token is requested, it exits early without making further calls or updates.
/// </summary>
/// <param name="e">The event arguments containing pagination details such as page size and page number.</param>
private async Task OnReadData(DataGridReadDataEventArgs<Quote> e)
{
// Check if the cancellation token has been requested
if (e.CancellationToken.IsCancellationRequested)
{
return;
}
// Fetch the quote data for the specified page and page size
var response = await QuoteService.getSomeQuote(e.PageSize, e.Page);
// If cancellation hasn't been requested, process the data
if (!e.CancellationToken.IsCancellationRequested)
{
// Get the total number of quotes for pagination purposes
totalItem = await QuoteService.getNbQuote();
// Update the quotes data for the current page
quotes = response.ToArray();
// Update the current page number
page = e.Page;
}
}
@ -51,11 +66,17 @@ namespace WF_WebAdmin.Pages
selectedQuote = quote;
showEditQuote = true;
}*/
/// <summary>
/// Closes the open popups and resets any related states.
/// This method hides the delete confirmation popup and clears the selected quote.
/// </summary>
private void ClosePopup()
{
/*showEditQuote = false;*/
// Hide the delete confirmation popup
showPopupDelete = false;
// Reset the selected quote to null
selectedQuote = null;
}
@ -66,22 +87,43 @@ namespace WF_WebAdmin.Pages
ClosePopup();
}*/
/// <summary>
/// Handles the event when the delete action is triggered for a quote.
/// This method sets the selected quote to the one passed as a parameter and displays the delete confirmation popup.
/// </summary>
/// <param name="q">The quote that is being deleted.</param>
private void OnDelete(Quote q)
{
// Set the selected quote to the one passed in
selectedQuote = q;
// Display the delete confirmation popup
showPopupDelete = true;
}
/// <summary>
/// Removes the selected quote by calling the remove service and updates the quote list.
/// This method checks if a quote is selected. If so, it removes the quote using the `QuoteService`, clears the selected quote,
/// and fetches the updated list of quotes. It also closes the delete confirmation popup after the operation.
/// </summary>
private async void RemoveQuote()
{
// Check if a quote is selected for removal
if (selectedQuote != null)
{
// Remove the selected quote using the QuoteService
await QuoteService.removeQuote(selectedQuote);
selectedQuote= null;
// Clear the selected quote after removal
selectedQuote = null;
// Update the quotes list by fetching the latest quotes data
var response = await QuoteService.getSomeQuote(MaxValue, page);
quotes = response.ToArray();
}
showPopupDelete= false;
// Close the delete confirmation popup
showPopupDelete = false;
}
}
}

@ -20,39 +20,73 @@ namespace WF_WebAdmin.Pages
public NavigationManager NavigationManager { get; set; }
[Inject]
public IQuizService QuizService { get; set; }
protected override async Task OnInitializedAsync()
{
quizzes = await QuizService.getQuizzesToValidate();
}
private void OnValidButton(Quiz quiz)
{
ValidateQuiz(quiz);
}
private void ValidateQuiz(Quiz quiz)
{
Console.WriteLine($"Quiz {quiz.Id} validated!");
Quiz newQuiz = quiz;
newQuiz.IsValid = true;
// Mis à jour de l'état du quiz
QuizService.updateQuiz(quiz);
}
private void OnRejectButton(Quiz quiz)
{
RejectQuiz(quiz);
}
private void RejectQuiz(Quiz quiz)
{
Console.WriteLine($"Quiz {quiz.Id} rejected!");
QuizService.removeQuiz(quiz.Id);
public IQuizService QuizService { get; set; }
/// <summary>
/// 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.
/// </summary>
protected override async Task OnInitializedAsync()
{
// Fetch quizzes that need validation
quizzes = await QuizService.getQuizzesToValidate();
}
/// <summary>
/// Handles the event when the "Validate" button is clicked for a quiz.
/// This method calls the `ValidateQuiz` method, passing the specified quiz for validation.
/// </summary>
/// <param name="quiz">The quiz that is being validated.</param>
private void OnValidButton(Quiz quiz)
{
// Call the ValidateQuiz method to validate the quiz
ValidateQuiz(quiz);
}
/// <summary>
/// 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.
/// </summary>
/// <param name="quiz">The quiz that is being validated.</param>
private void ValidateQuiz(Quiz quiz)
{
// Log the validation action to the console
Console.WriteLine($"Quiz {quiz.Id} validated!");
// Create a new quiz instance (or modify the existing one)
Quiz newQuiz = quiz;
newQuiz.IsValid = true;
// Update the quiz state in the QuizService
QuizService.updateQuiz(quiz);
}
/// <summary>
/// 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.
/// </summary>
/// <param name="quiz">The quiz that is being rejected.</param>
private void OnRejectButton(Quiz quiz)
{
// Call the RejectQuiz method to reject the quiz
RejectQuiz(quiz);
}
/// <summary>
/// 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.
/// </summary>
/// <param name="quiz">The quiz that is being rejected.</param>
private void RejectQuiz(Quiz quiz)
{
// Log the rejection action to the console
Console.WriteLine($"Quiz {quiz.Id} rejected!");
// Remove the rejected quiz from the QuizService
QuizService.removeQuiz(quiz.Id);
}
}
}

@ -21,11 +21,17 @@ namespace WF_WebAdmin.Pages
public HttpClient Http { get; set; }
[Inject]
public NavigationManager NavigationManager { get; set; }
protected override async Task OnInitializedAsync()
{
quotes = await Http.GetFromJsonAsync<Quote[]>($"{NavigationManager.BaseUri}fake-dataQuote.json");
public NavigationManager NavigationManager { get; set; }
/// <summary>
/// Initializes the component asynchronously by fetching a list of quotes from a JSON file.
/// This method makes an asynchronous HTTP request to retrieve an array of `Quote` objects from a specified JSON file
/// located at the base URI, and then assigns the result to the `quotes` variable.
/// </summary>
protected override async Task OnInitializedAsync()
{
// Fetch the list of quotes from the JSON file located at the base URI
quotes = await Http.GetFromJsonAsync<Quote[]>($"{NavigationManager.BaseUri}fake-dataQuote.json");
}
}
}

Loading…
Cancel
Save