private async Task SetUpdateAttributes(EntityEntry entry) { if (entry.State == EntityState.Modified || entry.State == EntityState.Added) { entry.Property("UpdatedOnUTC").CurrentValue = DateTime.UtcNow; entry.Property("UpdatedBy").CurrentValue = await _userIdProvider.GetAsync(); } }
public async Task LogCommandAsync <TCommand>(TCommand command) where TCommand : IRequest { try { var type = command.GetType().ToString(); var commandContent = JsonUtils.Serialize(command); var userId = await _userIdProvider.GetAsync(); _logger.LogWarning( "Command. UserId : {userId}. Type : {Type} - {CommandContent}", userId, type, commandContent); } catch (Exception ex) { _logger.LogError(ex, "Error occured while logging query"); } }
public async Task SendAsync <T>(T command, bool continueOnCapturedContext = false, CancellationToken cancellationToken = default) where T : class, IRequest { if (!(command is CommandBase commandBase)) { await _commandProcessor.SendAsync(command, continueOnCapturedContext, cancellationToken); return; } if (!(commandBase is ISkipLogging)) { await _commandQueryLogger.LogCommandAsync(command); } commandBase.UserId = await _userIdProvider.GetAsync(); await _commandProcessor.SendAsync(command, continueOnCapturedContext, cancellationToken); }
public async Task <TResult> ExecuteAsync <TResult>(IQuery <TResult> query, CancellationToken cancellationToken = default) { if (!(query is QueryBase <TResult> queryBase)) { return(await _decoratee.ExecuteAsync(query, cancellationToken)); } if (!(queryBase is ISkipLogging)) { await _commandQueryLogger.LogQueryAsync(query); } if (queryBase.UserId == default) { queryBase.UserId = await _userIdProvider.GetAsync(); } return(await _decoratee.ExecuteAsync(queryBase, cancellationToken)); }