Rename InteractionDialog
This commit is contained in:
151
FoodsharingSiegen.Server/Dialogs/InteractionDialog.razor.cs
Normal file
151
FoodsharingSiegen.Server/Dialogs/InteractionDialog.razor.cs
Normal file
@@ -0,0 +1,151 @@
|
||||
using Blazorise;
|
||||
using FoodsharingSiegen.Contracts.Entity;
|
||||
using FoodsharingSiegen.Server.BaseClasses;
|
||||
using FoodsharingSiegen.Server.Data.Service;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace FoodsharingSiegen.Server.Dialogs
|
||||
{
|
||||
public partial class InteractionDialog : FsBase
|
||||
{
|
||||
#region Dependencies
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value of the prospect service (ab)
|
||||
/// </summary>
|
||||
[Inject]
|
||||
public ProspectService ProspectService { get; set; } = null!;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Parameters
|
||||
|
||||
[Parameter]
|
||||
public string? InfoName { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public Interaction Interaction { get; set; } = new();
|
||||
|
||||
[Parameter]
|
||||
public Func<Task>? OnSuccess { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool ShowAlert { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool ShowInfo { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool ShowNotNeeded { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Method ShowAsync
|
||||
|
||||
/// <summary>
|
||||
/// Displays a modal dialog for adding an interaction with configurable settings based on the interaction type and associated prospect ID.
|
||||
/// </summary>
|
||||
/// <param name="modalService">
|
||||
/// The modal service used to display the modal dialog.
|
||||
/// </param>
|
||||
/// <param name="onSuccess">
|
||||
/// Callback to be invoked upon successful addition of an interaction
|
||||
/// </param>
|
||||
/// <param name="type">
|
||||
/// The type of interaction to be added.
|
||||
/// </param>
|
||||
/// <param name="prospectId">
|
||||
/// The unique identifier of the prospect associated with the interaction.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// A task representing the asynchronous operation of showing the modal dialog.
|
||||
/// </returns>
|
||||
public static async Task ShowAsync(IModalService modalService, Func<Task> onSuccess, InteractionType type, Guid prospectId)
|
||||
{
|
||||
var headerText = type switch
|
||||
{
|
||||
InteractionType.EinAb => "Einführung eintragen",
|
||||
InteractionType.Welcome => "Begrüßung eintragen",
|
||||
InteractionType.IdCheck => "Ausweisprüfung eintragen",
|
||||
InteractionType.PrintPass => "FS-Ausweis (Print)",
|
||||
InteractionType.PdfPass => "FS-Ausweis (PDF)",
|
||||
InteractionType.Verify => "Verifizierung eintragen",
|
||||
InteractionType.Complete => "Als fertig markieren",
|
||||
InteractionType.StepInBriefing => $"Neulingstreffen absolviert",
|
||||
InteractionType.ReleasedForVerification => "Zur Verifizierung freigegeben",
|
||||
_ => "Neuer Eintrag"
|
||||
};
|
||||
|
||||
var showInfo = type switch
|
||||
{
|
||||
InteractionType.EinAb => true,
|
||||
InteractionType.Complete => true,
|
||||
InteractionType.IdCheck => true,
|
||||
InteractionType.PrintPass => true,
|
||||
InteractionType.PdfPass => true,
|
||||
InteractionType.ReleasedForVerification => true,
|
||||
_ => false
|
||||
};
|
||||
|
||||
var infoName = type switch
|
||||
{
|
||||
InteractionType.EinAb => "Welcher Betrieb?",
|
||||
InteractionType.ReleasedForVerification => "Hinweis",
|
||||
_ => "Kommentar"
|
||||
};
|
||||
|
||||
var showAlert = type switch
|
||||
{
|
||||
InteractionType.EinAb => true,
|
||||
InteractionType.IdCheck => true,
|
||||
_ => false
|
||||
};
|
||||
|
||||
var showNotNeeded = type switch
|
||||
{
|
||||
InteractionType.PrintPass => true,
|
||||
InteractionType.PdfPass => true,
|
||||
_ => false
|
||||
};
|
||||
|
||||
var interaction = new Interaction
|
||||
{
|
||||
Type = type,
|
||||
Date = DateTime.UtcNow,
|
||||
ProspectID = prospectId
|
||||
};
|
||||
|
||||
await modalService.Show<InteractionDialog>(headerText, parameter =>
|
||||
{
|
||||
parameter.Add(nameof(Interaction), interaction);
|
||||
parameter.Add(nameof(ShowInfo), showInfo);
|
||||
parameter.Add(nameof(InfoName), infoName);
|
||||
parameter.Add(nameof(ShowAlert), showAlert);
|
||||
parameter.Add(nameof(ShowNotNeeded), showNotNeeded);
|
||||
parameter.Add(nameof(OnSuccess), onSuccess);
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Method AddInteractionAsync
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new interaction for the current user using the ProspectService and hides the modal.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A task representing the asynchronous operation.
|
||||
/// </returns>
|
||||
private async Task AddInteractionAsync()
|
||||
{
|
||||
Interaction.UserID = CurrentUser.Id;
|
||||
|
||||
var addR = await ProspectService.AddInteraction(Interaction);
|
||||
if (addR.Success && OnSuccess != null) await OnSuccess.Invoke();
|
||||
|
||||
await ModalService.Hide();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user