Move edit prospect dialog logic
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
@using FoodsharingSiegen.Contracts.Entity
|
||||
|
||||
<Modal @ref="@ModalReference">
|
||||
<ModalContent Centered Size="ModalSize.Default">
|
||||
<ModalHeader>
|
||||
<ModalTitle>@Header</ModalTitle>
|
||||
<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>Info (optional)</FieldLabel>
|
||||
<TextEdit @bind-Text="Prospect.Memo" Placeholder="Beliebige Info"></TextEdit>
|
||||
</Field>
|
||||
|
||||
<Field>
|
||||
<Switch TValue="bool" @bind-Checked="Prospect.Warning">Achtung!</Switch>
|
||||
</Field>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button Color="Color.Primary" Clicked="@SaveClick">@SaveButtonText</Button>
|
||||
</ModalFooter>
|
||||
</ModalContent>
|
||||
</Modal>
|
||||
@@ -1,103 +0,0 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
28
FoodsharingSiegen.Server/Dialogs/EditProspectDialog.razor
Normal file
28
FoodsharingSiegen.Server/Dialogs/EditProspectDialog.razor
Normal file
@@ -0,0 +1,28 @@
|
||||
@using FoodsharingSiegen.Contracts.Entity
|
||||
@inherits FsBase
|
||||
|
||||
<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>Info (optional)</FieldLabel>
|
||||
<TextEdit @bind-Text="Prospect.Memo" Placeholder="Beliebige Info"></TextEdit>
|
||||
</Field>
|
||||
|
||||
<Field>
|
||||
<Switch TValue="bool" @bind-Checked="Prospect.Warning">Achtung!</Switch>
|
||||
</Field>
|
||||
|
||||
<Button Color="Color.Primary" Clicked="@SaveClick">@SaveButtonText</Button>
|
||||
106
FoodsharingSiegen.Server/Dialogs/EditProspectDialog.razor.cs
Normal file
106
FoodsharingSiegen.Server/Dialogs/EditProspectDialog.razor.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
using Blazorise;
|
||||
using FoodsharingSiegen.Contracts.Entity;
|
||||
using FoodsharingSiegen.Server.BaseClasses;
|
||||
using FoodsharingSiegen.Server.Data.Service;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace FoodsharingSiegen.Server.Dialogs
|
||||
{
|
||||
/// <summary>
|
||||
/// The add prospect modal class (a. beging, 31.05.2022)
|
||||
/// </summary>
|
||||
public partial class EditProspectDialog : 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
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value of the is update mode (ab)
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public bool IsUpdateMode { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public Func<Task>? OnSuccess { get; set; }
|
||||
|
||||
/// <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; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value of the prospect (ab)
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public Prospect Prospect { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value of the save button text (ab)
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string? SaveButtonText { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Method ShowAsync
|
||||
|
||||
/// <summary>
|
||||
/// Displays the AddProspectModal dialog asynchronously, allowing for the creation or editing of a prospect.
|
||||
/// </summary>
|
||||
/// <param name="modalService">The modal service used to display the dialog.</param>
|
||||
/// <param name="onSuccess">Callback to be invoked upon successful addition or update of a prospect.</param>
|
||||
/// <param name="prospect">The prospect to be edited, or null for creating a new prospect.</param>
|
||||
/// <returns>A task representing the asynchronous operation.</returns>
|
||||
public static async Task ShowAsync(IModalService modalService, Func<Task> onSuccess, Prospect? prospect = null)
|
||||
{
|
||||
await modalService.Show<EditProspectDialog>(prospect == null ? "Neuling hinzufügen" : $"{prospect.Name} bearbeiten", p =>
|
||||
{
|
||||
p.Add(nameof(Prospect), prospect ?? new Prospect());
|
||||
p.Add(nameof(IsUpdateMode), prospect != null);
|
||||
p.Add(nameof(SaveButtonText), prospect == null ? "Hinzufügen" : "Speichern");
|
||||
p.Add(nameof(OnSuccess), onSuccess);
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Method SaveClick
|
||||
|
||||
/// <summary>
|
||||
/// Saves the click (a. beging, 31.05.2022)
|
||||
/// </summary>
|
||||
private async Task SaveClick()
|
||||
{
|
||||
if (IsUpdateMode)
|
||||
{
|
||||
var updateR = await ProspectService.UpdateAsync(Prospect);
|
||||
if (updateR.Success && OnSuccess != null) await OnSuccess.Invoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
var addR = await ProspectService.AddProspectAsync(Prospect);
|
||||
if (addR.Success && OnSuccess != null) await OnSuccess.Invoke();
|
||||
}
|
||||
|
||||
await ModalService.Hide();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user