From 611de183624cbb11f1758043f1300b364e39560a Mon Sep 17 00:00:00 2001 From: Louis GUICHARD-MONTGUERS Date: Sat, 8 Feb 2025 19:04:14 +0100 Subject: [PATCH] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'WF-WebAdmin/WF-Web?= =?UTF-8?q?Admin/Pages/Edit.razor.cs'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor.cs | 200 ++++++++++---------- 1 file changed, 100 insertions(+), 100 deletions(-) diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor.cs index 3f0ab80..dad1e46 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor.cs @@ -1,100 +1,100 @@ -using Microsoft.AspNetCore.Components; -using System.Security.Claims; -using WF_WebAdmin.Model; -using WF_WebAdmin.Service; - -namespace WF_WebAdmin.Pages -{ - public partial class Edit - { - [Parameter] - public int Id { get; set; } - - [Inject] - public ILogger Logger { get; set; } - - [Inject] - private IQuoteService quoteService { get; set; } - - [Inject] - public NavigationManager NavigationManager { get; set; } - - private Quote q{ get; set; } - - private QuoteModel quoteModel = new(); - - private List charac = new List(); - - private List src = new List(); - - - /// - /// 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. - /// - 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; - quoteModel.TitleSrc = q.TitleSrc; - quoteModel.Id = q.Id; - quoteModel.Like = q.Like; - quoteModel.ImgPath = q.ImgPath; - 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(); - } - - /// - /// 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. - /// - protected async void HandleValidSubmit() - { - // Update the properties of the selected quote (`q`) with the data from `quoteModel`. - LoggerSaveStub.Log(Logger, LogLevel.Information, $"Editing the quote {q.Content}"); - 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"); - } - - - - /// - /// 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. - /// - /// The selected language ("fr" or "en") passed to the method. - /// The checked value (unused in this method but may be used for other purposes). - private void OnlangChange(string item, object checkedValue) - { - // 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; - } - } - } -} +using Microsoft.AspNetCore.Components; +using System.Security.Claims; +using WF_WebAdmin.Model; +using WF_WebAdmin.Service; + +namespace WF_WebAdmin.Pages +{ + public partial class Edit + { + [Parameter] + public int Id { get; set; } + + [Inject] + public ILogger Logger { get; set; } + + [Inject] + private IQuoteService quoteService { get; set; } + + [Inject] + public NavigationManager NavigationManager { get; set; } + + private Quote q{ get; set; } + + private QuoteModel quoteModel = new(); + + private List charac = new List(); + + private List src = new List(); + + + /// + /// 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. + /// + 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; + quoteModel.TitleSrc = q.TitleSrc; + quoteModel.Id = q.Id; + quoteModel.Like = q.Like; + quoteModel.ImgPath = q.ImgPath; + 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(); + } + + /// + /// 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. + /// + protected async Task HandleValidSubmit() + { + // Update the properties of the selected quote (`q`) with the data from `quoteModel`. + LoggerSaveStub.Log(Logger, LogLevel.Information, $"Editing the quote {q.Content}"); + 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"); + } + + + + /// + /// 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. + /// + /// The selected language ("fr" or "en") passed to the method. + /// The checked value (unused in this method but may be used for other purposes). + private void OnlangChange(string item, object checkedValue) + { + // 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; + } + } + } +}