public async Task <GameStateModel> Build(Guid id, string userId, int streamVersion) { GameStateModel result = new GameStateModel() { Id = id, }; var gameData = await _gameRepository.GetByIdAsync(id.ToString()); if (gameData == null) { result.HasError = true; return(result); } _domain.Build(id, InitGameSnapshot); result.HasError = false; ISnapshot latestSnapshot = _store.Advanced.GetSnapshot(id, int.MaxValue); GameAggregate gameSnapshot = latestSnapshot?.Payload as GameAggregate; if (gameSnapshot == null) { result.HasError = true; return(result); } result = GetGameStateBySnapshot(gameSnapshot); result.StreamRevision = latestSnapshot.StreamRevision; if (streamVersion >= 0) { result.Events = GetUsedEvents(id, userId, streamVersion); } result.BattalionMovements = Mapper.Map <List <BattalionMovementEventModel> >(_domain.GetNotExecuteEvents <BattalionMovementEvent>(id)); await UpdateGameStateForReadData(id.ToString(), result); return(result); }