diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor.cs index f7b188f..bafd81b 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor.cs @@ -1,135 +1,135 @@ -using Blazorise.DataGrid; -using Microsoft.AspNetCore.Components; -using Microsoft.Extensions.Localization; -using Microsoft.Extensions.Logging; -using System.Security.Claims; -using WF_WebAdmin.Model; -using WF_WebAdmin.Service; - -namespace WF_WebAdmin.Pages -{ - public partial class ModifQuote - { - private Quote[] quotes; - - private int MaxValue = 5; - - private int totalItem; - - /*private bool showEditQuote = false;*/ - - private Quote? selectedQuote; - - private bool showPopupDelete = false; - - private int page = 1; - - [Inject] - public ILogger Logger { get; set; } - - [Inject] - public IStringLocalizer Localizer { get; set; } - - [Inject] - public IQuoteService QuoteService { get; set; } - - - /// - /// 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. - /// - /// The event arguments containing pagination details such as page size and page number. - private async Task OnReadData(DataGridReadDataEventArgs 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; - } - } - - /*private void OnEditButtonClicked(Quote quote) - { - if (selectedQuote == null) return; - selectedQuote = quote; - showEditQuote = true; - }*/ - - /// - /// Closes the open popups and resets any related states. - /// This method hides the delete confirmation popup and clears the selected quote. - /// - private void ClosePopup() - { - // Hide the delete confirmation popup - showPopupDelete = false; - - // Reset the selected quote to null - selectedQuote = null; - } - - /*private async Task EditQuote() - { - await QuoteService.updateQuote(selectedQuote); - selectedQuote = null; - ClosePopup(); - }*/ - - /// - /// 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. - /// - /// The quote that is being deleted. - private void OnDelete(Quote q) - { - // Set the selected quote to the one passed in - selectedQuote = q; - - // Display the delete confirmation popup - showPopupDelete = true; - } - - /// - /// 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. - /// - private async void RemoveQuote() - { - // Check if a quote is selected for removal - if (selectedQuote != null) - { - // Remove the selected quote using the QuoteService - LoggerSaveStub.Log(Logger, LogLevel.Information, $"The quote {selectedQuote.Content} has been deleted"); - await QuoteService.removeQuote(selectedQuote); - - // 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(); - } - - // Close the delete confirmation popup - showPopupDelete = false; - } - } -} +using Blazorise.DataGrid; +using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Logging; +using System.Security.Claims; +using WF_WebAdmin.Model; +using WF_WebAdmin.Service; + +namespace WF_WebAdmin.Pages +{ + public partial class ModifQuote + { + private Quote[] quotes; + + private int MaxValue = 5; + + private int totalItem; + + /*private bool showEditQuote = false;*/ + + private Quote? selectedQuote; + + private bool showPopupDelete = false; + + private int page = 1; + + [Inject] + public ILogger Logger { get; set; } + + [Inject] + public IStringLocalizer Localizer { get; set; } + + [Inject] + public IQuoteService QuoteService { get; set; } + + + /// + /// 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. + /// + /// The event arguments containing pagination details such as page size and page number. + private async Task OnReadData(DataGridReadDataEventArgs 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; + } + } + + /*private void OnEditButtonClicked(Quote quote) + { + if (selectedQuote == null) return; + selectedQuote = quote; + showEditQuote = true; + }*/ + + /// + /// Closes the open popups and resets any related states. + /// This method hides the delete confirmation popup and clears the selected quote. + /// + private void ClosePopup() + { + // Hide the delete confirmation popup + showPopupDelete = false; + + // Reset the selected quote to null + selectedQuote = null; + } + + /*private async Task EditQuote() + { + await QuoteService.updateQuote(selectedQuote); + selectedQuote = null; + ClosePopup(); + }*/ + + /// + /// 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. + /// + /// The quote that is being deleted. + private void OnDelete(Quote q) + { + // Set the selected quote to the one passed in + selectedQuote = q; + + // Display the delete confirmation popup + showPopupDelete = true; + } + + /// + /// 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. + /// + private async Task RemoveQuote() + { + // Check if a quote is selected for removal + if (selectedQuote != null) + { + // Remove the selected quote using the QuoteService + LoggerSaveStub.Log(Logger, LogLevel.Information, $"The quote {selectedQuote.Content} has been deleted"); + await QuoteService.removeQuote(selectedQuote); + + // 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(); + } + + // Close the delete confirmation popup + showPopupDelete = false; + } + } +}