25 lines
632 B
C#

using global::BuildFlow.Shared.Domain.Common;
using Microsoft.EntityFrameworkCore;
namespace BuildFlow.Workflow.Tests;
public static class AuditStub
{
public static void OnSave(object? sender, EventArgs _)
{
if (sender is not DbContext ctx) return;
foreach (var entry in ctx.ChangeTracker.Entries())
{
if (entry.Entity is IAuditable a)
{
a.CreatedBy ??= "test";
a.UpdatedBy ??= "test";
}
if (entry.Entity is IHasOperatorIP o)
{
o.OperatorIP ??= "127.0.0.1";
}
}
}
}