Display prospect memo

This commit is contained in:
Andre Beging
2022-05-31 17:00:32 +02:00
parent 3487cdcb58
commit e21c9a7b52
4 changed files with 132 additions and 54 deletions

View File

@@ -1,63 +1,30 @@
@using FoodsharingSiegen.Contracts.Entity
@code {
private Modal ModalReference { get; set; } = null!;
private Prospect Prospect { get; set; } = new();
private string? Header { get; set; }
private string? SaveButtonText { get; set; }
private bool IsUpdateMode { get; set; }
[Parameter] public EventCallback<Prospect> OnAdd { get; set; }
[Parameter] public EventCallback<Prospect> OnUpdate { get; set; }
public async Task Show()
{
Prospect = new Prospect();
Header = "Neuling hinzufügen";
SaveButtonText = "Hinzufügen";
await ModalReference.Show();
}
public async Task Show(Prospect? prospect)
{
if (prospect == null) return;
Prospect = prospect;
IsUpdateMode = true;
Header = $"{Prospect.Name} bearbeiten";
SaveButtonText = "Speichern";
await ModalReference.Show();
}
private async Task SaveClick()
{
if (IsUpdateMode)
await OnUpdate.InvokeAsync(Prospect);
else
await OnAdd.InvokeAsync(Prospect);
await ModalReference.Hide();
}
}
<Modal @ref="@ModalReference">
<ModalContent Centered Size="ModalSize.Small">
<ModalContent Centered Size="ModalSize.Default">
<ModalHeader>
<ModalTitle>@Header</ModalTitle>
<CloseButton />
<CloseButton/>
</ModalHeader>
<ModalBody>
<div class="row">
<div class="col">
<Field>
<FieldLabel>Name</FieldLabel>
<TextEdit @bind-Text="Prospect.Name"/>
</Field>
</div>
<div class="col">
<Field>
<FieldLabel>Foodsharing-ID</FieldLabel>
<NumericEdit TValue="int" @bind-Value="Prospect.FsId"></NumericEdit>
</Field>
</div>
</div>
<Field>
<FieldLabel>Name</FieldLabel>
<TextEdit @bind-Text="Prospect.Name" />
</Field>
<Field>
<FieldLabel>Foodsharing-ID</FieldLabel>
<NumericEdit TValue="int" @bind-Value="Prospect.FsId"></NumericEdit>
<FieldLabel>Memo (optional)</FieldLabel>
<TextEdit @bind-Text="Prospect.Memo" Placeholder="Beliebige Info"></TextEdit>
</Field>
</ModalBody>
<ModalFooter>

View File

@@ -0,0 +1,103 @@
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
}
}