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); } }