| | | 1 | | using Audit.Core; |
| | | 2 | | using System.Text.Json; |
| | | 3 | | using Audit.EntityFramework; |
| | | 4 | | |
| | | 5 | | namespace Syki.Back.Audit; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Guarda os dados de auditoria de uma entidade. |
| | | 9 | | /// </summary> |
| | | 10 | | public class AuditTrail |
| | | 11 | | { |
| | 0 | 12 | | public int Id { get; set; } |
| | | 13 | | |
| | 1386 | 14 | | public string ActivityId { get; set; } |
| | 1386 | 15 | | public string Operation { get; set; } |
| | | 16 | | |
| | 1386 | 17 | | public string EntityId { get; set; } |
| | 1386 | 18 | | public string EntityType { get; set; } |
| | | 19 | | |
| | 1386 | 20 | | public int UserId { get; set; } |
| | 1386 | 21 | | public int InstitutionId { get; set; } |
| | | 22 | | |
| | 1386 | 23 | | public string Action { get; set; } |
| | 1386 | 24 | | public DateTime CreatedAt { get; set; } |
| | 1386 | 25 | | public JsonDocument Data { get; set; } |
| | | 26 | | |
| | | 27 | | public bool Fill(AuditEvent evt, EventEntry entry) |
| | | 28 | | { |
| | 1386 | 29 | | ActivityId = evt.ActivityId; |
| | 1386 | 30 | | Operation = evt.Operation; |
| | | 31 | | |
| | 1386 | 32 | | EntityId = entry.PrimaryKey.First().Value.ToString()!; |
| | 1386 | 33 | | EntityType = entry.EntityType.Name; |
| | | 34 | | |
| | 1386 | 35 | | UserId = evt.UserId; |
| | 1386 | 36 | | InstitutionId = evt.InstitutionId; |
| | | 37 | | |
| | 1386 | 38 | | Action = entry.Action; |
| | 1386 | 39 | | CreatedAt = DateTime.UtcNow; |
| | 1386 | 40 | | Data = AuditData.NewAsJson(entry); |
| | | 41 | | |
| | 1386 | 42 | | return true; |
| | | 43 | | } |
| | | 44 | | } |