using FoodsharingSiegen.Contracts.Entity; using FoodsharingSiegen.Contracts.Model; using FoodsharingSiegen.Server.Data.Service; using FoodsharingSiegen.Server.Dialogs; using Microsoft.AspNetCore.Components; namespace FoodsharingSiegen.Server.Pages { /// /// The prospects class (a. beging, 11.04.2022) /// public partial class Prospects { #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 interaction modal (ab) /// private AddInteractionModal? InteractionModal { get; set; } /// /// Gets or sets the value of the prospect list (ab) /// private List? ProspectList { get; set; } /// /// Gets or sets the value of the users (ab) /// private List? Users { get; set; } #endregion #region Override InitializeDataAsync /// protected override async Task InitializeDataAsync() { // Load prospects await LoadProspects(); // Load users var getUsersR = await UserService.GetUsersAsync(); if (getUsersR.Success) Users = getUsersR.Data; } #endregion #region Private Method CreateProspectAsync /// /// Asynchronously creates a new prospect by displaying the AddProspectModal dialog and refreshing the prospect list. /// /// A task that represents the asynchronous operation. private async Task CreateProspectAsync() { await EditProspectDialog.ShowAsync(ModalService, LoadProspects); } #endregion #region Private Method LoadProspects /// /// Loads the prospects (a. beging, 11.04.2022) /// private async Task LoadProspects() { var parameter = new GetProspectsParameter { CannotHaveInteractions = [InteractionType.Complete, InteractionType.Verify, InteractionType.ReleasedForVerification] }; var prospectsR = await ProspectService.GetProspectsAsync(parameter); if (prospectsR.Success) ProspectList = prospectsR.Data; await InvokeAsync(StateHasChanged); } #endregion #region Private Method RemoveInteractionAsync /// /// Removes the interaction using the specified arg (a. beging, 11.04.2022) /// /// The arg private async Task RemoveInteractionAsync(Guid arg) { var confirm = await Message.Confirm("Interaktion wirklich löschen?", "Bestätigen", o => { o.ConfirmButtonText = "Ja, wirklich!"; o.CancelButtonText = "Abbrechen"; o.ShowMessageIcon = false; }); if (confirm) { await ProspectService.RemoveInteraction(arg); await LoadProspects(); } await InvokeAsync(StateHasChanged); } #endregion } }