public async Task <GameEventSourceDto> HandleAsync(GetGameEventSource query) { var gameEventSource = await _gameEventSourceRepository.GetAsync(query.Id); return(gameEventSource == null ? null : new GameEventSourceDto { Id = gameEventSource.Id, IsWin = gameEventSource.IsWin, Score = gameEventSource.Score }); }
public async Task HandleAsync(AddGameEventSource command, ICorrelationContext context) { var gameEventSource = await _gameSourceRepository.GetAsync(command.Id); if (gameEventSource != null) { gameEventSource.UpdateScoreAndIsWin(command.Score, command.IsWin); await _gameSourceRepository.UpdateAsync(gameEventSource); } else { var gameSource = new GameEventSource(command.Id, command.IsWin, command.Score, command.UserId); await _gameSourceRepository.AddAsync(gameSource); } await _busPublisher.PublishAsync(new GameEventSourceAdded(command.Id, command.Score, command.IsWin, command.UserId), context); }
public async Task HandleAsync(GameEventSourceAdded @event, ICorrelationContext context) { var gameEventSource = await _gameEventSourceRepository.GetAsync(@event.Id); if (gameEventSource != null) { gameEventSource.UpdateScoreAndIsWin(@event.Score, @event.IsWin); await _gameEventSourceRepository.UpdateAsync(gameEventSource); } else { var gameSource = new GameEventSource(@event.Id, @event.IsWin, @event.Score, @event.UserId); await _gameEventSourceRepository.AddAsync(gameSource); } _logger.LogInformation($"GameEventSource Added with id: '{@event.Id}'."); LeaderBoardPlayerDto leaderBorderPlayer = CalculatePositionInLeaderBoard(@event); await _hubService.PublishUserLeaderBoradInfoAsync(leaderBorderPlayer); }