public GameResultDto GetGameResult(int id) { var gameResult = _gameResultRepository.Get(id); var gameResultDto = Mapper.Map <GameResultDto>(gameResult); gameResultDto.CreatedGamerNickname = _gamerRepository.Get(Guid.Parse(gameResultDto.CreatedGamerId))?.Nickname; if (gameResultDto.GameTableId.HasValue) { gameResultDto.GameTableName = _gameTableRepository.Get(gameResultDto.GameTableId.Value)?.Name; } return(gameResultDto); }
public async Task Upsert(List <GameResult> gameResults, int weekId) { foreach (GameResult gameResult in gameResults) { GameResult existingGameResult = await _gameResultRepository.Get(weekId, gameResult.Game.AwayTeamId, gameResult.Game.HomeTeamId); if (existingGameResult == null) { // adding result gameResult.Game = null; await _gameResultRepository.Insert(gameResult); } else { // updating a result existingGameResult.AwayScore = gameResult.AwayScore; existingGameResult.HomeScore = gameResult.HomeScore; } } await _gameResultRepository.SaveChanges(); }