public async Task <(bool IsOperationExists, string OperationResult)> TryAddCurrentOperationAsync( CancellationToken cancellationToken) { var key = GetKey(); var existingOperationEntityJson = await _cache.GetStringAsync(key, cancellationToken); if (!string.IsNullOrWhiteSpace(existingOperationEntityJson)) { var existingOperationEntity = JsonSerializer .Deserialize(existingOperationEntityJson, typeof(OperationRegistryEntry)); if (existingOperationEntity is OperationRegistryEntry entity) { var operationResult = entity.OperationResult; return(true, operationResult.ToEmptyIfNull()); } } var operationEntity = OperationRegistryMapper.MapOperationRegistry(_operationContext); var operationEntityJson = JsonSerializer .Serialize(operationEntity, typeof(OperationRegistryEntry)); await _cache.SetStringAsync(key, operationEntityJson, _cacheEntryOptions, cancellationToken); return(false, string.Empty); }
public async Task <(bool IsOperationExists, string OperationResult)> TryAddCurrentOperationAsync( CancellationToken cancellationToken) { var operation = await GetOperationAsync(cancellationToken); if (operation != null) { return(true, string.IsNullOrWhiteSpace(operation.OperationResult) ? string.Empty : operation.OperationResult); } _dbContext.OperationRegistryEntries .Add(OperationRegistryMapper.MapOperationRegistry(_operationContext)); return(false, string.Empty); }