public async Task HandleAsync(AddGameEventSource command, ICorrelationContext context) { var gameSource = new GameEventSource(command.Id, command.IsWin, command.Score); await _gameSourceRepository.AddAsync(gameSource); await _busPublisher.PublishAsync(new GameEventSourceAdded(command.Id, command.Score, command.IsWin), context); }
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(AddGameEventSource command) { if (await _gameSourceRepository.ExistsAsync(command.Id)) { throw new GameEventSourceAlreadyExistsException(command.Id); } var gameSource = new GameEventSource(command.Id, command.IsWin, command.Score); await _gameSourceRepository.AddAsync(gameSource); var messageId = Guid.NewGuid().ToString("N");//this is unique per message type, each message has its own messageId in rabbitmq var correlationId = _messagePropertiesAccessor.MessageProperties.CorrelationId; var correlationContext = _correlationContextAccessor.CorrelationContext; var @event = new GameEventSourceAdded(command.Id, command.Score, command.IsWin, command.UserId); await _busPublisher.PublishAsync(@event, messageId : messageId, correlationId : correlationId, messageContext : correlationContext); }
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); }
private GameEventSource Act(Guid id, bool isWin, int score) => GameEventSource.Create(id, isWin, score);