using Blazorise;
using FoodsharingSiegen.Contracts.Entity;
using Microsoft.AspNetCore.Components;
namespace FoodsharingSiegen.Server.Dialogs
{
///
/// The add prospect modal class (a. beging, 31.05.2022)
///
public partial class AddProspectModal
{
#region Parameters
///
/// Gets or sets the value of the on add (ab)
///
[Parameter]
public EventCallback OnAdd { get; set; }
///
/// Gets or sets the value of the on update (ab)
///
[Parameter]
public EventCallback OnUpdate { get; set; }
#endregion
#region Private Properties
///
/// Gets or sets the value of the header (ab)
///
private string? Header { get; set; }
///
/// Gets or sets the value of the is update mode (ab)
///
private bool IsUpdateMode { get; set; }
///
/// Gets or sets the value of the modal reference (ab)
///
private Modal ModalReference { get; set; } = null!;
///
/// Gets or sets the value of the prospect (ab)
///
private Prospect Prospect { get; set; } = new();
///
/// Gets or sets the value of the save button text (ab)
///
private string? SaveButtonText { get; set; }
#endregion
#region Public Method Show
///
/// Shows this instance (a. beging, 31.05.2022)
///
public async Task Show()
{
Prospect = new Prospect();
Header = "Neuling hinzufügen";
SaveButtonText = "Hinzufügen";
await ModalReference.Show();
}
///
/// Shows the prospect (a. beging, 31.05.2022)
///
/// The prospect
public async Task Show(Prospect? prospect)
{
if (prospect == null) return;
Prospect = prospect;
IsUpdateMode = true;
Header = $"{Prospect.Name} bearbeiten";
SaveButtonText = "Speichern";
await ModalReference.Show();
}
#endregion
#region Private Method SaveClick
///
/// Saves the click (a. beging, 31.05.2022)
///
private async Task SaveClick()
{
if (IsUpdateMode)
await OnUpdate.InvokeAsync(Prospect);
else
await OnAdd.InvokeAsync(Prospect);
await ModalReference.Hide();
}
#endregion
}
}