Mise à jour de 'WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor.cs'
continuous-integration/drone/push Build is passing Details

master
parent 5ad531d6bb
commit 611de18362

@ -1,100 +1,100 @@
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using System.Security.Claims; using System.Security.Claims;
using WF_WebAdmin.Model; using WF_WebAdmin.Model;
using WF_WebAdmin.Service; using WF_WebAdmin.Service;
namespace WF_WebAdmin.Pages namespace WF_WebAdmin.Pages
{ {
public partial class Edit public partial class Edit
{ {
[Parameter] [Parameter]
public int Id { get; set; } public int Id { get; set; }
[Inject] [Inject]
public ILogger<Edit> Logger { get; set; } public ILogger<Edit> Logger { get; set; }
[Inject] [Inject]
private IQuoteService quoteService { get; set; } private IQuoteService quoteService { get; set; }
[Inject] [Inject]
public NavigationManager NavigationManager { get; set; } public NavigationManager NavigationManager { get; set; }
private Quote q{ get; set; } private Quote q{ get; set; }
private QuoteModel quoteModel = new(); private QuoteModel quoteModel = new();
private List<Character> charac = new List<Character>(); private List<Character> charac = new List<Character>();
private List<Source> src = new List<Source>(); private List<Source> src = new List<Source>();
/// <summary> /// <summary>
/// Asynchronously initializes the component by loading data related to a quote. /// 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` /// 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. /// 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. /// It also loads additional data such as character and source information for the quote.
/// </summary> /// </summary>
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
// Fetch the quote data based on the provided ID. // Fetch the quote data based on the provided ID.
q = await quoteService.getOnequote(Id); q = await quoteService.getOnequote(Id);
// Populate the quoteModel with the data from the retrieved quote. // Populate the quoteModel with the data from the retrieved quote.
quoteModel.Content = q.Content; quoteModel.Content = q.Content;
quoteModel.Langue = q.Langue; quoteModel.Langue = q.Langue;
quoteModel.Charac = q.Charac; quoteModel.Charac = q.Charac;
quoteModel.TitleSrc = q.TitleSrc; quoteModel.TitleSrc = q.TitleSrc;
quoteModel.Id = q.Id; quoteModel.Id = q.Id;
quoteModel.Like = q.Like; quoteModel.Like = q.Like;
quoteModel.ImgPath = q.ImgPath; quoteModel.ImgPath = q.ImgPath;
quoteModel.DateSrc = q.DateSrc; quoteModel.DateSrc = q.DateSrc;
quoteModel.UserProposition = q.UserProposition; quoteModel.UserProposition = q.UserProposition;
quoteModel.IsValid = q.IsValid; quoteModel.IsValid = q.IsValid;
// Fetch additional data related to the quote, such as character and source. // Fetch additional data related to the quote, such as character and source.
charac = await quoteService.getChar(); charac = await quoteService.getChar();
src = await quoteService.getSrc(); src = await quoteService.getSrc();
} }
/// <summary> /// <summary>
/// Handles the submission of a valid form for updating a quote. /// 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, /// 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. /// and then calls the `quoteService.updateQuote` method to persist the changes.
/// After updating, it navigates to the "modifquote" page. /// After updating, it navigates to the "modifquote" page.
/// </summary> /// </summary>
protected async void HandleValidSubmit() protected async Task HandleValidSubmit()
{ {
// Update the properties of the selected quote (`q`) with the data from `quoteModel`. // Update the properties of the selected quote (`q`) with the data from `quoteModel`.
LoggerSaveStub.Log(Logger, LogLevel.Information, $"Editing the quote {q.Content}"); LoggerSaveStub.Log(Logger, LogLevel.Information, $"Editing the quote {q.Content}");
q.Content = quoteModel.Content; q.Content = quoteModel.Content;
q.Langue = quoteModel.Langue; q.Langue = quoteModel.Langue;
q.TitleSrc = quoteModel.TitleSrc; q.TitleSrc = quoteModel.TitleSrc;
q.Charac = quoteModel.Charac; q.Charac = quoteModel.Charac;
// Call the quote service to update the quote in the data source. // Call the quote service to update the quote in the data source.
await quoteService.updateQuote(q); await quoteService.updateQuote(q);
// Navigate to the "modifquote" page after updating the quote. // Navigate to the "modifquote" page after updating the quote.
NavigationManager.NavigateTo("modifquote"); NavigationManager.NavigateTo("modifquote");
} }
/// <summary> /// <summary>
/// Handles the language change event for the quote. /// Handles the language change event for the quote.
/// This method updates the `Langue` property of the `quoteModel` based on the selected language (`item`). /// 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. /// It only accepts "fr" (French) or "en" (English) as valid language options.
/// </summary> /// </summary>
/// <param name="item">The selected language ("fr" or "en") passed to the method.</param> /// <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> /// <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) private void OnlangChange(string item, object checkedValue)
{ {
// Check if the selected language is either "fr" or "en" // Check if the selected language is either "fr" or "en"
if (item == "fr" || item == "en") if (item == "fr" || item == "en")
{ {
// Update the Langue property of the quoteModel with the selected language // Update the Langue property of the quoteModel with the selected language
quoteModel.Langue = item; quoteModel.Langue = item;
} }
} }
} }
} }

Loading…
Cancel
Save