mirror of
https://github.com/Sea-Haven-Industries/proposal-system.git
synced 2026-09-30 12:23:14 +00:00
35 lines
996 B
C#
35 lines
996 B
C#
|
|
using ProposalSystem.Application.Interfaces;
|
||
|
|
using ProposalSystem.Domain.Entities;
|
||
|
|
using ProposalSystem.Infrastructure.Data;
|
||
|
|
|
||
|
|
namespace ProposalSystem.Infrastructure.Services;
|
||
|
|
|
||
|
|
public class AuditService : IAuditService
|
||
|
|
{
|
||
|
|
private readonly ProposalDbContext _db;
|
||
|
|
private readonly ICurrentUserService _currentUser;
|
||
|
|
|
||
|
|
public AuditService(ProposalDbContext db, ICurrentUserService currentUser)
|
||
|
|
{
|
||
|
|
_db = db;
|
||
|
|
_currentUser = currentUser;
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task LogAsync(AuditAction action, Guid? proposalId, string? details = null, CancellationToken ct = default)
|
||
|
|
{
|
||
|
|
var entry = new AuditLog
|
||
|
|
{
|
||
|
|
Id = Guid.NewGuid(),
|
||
|
|
ProposalId = proposalId,
|
||
|
|
UserId = _currentUser.UserId,
|
||
|
|
Action = action,
|
||
|
|
Details = details,
|
||
|
|
Timestamp = DateTime.UtcNow,
|
||
|
|
IpAddress = _currentUser.IpAddress,
|
||
|
|
};
|
||
|
|
|
||
|
|
_db.AuditLogs.Add(entry);
|
||
|
|
await _db.SaveChangesAsync(ct);
|
||
|
|
}
|
||
|
|
}
|