using FoodsharingSiegen.Contracts;
using FoodsharingSiegen.Contracts.Entity;
using FoodsharingSiegen.Contracts.Enums;
using FoodsharingSiegen.Contracts.Helper;
using FoodsharingSiegen.Contracts.Model;
using FoodsharingSiegen.Server.Data.Service;
using FoodsharingSiegen.Server.Dialogs;
using Microsoft.AspNetCore.Components;
namespace FoodsharingSiegen.Server.Pages
{
///
/// The prospects done class (a. beging, 07.02.2023)
///
public partial class ProspectsAll
{
#region Dependencies
///
/// Gets or sets the value of the prospect service (ab)
///
[Inject]
public ProspectService ProspectService { get; set; } = null!;
///
/// Gets or sets the value of the user service (ab)
///
[Inject]
public UserService UserService { get; set; } = null!;
#endregion
#region Private Properties
private ProspectFilter Filter { get; set; } = new();
///
/// Gets or sets the value of the prospect list (ab)
///
private List? ProspectList { get; set; }
#endregion
#region Override InitializeDataAsync
///
protected override async Task InitializeDataAsync()
{
if(!CurrentUser.IsInGroup(UserGroup.WelcomeTeam, UserGroup.Ambassador)) NavigationManager.NavigateTo("/");
// Load Filter
var filter = await LocalStorageService.GetItem(StorageKeys.ProspectFilter);
if (filter != null) Filter = filter;
// Load prospects
await LoadProspects();
}
#endregion
#region Private Method FilterChangedAsync
///
/// Updates the current filter with the specified ProspectFilter object.
///
/// The ProspectFilter object containing the updated filter criteria.
/// A task that represents the asynchronous operation.
private async Task FilterChangedAsync(ProspectFilter arg)
{
Filter = arg;
await LocalStorageService.SetItem(StorageKeys.ProspectFilter, Filter);
}
#endregion
#region Private Method LoadProspects
///
/// Loads the prospects (a. beging, 11.04.2022)
///
private async Task LoadProspects()
{
var parameter = new GetProspectsParameter
{
IncludeDeleted = true
};
var prospectsR = await ProspectService.GetProspectsAsync(parameter);
if (prospectsR.Success) ProspectList = prospectsR.Data;
await InvokeAsync(StateHasChanged);
}
#endregion
}
}