Files
FoodsharingOnboarding/FoodsharingSiegen.Server/Dialogs/AddProspectModal.razor.cs
2022-05-31 17:00:32 +02:00

103 lines
2.8 KiB
C#

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