|
|
|
@ -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<Edit> 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<Character> charac = new List<Character>();
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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`.
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <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)
|
|
|
|
|
{
|
|
|
|
|
// 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<Edit> 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<Character> charac = new List<Character>();
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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 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");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <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)
|
|
|
|
|
{
|
|
|
|
|
// 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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|