| | | 1 | | using Audit.Core; |
| | | 2 | | using Syki.Back.Audit; |
| | | 3 | | using Audit.EntityFramework; |
| | | 4 | | using Syki.Back.Domain.Identity; |
| | | 5 | | using AuditConfig = Audit.Core.Configuration; |
| | | 6 | | |
| | | 7 | | namespace Syki.Back.Configs; |
| | | 8 | | |
| | | 9 | | public static class AuditConfigs |
| | | 10 | | { |
| | | 11 | | public static void AddAuditConfigs(this WebApplicationBuilder _) |
| | | 12 | | { |
| | 4 | 13 | | AuditConfig.Setup().UseEntityFramework(_ => _ |
| | 2 | 14 | | .AuditTypeExplicitMapper(_ => _ |
| | 2 | 15 | | .Map<SykiUser, AuditTrail>() |
| | 2 | 16 | | .Map<MagicLink, AuditTrail>() |
| | 2 | 17 | | .AuditEntityAction<AuditTrail>((evt, entry, trail) => |
| | 2 | 18 | | { |
| | 1530 | 19 | | if (evt.Environment.Exception != null) return false; |
| | 1530 | 20 | | return trail.Fill(evt, entry); |
| | 2 | 21 | | })) |
| | 4 | 22 | | .IgnoreMatchedProperties(true)); |
| | | 23 | | |
| | 2 | 24 | | AuditConfig.AddCustomAction(ActionType.OnScopeCreated, scope => |
| | 2 | 25 | | { |
| | 2654 | 26 | | var dbContext = scope.GetEntityFrameworkEvent().GetDbContext() as SykiDbContext; |
| | 2 | 27 | | |
| | 2654 | 28 | | scope.SetUserId(dbContext.RequestUser.Id); |
| | 2654 | 29 | | scope.SetInstitutionId(dbContext.RequestUser.InstitutionId); |
| | 2654 | 30 | | scope.SetActivityId(dbContext.ActivityId); |
| | 2654 | 31 | | scope.SetOperation(dbContext.Operation); |
| | 2656 | 32 | | }); |
| | 2 | 33 | | } |
| | | 34 | | } |