Add RecordState handling for prospects and support soft deletion
Introduced the RecordState property to manage the state of prospects, enabling soft deletion and restoration. Updated related database migrations, UI interactions, and filtering logic to accommodate this addition. Also included automatic database migration at runtime to ensure schema compatibility.
This commit is contained in:
@@ -5,19 +5,34 @@
|
||||
var divClass = $"{CssClass} pc-main";
|
||||
if (Prospect is { Complete: true }) divClass += " complete";
|
||||
if (Prospect is { Warning: true }) divClass += " warning";
|
||||
if (Prospect is { RecordState: RecordState.Deleted }) divClass += " deleted";
|
||||
}
|
||||
|
||||
<div class="@divClass">
|
||||
<h5 class="mb-0">
|
||||
@if (CurrentUser.IsInGroup(UserGroup.WelcomeTeam, UserGroup.Ambassador))
|
||||
{
|
||||
<i class="fa-solid fa-pen-to-square mr-2" style="cursor: pointer; color: #64ae24;" @onclick="EditProspectAsync" @onclick:preventDefault></i>
|
||||
}
|
||||
|
||||
@Prospect?.Name
|
||||
<small style="font-size: .9rem; opacity: .7;">
|
||||
<a class="invert" href="@(CurrentUser.NetworkLink)/profile/@Prospect?.FsId" target="_blank">Profil öffnen</a>
|
||||
</small>
|
||||
<h5 class="mb-2 d-flex">
|
||||
<div class="flex-grow-1">
|
||||
@Prospect?.Name
|
||||
<small style="font-size: .9rem;">@Prospect?.FsId</small>
|
||||
</div>
|
||||
<div>
|
||||
@if (CurrentUser.IsInGroup(UserGroup.WelcomeTeam, UserGroup.Ambassador))
|
||||
{
|
||||
<i class="fa-solid fa-pen-to-square link mr-2" @onclick="EditProspectAsync" @onclick:preventDefault></i>
|
||||
}
|
||||
<a href="@(CurrentUser.NetworkLink)/profile/@Prospect?.FsId" target="_blank"><i class="fa-solid fa-eye"></i></a>
|
||||
@if (CurrentUser.IsInGroup(UserGroup.WelcomeTeam, UserGroup.Ambassador))
|
||||
{
|
||||
if (Prospect?.RecordState != RecordState.Deleted)
|
||||
{
|
||||
<i class="fa-solid fa-trash link ml-2" @onclick="DeleteProspectAsync" @onclick:preventDefault></i>
|
||||
}
|
||||
else if(CurrentUser.IsAdmin())
|
||||
{
|
||||
<i class="fa-solid fa-recycle link ml-2" @onclick="RestoreProspectAsync" @onclick:preventDefault></i>
|
||||
}
|
||||
|
||||
}
|
||||
</div>
|
||||
</h5>
|
||||
|
||||
@if (!string.IsNullOrWhiteSpace(Prospect?.Memo))
|
||||
|
||||
@@ -48,6 +48,26 @@ namespace FoodsharingSiegen.Server.Controls
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Method DeleteProspectAsync
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the currently selected prospect after user confirmation. This action is irreversible and will update the record state to "Deleted".
|
||||
/// </summary>
|
||||
/// <returns>A task that represents the asynchronous delete operation.</returns>
|
||||
private async Task DeleteProspectAsync()
|
||||
{
|
||||
if (Prospect == null) return;
|
||||
|
||||
await ConfirmDialog.ShowAsync(ModalService, $"⚠️ {Prospect.Name} löschen", $"Soll {Prospect.Name} mit der FS-ID {Prospect.FsId} wirklich gelöscht werden? Das kann nicht rückgängig gemacht werden!!", async () =>
|
||||
{
|
||||
Prospect.RecordState = RecordState.Deleted;
|
||||
var updateR = await ProspectService.UpdateAsync(Prospect);
|
||||
if (updateR.Success && OnDataChanged != null) await OnDataChanged();
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Method EditProspectAsync
|
||||
|
||||
private async Task EditProspectAsync()
|
||||
@@ -86,5 +106,25 @@ namespace FoodsharingSiegen.Server.Controls
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Method RestoreProspectAsync
|
||||
|
||||
/// <summary>
|
||||
/// Restores the currently selected prospect after user confirmation. This action will update the record state to "Default".
|
||||
/// </summary>
|
||||
/// <returns>A task that represents the asynchronous restore operation.</returns>
|
||||
private async Task RestoreProspectAsync()
|
||||
{
|
||||
if (Prospect == null) return;
|
||||
|
||||
await ConfirmDialog.ShowAsync(ModalService, $"{Prospect.Name} wiederherstellen", $"Soll {Prospect.Name} mit der FS-ID {Prospect.FsId} wiederhergestellt werden?", async () =>
|
||||
{
|
||||
Prospect.RecordState = RecordState.Default;
|
||||
var updateR = await ProspectService.UpdateAsync(Prospect);
|
||||
if (updateR.Success && OnDataChanged != null) await OnDataChanged();
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,20 @@
|
||||
box-shadow: 0 0 9px 4px rgba(214,100,23,0.87);
|
||||
}
|
||||
|
||||
.pc-main.deleted {
|
||||
-webkit-box-shadow: 0 0 9px 4px rgb(214 23 23 / 87%);
|
||||
-moz-box-shadow: 0 0 9px 4px rgb(214 23 23 / 87%);
|
||||
box-shadow: 0 0 9px 4px rgb(214 23 23 / 87%);
|
||||
}
|
||||
|
||||
.complete {
|
||||
background: #76ff003b;
|
||||
}
|
||||
|
||||
i.link {
|
||||
cursor: pointer; color: #64ae24;
|
||||
}
|
||||
|
||||
i.link:hover {
|
||||
color: #000;
|
||||
}
|
||||
Reference in New Issue
Block a user