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:
Andre Beging
2025-03-29 13:49:47 +01:00
parent 16023a89e9
commit c2de397a0f
15 changed files with 404 additions and 33 deletions

View File

@@ -1,42 +1,43 @@
using FoodsharingSiegen.Contracts.Entity;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
namespace FoodsharingSiegen.Server.Data
{
/// <summary>
/// The fs context class (a. beging, 21.05.2022)
/// The fs context class (a. beging, 21.05.2022)
/// </summary>
/// <seealso cref="DbContext"/>
/// <seealso cref="DbContext" />
public sealed class FsContext : DbContext
{
#region Public Properties
/// <summary>
/// Gets or sets the value of the interactions (ab)
/// Gets or sets the value of the audits (ab)
/// </summary>
public DbSet<Audit>? Audits { get; set; }
/// <summary>
/// Gets or sets the value of the interactions (ab)
/// </summary>
public DbSet<Interaction>? Interactions { get; set; }
/// <summary>
/// Gets or sets the value of the prospects (ab)
/// Gets or sets the value of the prospects (ab)
/// </summary>
public DbSet<Prospect>? Prospects { get; set; }
/// <summary>
/// Gets or sets the value of the users (ab)
/// Gets or sets the value of the users (ab)
/// </summary>
public DbSet<User>? Users { get; set; }
/// <summary>
/// Gets or sets the value of the audits (ab)
/// </summary>
public DbSet<Audit>? Audits { get; set; }
#endregion
#region Setup/Teardown
/// <summary>
/// Initializes a new instance of the <see cref="FsContext"/> class
/// Initializes a new instance of the <see cref="FsContext" /> class
/// </summary>
/// <param name="options">The options (ab)</param>
public FsContext(DbContextOptions<FsContext> options) : base(options)
@@ -45,11 +46,26 @@ namespace FoodsharingSiegen.Server.Data
}
#endregion
#region Override OnConfiguring
/// <summary>
/// Configures the database context options.
/// </summary>
/// <param name="optionsBuilder">A builder used to create or modify options for the context.</param>
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.ConfigureWarnings(builder => { builder.Ignore(RelationalEventId.PendingModelChangesWarning); });
base.OnConfiguring(optionsBuilder);
}
#endregion
#region Public Method HasChanges
/// <summary>
/// Describes whether this instance has changes
/// Describes whether this instance has changes
/// </summary>
/// <returns>The bool</returns>
public bool HasChanges()

View File

@@ -115,6 +115,9 @@ namespace FoodsharingSiegen.Server.Data.Service
if(parameter.CannotHaveInteractions != null && parameter.CannotHaveInteractions.Any())
prospectsQuery = prospectsQuery.Where(x => x.Interactions.All(i => !parameter.CannotHaveInteractions.Contains(i.Type)));
if (!parameter.IncludeDeleted)
prospectsQuery = prospectsQuery.Where(x => x.RecordState != RecordState.Deleted);
var prospects = await prospectsQuery.ToListAsync();
@@ -172,6 +175,7 @@ namespace FoodsharingSiegen.Server.Data.Service
entityProspect.Name = prospect.Name;
entityProspect.FsId = prospect.FsId;
entityProspect.Warning = prospect.Warning;
entityProspect.RecordState = prospect.RecordState;
var saveR = await Context.SaveChangesAsync();