예제 #1
0
        public async Task HandleAsync(AddAuditLogEntryCommand command, CancellationToken cancellationToken = default)
        {
            var auditLog = new AuditLogEntry
            {
                UserId          = command.AuditLogEntry.UserId,
                CreatedDateTime = command.AuditLogEntry.CreatedDateTime,
                Action          = command.AuditLogEntry.Action,
                ObjectId        = command.AuditLogEntry.ObjectId,
                Log             = command.AuditLogEntry.Log,
            };

            await _auditLogRepository.AddOrUpdateAsync(auditLog);

            await _auditLogRepository.UnitOfWork.SaveChangesAsync(cancellationToken);

            await _eventLogRepository.AddOrUpdateAsync(new EventLog
            {
                EventType       = "AUDIT_LOG_ENTRY_CREATED",
                TriggeredById   = _currentUser.UserId,
                CreatedDateTime = auditLog.CreatedDateTime,
                ObjectId        = auditLog.Id.ToString(),
                Message         = auditLog.AsJsonString(),
                Published       = false,
            }, cancellationToken);

            await _eventLogRepository.UnitOfWork.SaveChangesAsync(cancellationToken);
        }
        public async Task HandleAsync(EntityUpdatedEvent <Entities.Product> domainEvent, CancellationToken cancellationToken = default)
        {
            var auditLog = new AuditLogEntry
            {
                UserId          = _currentUser.UserId,
                CreatedDateTime = domainEvent.EventDateTime,
                Action          = "UPDATED_PRODUCT",
                ObjectId        = domainEvent.Entity.Id.ToString(),
                Log             = domainEvent.Entity.AsJsonString(),
            };

            await _auditLogRepository.AddOrUpdateAsync(auditLog);

            await _auditLogRepository.UnitOfWork.SaveChangesAsync(cancellationToken);

            await _eventLogRepository.AddOrUpdateAsync(new EventLog
            {
                EventType       = "AUDIT_LOG_ENTRY_CREATED",
                TriggeredById   = _currentUser.UserId,
                CreatedDateTime = auditLog.CreatedDateTime,
                ObjectId        = auditLog.Id.ToString(),
                Message         = auditLog.AsJsonString(),
                Published       = false,
            }, cancellationToken);

            await _eventLogRepository.AddOrUpdateAsync(new EventLog
            {
                EventType       = "PRODUCT_UPDATED",
                TriggeredById   = _currentUser.UserId,
                CreatedDateTime = domainEvent.EventDateTime,
                ObjectId        = domainEvent.Entity.Id.ToString(),
                Message         = domainEvent.Entity.AsJsonString(),
                Published       = false,
            }, cancellationToken);

            await _eventLogRepository.UnitOfWork.SaveChangesAsync(cancellationToken);
        }
예제 #3
0
        public async Task HandleAsync(EntityDeletedEvent <FileEntry> domainEvent, CancellationToken cancellationToken = default)
        {
            var auditLog = new AuditLogEntry
            {
                UserId          = _currentUser.IsAuthenticated ? _currentUser.UserId : Guid.Empty,
                CreatedDateTime = domainEvent.EventDateTime,
                Action          = "DELETE_FILEENTRY",
                ObjectId        = domainEvent.Entity.Id.ToString(),
                Log             = domainEvent.Entity.AsJsonString(),
            };

            await _auditLogRepository.AddOrUpdateAsync(auditLog);

            await _auditLogRepository.UnitOfWork.SaveChangesAsync(cancellationToken);

            await _eventLogRepository.AddOrUpdateAsync(new EventLog
            {
                EventType       = "AUDIT_LOG_ENTRY_CREATED",
                TriggeredById   = _currentUser.UserId,
                CreatedDateTime = auditLog.CreatedDateTime,
                ObjectId        = auditLog.Id.ToString(),
                Message         = auditLog.AsJsonString(),
                Published       = false,
            }, cancellationToken);

            await _eventLogRepository.AddOrUpdateAsync(new EventLog
            {
                EventType       = "FILEENTRY_DELETED",
                TriggeredById   = _currentUser.UserId,
                CreatedDateTime = domainEvent.EventDateTime,
                ObjectId        = domainEvent.Entity.Id.ToString(),
                Message         = domainEvent.Entity.AsJsonString(),
                Published       = false,
            }, cancellationToken);

            await _eventLogRepository.UnitOfWork.SaveChangesAsync(cancellationToken);
        }