Add 'Modified' tracking for Prospect entity
Introduce a 'Modified' field to track the last modification date of prospects. Automatically update this field on changes and integrate it in UI display for better transparency.
This commit is contained in:
@@ -44,6 +44,7 @@ namespace FoodsharingSiegen.Server.Data.Service
|
||||
interaction.Created = DateTime.UtcNow;
|
||||
|
||||
targetProspect.Interactions.Add(interaction);
|
||||
targetProspect.Modified = DateTime.UtcNow;
|
||||
|
||||
await Context.SaveChangesAsync();
|
||||
|
||||
@@ -77,6 +78,7 @@ namespace FoodsharingSiegen.Server.Data.Service
|
||||
if (prospect == null) return new(new Exception("Cannot be empty"));
|
||||
|
||||
prospect.Created = DateTime.UtcNow;
|
||||
prospect.Modified = DateTime.UtcNow;
|
||||
prospect.Id = Guid.Empty;
|
||||
|
||||
await Context.Prospects!.AddAsync(prospect);
|
||||
@@ -142,8 +144,19 @@ namespace FoodsharingSiegen.Server.Data.Service
|
||||
{
|
||||
try
|
||||
{
|
||||
Context.Interactions!.Remove(new() { Id = interactionId });
|
||||
var interaction = await Context.Interactions!.AsNoTracking().FirstOrDefaultAsync(x => x.Id == interactionId);
|
||||
if(interaction == null) return new(new Exception("Interaction not found"));
|
||||
|
||||
Context.Interactions!.Remove(new() { Id = interaction.Id });
|
||||
await Context.SaveChangesAsync();
|
||||
|
||||
// Update prospect modified date
|
||||
var prospect = await Context.Prospects!.FirstOrDefaultAsync(x => x.Id == interaction.ProspectID);
|
||||
if (prospect != null)
|
||||
{
|
||||
prospect.Modified = DateTime.UtcNow;
|
||||
await Context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
await AuditService.Insert(AuditType.RemoveInteraction, "?");
|
||||
|
||||
@@ -176,6 +189,7 @@ namespace FoodsharingSiegen.Server.Data.Service
|
||||
entityProspect.FsId = prospect.FsId;
|
||||
entityProspect.Warning = prospect.Warning;
|
||||
entityProspect.RecordState = prospect.RecordState;
|
||||
entityProspect.Modified = DateTime.UtcNow;
|
||||
|
||||
var saveR = await Context.SaveChangesAsync();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user