Edit prospect
This commit is contained in:
@@ -10,6 +10,11 @@
|
|||||||
|
|
||||||
<div class="@divClass">
|
<div class="@divClass">
|
||||||
<h5 class="mb-0">
|
<h5 class="mb-0">
|
||||||
|
@if (CurrentUser.IsInGroup(UserGroup.WelcomeTeam, UserGroup.Ambassador))
|
||||||
|
{
|
||||||
|
<a href=""><i class="fa-solid fa-pen-to-square" @onclick="() => ProspectModal.Show(Prospect)" @onclick:preventDefault></i> </a>
|
||||||
|
}
|
||||||
|
|
||||||
@Prospect.Name
|
@Prospect.Name
|
||||||
<small style="font-size: .9rem; opacity: .7;">
|
<small style="font-size: .9rem; opacity: .7;">
|
||||||
<a class="invert" href="https://foodsharing.de/profile/@Prospect.FsId" target="_blank">Profil öffnen</a>
|
<a class="invert" href="https://foodsharing.de/profile/@Prospect.FsId" target="_blank">Profil öffnen</a>
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ namespace FoodsharingSiegen.Server.Controls
|
|||||||
|
|
||||||
[Parameter] public AddInteractionModal InteractionModal { get; set; } = null!;
|
[Parameter] public AddInteractionModal InteractionModal { get; set; } = null!;
|
||||||
|
|
||||||
|
[Parameter] public AddProspectModal ProspectModal { get; set; } = null!;
|
||||||
|
|
||||||
[Parameter] public EventCallback<Guid> RemoveInteraction { get; set; }
|
[Parameter] public EventCallback<Guid> RemoveInteraction { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -55,21 +55,6 @@ namespace FoodsharingSiegen.Server.Data.Service
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public async Task<OperationResult> RemoveInteraction(Guid interactionId)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Context.Interactions.Remove(new Interaction { Id = interactionId });
|
|
||||||
await Context.SaveChangesAsync();
|
|
||||||
|
|
||||||
return new OperationResult();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
return new OperationResult(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Public Method AddProspectAsync
|
#region Public Method AddProspectAsync
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -122,5 +107,60 @@ namespace FoodsharingSiegen.Server.Data.Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Public Method RemoveInteraction
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes the interaction using the specified interaction id (a. beging, 11.04.2022)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="interactionId">The interaction id</param>
|
||||||
|
/// <returns>A task containing the operation result</returns>
|
||||||
|
public async Task<OperationResult> RemoveInteraction(Guid interactionId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Context.Interactions.Remove(new Interaction { Id = interactionId });
|
||||||
|
await Context.SaveChangesAsync();
|
||||||
|
|
||||||
|
return new OperationResult();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return new OperationResult(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Public Method UpdateAsync
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates the prospect (a. beging, 11.04.2022)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="prospect">The prospect</param>
|
||||||
|
/// <returns>A task containing the operation result</returns>
|
||||||
|
public async Task<OperationResult> UpdateAsync(Prospect prospect)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var entityProspect = await Context.Prospects.FirstOrDefaultAsync(x => x.Id == prospect.Id);
|
||||||
|
if (entityProspect == null) return new OperationResult(new Exception("Prospect not found"));
|
||||||
|
|
||||||
|
entityProspect.Memo = prospect.Memo;
|
||||||
|
entityProspect.Name = prospect.Name;
|
||||||
|
entityProspect.FsId = prospect.FsId;
|
||||||
|
|
||||||
|
var saveR = await Context.SaveChangesAsync();
|
||||||
|
|
||||||
|
if(saveR < 1) return new OperationResult(new Exception("Fehler beim speichern"));
|
||||||
|
return new OperationResult();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return new OperationResult(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,17 +4,40 @@
|
|||||||
|
|
||||||
private Prospect Prospect { get; set; } = new();
|
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> OnAdd { get; set; }
|
||||||
|
|
||||||
|
[Parameter] public EventCallback<Prospect> OnUpdate { get; set; }
|
||||||
|
|
||||||
public async Task Show()
|
public async Task Show()
|
||||||
{
|
{
|
||||||
Prospect = new();
|
Prospect = new();
|
||||||
|
Header = "Neuling hinzufügen";
|
||||||
|
SaveButtonText = "Hinzufügen";
|
||||||
await ModalReference.Show();
|
await ModalReference.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task AddProspect()
|
public async Task Show(Prospect prospect)
|
||||||
{
|
{
|
||||||
|
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 OnAdd.InvokeAsync(Prospect);
|
||||||
|
|
||||||
await ModalReference.Hide();
|
await ModalReference.Hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,7 +46,7 @@
|
|||||||
<Modal @ref="@ModalReference">
|
<Modal @ref="@ModalReference">
|
||||||
<ModalContent Centered Size="ModalSize.Small">
|
<ModalContent Centered Size="ModalSize.Small">
|
||||||
<ModalHeader>
|
<ModalHeader>
|
||||||
<ModalTitle>Neuling hinzufügen</ModalTitle>
|
<ModalTitle>@Header</ModalTitle>
|
||||||
<CloseButton />
|
<CloseButton />
|
||||||
</ModalHeader>
|
</ModalHeader>
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
@@ -38,7 +61,7 @@
|
|||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
<Button Color="Color.Secondary" Clicked="ModalReference.Hide">Abbrechen</Button>
|
<Button Color="Color.Secondary" Clicked="ModalReference.Hide">Abbrechen</Button>
|
||||||
<Button Color="Color.Primary" Clicked="@AddProspect">Hinzufügen</Button>
|
<Button Color="Color.Primary" Clicked="@SaveClick">@SaveButtonText</Button>
|
||||||
</ModalFooter>
|
</ModalFooter>
|
||||||
</ModalContent>
|
</ModalContent>
|
||||||
</Modal>
|
</Modal>
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
<h4>Aktuell:</h4>
|
<h4>Aktuell:</h4>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<Repeater Items="@activeProspects">
|
<Repeater Items="@activeProspects">
|
||||||
<ProspectContainer Prospect="context" InteractionModal="InteractionModal" RemoveInteraction="@RemoveInteraction"></ProspectContainer>
|
<ProspectContainer Prospect="context" InteractionModal="InteractionModal" ProspectModal="ProspectModal" RemoveInteraction="@RemoveInteraction"></ProspectContainer>
|
||||||
</Repeater>
|
</Repeater>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
@@ -43,11 +43,11 @@
|
|||||||
<h4>Abgeschlossen:</h4>
|
<h4>Abgeschlossen:</h4>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<Repeater Items="@completedProspects">
|
<Repeater Items="@completedProspects">
|
||||||
<ProspectContainer Prospect="context" InteractionModal="InteractionModal" RemoveInteraction="@RemoveInteraction"></ProspectContainer>
|
<ProspectContainer Prospect="context" InteractionModal="InteractionModal" ProspectModal="ProspectModal" RemoveInteraction="@RemoveInteraction"></ProspectContainer>
|
||||||
</Repeater>
|
</Repeater>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
<AddProspectModal @ref="ProspectModal" OnAdd="OnAddProspect"></AddProspectModal>
|
<AddProspectModal @ref="ProspectModal" OnAdd="OnAddProspect" OnUpdate="OnUpdateProspect"></AddProspectModal>
|
||||||
<AddInteractionModal @ref="InteractionModal" OnAdd="OnAddInteraction" Users="Users"></AddInteractionModal>
|
<AddInteractionModal @ref="InteractionModal" OnAdd="OnAddInteraction" Users="Users"></AddInteractionModal>
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using Blazorise;
|
using Blazorise;
|
||||||
using FoodsharingSiegen.Contracts.Entity;
|
using FoodsharingSiegen.Contracts.Entity;
|
||||||
using FoodsharingSiegen.Server.Data.Service;
|
using FoodsharingSiegen.Server.Data.Service;
|
||||||
using FoodsharingSiegen.Server.Dialogs;
|
using FoodsharingSiegen.Server.Dialogs;
|
||||||
@@ -6,18 +6,60 @@ using Microsoft.AspNetCore.Components;
|
|||||||
|
|
||||||
namespace FoodsharingSiegen.Server.Pages
|
namespace FoodsharingSiegen.Server.Pages
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The prospects class (a. beging, 11.04.2022)
|
||||||
|
/// </summary>
|
||||||
public partial class Prospects
|
public partial class Prospects
|
||||||
{
|
{
|
||||||
|
#region Dependencies (Injected)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the value of the message service (ab)
|
||||||
|
/// </summary>
|
||||||
[Inject] IMessageService MessageService { get; set; }
|
[Inject] IMessageService MessageService { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the value of the prospect service (ab)
|
||||||
|
/// </summary>
|
||||||
[Inject] public ProspectService ProspectService { get; set; } = null!;
|
[Inject] public ProspectService ProspectService { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the value of the user service (ab)
|
||||||
|
/// </summary>
|
||||||
[Inject] public UserService UserService { get; set; } = null!;
|
[Inject] public UserService UserService { get; set; } = null!;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the value of the interaction modal (ab)
|
||||||
|
/// </summary>
|
||||||
|
public AddInteractionModal InteractionModal { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the value of the prospect list (ab)
|
||||||
|
/// </summary>
|
||||||
public List<Prospect>? ProspectList { get; set; }
|
public List<Prospect>? ProspectList { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the value of the prospect modal (ab)
|
||||||
|
/// </summary>
|
||||||
public AddProspectModal ProspectModal { get; set; } = null!;
|
public AddProspectModal ProspectModal { get; set; } = null!;
|
||||||
public AddInteractionModal InteractionModal { get; set; }
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the value of the users (ab)
|
||||||
|
/// </summary>
|
||||||
public List<User>? Users { get; set; }
|
public List<User>? Users { get; set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Override OnAfterRenderAsync
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ons the after render using the specified first render (a. beging, 11.04.2022)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="firstRender">The first render</param>
|
||||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||||
{
|
{
|
||||||
if (firstRender)
|
if (firstRender)
|
||||||
@@ -28,6 +70,13 @@ namespace FoodsharingSiegen.Server.Pages
|
|||||||
await base.OnAfterRenderAsync(firstRender);
|
await base.OnAfterRenderAsync(firstRender);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Override OnInitializedAsync
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ons the initialized (a. beging, 11.04.2022)
|
||||||
|
/// </summary>
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
var getUsersR = await UserService.GetUsersAsync();
|
var getUsersR = await UserService.GetUsersAsync();
|
||||||
@@ -37,6 +86,13 @@ namespace FoodsharingSiegen.Server.Pages
|
|||||||
await base.OnInitializedAsync();
|
await base.OnInitializedAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Private Method LoadProspects
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Loads the prospects (a. beging, 11.04.2022)
|
||||||
|
/// </summary>
|
||||||
private async Task LoadProspects()
|
private async Task LoadProspects()
|
||||||
{
|
{
|
||||||
var prospectsR = await ProspectService.GetProspectsAsync();
|
var prospectsR = await ProspectService.GetProspectsAsync();
|
||||||
@@ -45,18 +101,56 @@ namespace FoodsharingSiegen.Server.Pages
|
|||||||
await InvokeAsync(StateHasChanged);
|
await InvokeAsync(StateHasChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task OnAddProspect(Prospect arg)
|
#endregion
|
||||||
{
|
|
||||||
var addProspectR = await ProspectService.AddProspectAsync(arg);
|
|
||||||
if (addProspectR.Success) await LoadProspects();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#region Private Method OnAddInteraction
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ons the add interaction using the specified arg (a. beging, 11.04.2022)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="arg">The arg</param>
|
||||||
private async Task OnAddInteraction(Interaction arg)
|
private async Task OnAddInteraction(Interaction arg)
|
||||||
{
|
{
|
||||||
await ProspectService.AddInteraction(arg);
|
await ProspectService.AddInteraction(arg);
|
||||||
await LoadProspects();
|
await LoadProspects();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Private Method OnAddProspect
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ons the add prospect using the specified arg (a. beging, 11.04.2022)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="arg">The arg</param>
|
||||||
|
private async Task OnAddProspect(Prospect arg)
|
||||||
|
{
|
||||||
|
var addProspectR = await ProspectService.AddProspectAsync(arg);
|
||||||
|
if (addProspectR.Success) await LoadProspects();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Private Method OnUpdateProspect
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ons the update prospect using the specified prospect (a. beging, 11.04.2022)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="prospect">The prospect</param>
|
||||||
|
private async Task OnUpdateProspect(Prospect prospect)
|
||||||
|
{
|
||||||
|
var updateProspectR = await ProspectService.UpdateAsync(prospect);
|
||||||
|
if (updateProspectR.Success) await LoadProspects();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Private Method RemoveInteraction
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes the interaction using the specified arg (a. beging, 11.04.2022)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="arg">The arg</param>
|
||||||
private async Task RemoveInteraction(Guid arg)
|
private async Task RemoveInteraction(Guid arg)
|
||||||
{
|
{
|
||||||
var confirm = await MessageService.Confirm("Interaktion wirklich löschen?", "Bestätigen", o => {
|
var confirm = await MessageService.Confirm("Interaktion wirklich löschen?", "Bestätigen", o => {
|
||||||
@@ -70,7 +164,8 @@ namespace FoodsharingSiegen.Server.Pages
|
|||||||
await ProspectService.RemoveInteraction(arg);
|
await ProspectService.RemoveInteraction(arg);
|
||||||
await LoadProspects();
|
await LoadProspects();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user