From 6b6a8599821089b309ea5a936679aba68fa3bbe8 Mon Sep 17 00:00:00 2001 From: Louis GUICHARD-MONTGUERS Date: Sat, 8 Feb 2025 19:24:37 +0100 Subject: [PATCH] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'WF-WebAdmin/WF-Web?= =?UTF-8?q?Admin/Pages/DeleteUser.razor.cs'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WF-WebAdmin/Pages/DeleteUser.razor.cs | 216 +++++++++--------- 1 file changed, 108 insertions(+), 108 deletions(-) diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs index 6d54c06..4008bf9 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs @@ -1,7 +1,7 @@ using Blazorise.DataGrid; using Microsoft.AspNetCore.Components; using Microsoft.Extensions.Configuration.UserSecrets; -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Localization; using System.Collections.Generic; using WF_WebAdmin.Model; @@ -11,12 +11,12 @@ namespace WF_WebAdmin.Pages { public partial class DeleteUser { - [Inject] - public ILogger Logger { get; set; } + [Inject] + public ILogger Logger { get; set; } + + private List users; - private List users; - - private bool showDeletePopup = false; + private bool showModifyPopup = false; private User userToDelete = null; private User selectedUser; @@ -37,180 +37,180 @@ namespace WF_WebAdmin.Pages [Inject] private IUserService userService { get; set; } - [Inject] + [Inject] public IStringLocalizer Localizer { get; set; } - /// - /// 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). - /// + /// + /// 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). + /// 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. + // 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); } - - - /// - /// 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. - /// - /// The event arguments containing pagination details (page size and page number) and a cancellation token. + + + /// + /// 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. + /// + /// The event arguments containing pagination details (page size and page number) and a cancellation token. private async Task OnReadData(DataGridReadDataEventArgs e) { - // If the cancellation token is requested, exit the method without processing the request. + // 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. + // 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 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(response.ToArray()); // Store the retrieved users in the users list - page = e.Page; // Update the current page number + totalItem = await userService.getNbUser(); // Get the total number of users + users = new List(response.ToArray()); // Store the retrieved users in the users list + page = e.Page; // Update the current page number } } // ------- Popup remove user ------- - - /// - /// 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. - /// - /// The user to be deleted, which is passed to the method for confirmation. + + /// + /// 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. + /// + /// The user to be deleted, which is passed to the method for confirmation. 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 + // 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 } - - /// - /// 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. - /// - /// The user whose information is to be modified, passed to the method for confirmation. + + /// + /// 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. + /// + /// The user whose information is to be modified, passed to the method for confirmation. 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 + // 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 } - - /// - /// 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. - /// + + /// + /// 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. + /// private async Task RemoveUser() { - // Check if there is a user to delete + // Check if there is a user to delete if (userToDelete != null) { - // Remove the selected user from the system using the user service + // Remove the selected user from the system using the user service LoggerSaveStub.Log(Logger, LogLevel.Information, $"Delete user {userToDelete.Name}"); await userService.removeUser(userToDelete); - - // Close the confirmation popup after the deletion + + // Close the confirmation popup after the deletion ClosePopup(); - - // Refresh the list of users by fetching the updated data from the user service + + // 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 + + // Update the users list with the latest data users = new List(response.ToArray()); } } - - /// - /// 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. - /// + + /// + /// 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. + /// private async Task ModifyUser() { - // Update the selected user's information using the user service + // Update the selected user's information using the user service LoggerSaveStub.Log(Logger, LogLevel.Information, $"Modification of user {selectedUser.Name}"); await userService.updateUser(selectedUser); - - // Close the modification popup after the update is complete + + // Close the modification popup after the update is complete ClosePopup(); } - - /// - /// 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. - /// + + /// + /// 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. + /// 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) + // 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 ------- - /// - /// 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. - /// - /// The user to be promoted to admin, passed to the method for confirmation. + /// + /// 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. + /// + /// The user to be promoted to admin, passed to the method for confirmation. 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 + // 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 } - /// - /// 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. - /// + /// + /// 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. + /// private async Task setAdmin() { - // Check if the user is not already an admin + // Check if the user is not already an admin if (!userToAdmin.IsAdmin) { - // Promote the user to admin - LoggerSaveStub.Log(Logger, LogLevel.Information, $"User {userToAdmin.Name} is now administrator"); + // Promote the user to admin + LoggerSaveStub.Log(Logger, LogLevel.Information, $"User {userToAdmin.Name} is now administrator"); userToAdmin.IsAdmin = true; - await userService.updateUser(userToAdmin); // Update the user status in the service - ClosePopup(); // Close the confirmation popup + 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 - LoggerSaveStub.Log(Logger, LogLevel.Information, $"User {userToAdmin.Name} is no longer an administator"); + // Demote the user from admin to normal user + LoggerSaveStub.Log(Logger, LogLevel.Information, $"User {userToAdmin.Name} is no longer an administator"); userToAdmin.IsAdmin = false; - await userService.updateUser(userToAdmin); // Update the user status in the service - ClosePopup(); // Close the confirmation popup + await userService.updateUser(userToAdmin); // Update the user status in the service + ClosePopup(); // Close the confirmation popup } }