Consolidated repeated methods for interaction/user deletion into reusable components to improve maintainability. Introduced a `ConfirmDialog` for consistent confirmation UI and streamlined associated logic across pages. Removed redundant methods and enhanced admin-specific page security checks.
126 lines
3.7 KiB
C#
126 lines
3.7 KiB
C#
using Blazorise;
|
|
using FoodsharingSiegen.Contracts.Entity;
|
|
using FoodsharingSiegen.Contracts.Model;
|
|
using FoodsharingSiegen.Server.Auth;
|
|
using FoodsharingSiegen.Server.Data.Service;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace FoodsharingSiegen.Server.BaseClasses
|
|
{
|
|
/// <summary>
|
|
/// The fs base class (a. beging, 08.04.2022)
|
|
/// </summary>
|
|
/// <seealso cref="ComponentBase" />
|
|
public class FsBase : ComponentBase
|
|
{
|
|
#region Dependencies
|
|
|
|
[Inject]
|
|
private IOptions<AppSettings> AppSettingsContainer { get; set; } = null!;
|
|
|
|
/// <summary>
|
|
/// Gets or sets the value of the audit service (ab)
|
|
/// </summary>
|
|
[Inject]
|
|
private AuditService AuditService { get; set; } = null!;
|
|
|
|
/// <summary>
|
|
/// Gets or sets the value of the auth service (ab)
|
|
/// </summary>
|
|
[Inject]
|
|
protected AuthService AuthService { get; set; } = null!;
|
|
|
|
/// <summary>
|
|
/// Gets or sets the modal service for handling modals within the application
|
|
/// </summary>
|
|
[Inject]
|
|
protected IModalService ModalService { get; set; } = null!;
|
|
|
|
/// <summary>
|
|
/// Gets or sets the value of the navigation manager (ab)
|
|
/// </summary>
|
|
[Inject]
|
|
protected NavigationManager NavigationManager { get; set; } = null!;
|
|
|
|
/// <summary>
|
|
/// Gets or sets the value of the notification (ab)
|
|
/// </summary>
|
|
[Inject]
|
|
protected INotificationService Notification { get; set; } = null!;
|
|
|
|
#endregion
|
|
|
|
#region Protected Properties
|
|
|
|
/// Provides application-specific settings used to configure the behavior and display of the application.
|
|
/// The AppSettings class encapsulates information such as the application title and other configurable parameters.
|
|
protected AppSettings AppSettings => AppSettingsContainer.Value;
|
|
|
|
/// <summary>
|
|
/// Gets the value of the current user (ab)
|
|
/// </summary>
|
|
protected User CurrentUser => AuthService?.User ?? new User();
|
|
|
|
#endregion
|
|
|
|
#region Private Fields
|
|
|
|
private bool _dataInitialized;
|
|
|
|
#endregion
|
|
|
|
#region Override OnInitializedAsync
|
|
|
|
/// <summary>
|
|
/// Ons the initialized (a. beging, 11.04.2022)
|
|
/// </summary>
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await AuthService.Initialize();
|
|
await base.OnInitializedAsync();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Override SetParametersAsync
|
|
|
|
/// <inheritdoc />
|
|
public override async Task SetParametersAsync(ParameterView parameters)
|
|
{
|
|
parameters.SetParameterProperties(this);
|
|
|
|
if (!_dataInitialized)
|
|
{
|
|
_dataInitialized = true;
|
|
await InitializeDataAsync();
|
|
}
|
|
|
|
// Da die Parameter bereits gesetzt wurden, kann die Basisklasse am Ende aufgerufen werden.
|
|
await base.SetParametersAsync(ParameterView.Empty);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Protected Method InitializeDataAsync
|
|
|
|
/// <summary>
|
|
/// Initialize data here, Database Actions belong here
|
|
/// </summary>
|
|
protected virtual async Task InitializeDataAsync() => await Task.CompletedTask;
|
|
|
|
#endregion
|
|
|
|
#region Protected Method RefreshState
|
|
|
|
/// <summary>
|
|
/// Refreshes the state (a. beging, 21.05.2022)
|
|
/// </summary>
|
|
protected async Task RefreshState()
|
|
{
|
|
await AuthService?.RefreshState()!;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |