/// <summary> /// Verifies if teams are same in two different games ignoring order /// </summary> /// <param name="firstGame">First game to check</param> /// <param name="secondGame">Second game to check</param> /// <returns>true if teams are the same in games</returns> public static bool AreSameTeamsInGames(GameResultDto firstGame, Game secondGame) { return((AreTheSameTeams(firstGame.AwayTeamId, secondGame.AwayTeamId) && AreTheSameTeams(firstGame.HomeTeamId, secondGame.HomeTeamId)) || (AreTheSameTeams(firstGame.AwayTeamId, secondGame.HomeTeamId) && AreTheSameTeams(firstGame.HomeTeamId, secondGame.AwayTeamId))); }
private static void ValidateAreSameTeamsInGames( GameResultDto game, Game newGame, TournamentScheduleDto tournamentScheduleInfo) { string errorMessage = null; if (GameValidation.IsFreeDayGame(newGame)) { if (tournamentScheduleInfo.Scheme != TournamentSchemeEnum.PlayOff) { errorMessage = Resources.SameFreeDayGameInRound; } else { errorMessage = string.Format( Resources.SameTeamInRound, game.HomeTeamId); } } else { errorMessage = String.Format( Resources.SameGameInRound, game.HomeTeamName, game.AwayTeamName, game.Round.ToString()); } throw new ArgumentException(errorMessage); }
public void Add(GameResultDto gameResultDto) { var gameResult = mapper.Map <GameResult>(gameResultDto); gameResultService.Add(gameResult); applicationServiceLeaderboard.AddLeaderboard(gameResult.PlayerId, gameResult.Win); }
public List <GameResultDto> GetResultsTeamAsDtoAll(string teamCode) { var query = (from g in _wpbDataContext.GameResults join homeTeam in _wpbDataContext.Teams on g.HomeTeamId equals homeTeam.Id join awayTeam in _wpbDataContext.Teams on g.AwayTeamId equals awayTeam.Id join subDiv in _wpbDataContext.SubDivisions on g.SubDivisionId equals subDiv.Id join div in _wpbDataContext.Divisions on subDiv.DivisionId equals div.Id where g.AwayTeamCode == teamCode || g.HomeTeamCode == teamCode select new GameResultDto { TimeStamp = g.TimeStamp, HomeTeamName = homeTeam.TeamName, HomeTeamCode = homeTeam.TeamCode, HomeTeamHasLogo = homeTeam.HasLogo, HomeTeamLogo = GameResultDto.GetLogolUrl(homeTeam.Logo), AwayTeamName = awayTeam.TeamName, AwayTeamCode = awayTeam.TeamCode, AwayTeamHasLogo = awayTeam.HasLogo, AwayTeamLogo = GameResultDto.GetLogolUrl(awayTeam.Logo), Division = div.DivisionName, DivisionCode = div.DivisionCode, SubDivision = subDiv.SubDivisionTitle, SubDivisionCode = subDiv.SubDivisionCode, Score = g.Score, WinnerTeamName = g.WinningTeamName, WinnerTeamCode = g.WinningTeamCode }); return(query.ToList()); }
/// <summary> /// Maps domain model of game result to view model of game. /// </summary> /// <param name="gameResult">Domain model of game.</param> /// <returns>View model of game.</returns> public static GameViewModel Map(GameResultDto gameResult) { var game = new GameViewModel { Id = gameResult.Id, HomeTeamName = gameResult.HomeTeamName, AwayTeamName = gameResult.AwayTeamName, Round = gameResult.Round, GameNumber = gameResult.GameNumber, Result = new GameResult { TotalScore = new ScoreViewModel { Home = gameResult.Result.GameScore.Home, Away = gameResult.Result.GameScore.Away }, IsTechnicalDefeat = gameResult.Result.GameScore.IsTechnicalDefeat, SetScores = gameResult.Result.SetScores.Select(item => new ScoreViewModel { Home = item.Home, Away = item.Away, IsTechnicalDefeat = item.IsTechnicalDefeat }).ToList() }, DivisionId = gameResult.DivisionId, DivisionName = gameResult.DivisionName, GroupId = gameResult.GroupId, Date = gameResult.GameDate.GetValueOrDefault(), UrlToGameVideo = gameResult.UrlToGameVideo }; if (game.Result.TotalScore.IsEmpty) { game.Result = null; } return(game); }
public List <GameResultDto> GetResultsAsDto() { var timestampNow = DateTime.Now; // We only want the "last" 14days var timestampSeven = timestampNow.AddDays(-14); var query = (from g in _wpbDataContext.GameResults where g.TimeStamp >= timestampSeven join homeTeam in _wpbDataContext.Teams on g.HomeTeamId equals homeTeam.Id join awayTeam in _wpbDataContext.Teams on g.AwayTeamId equals awayTeam.Id join subDiv in _wpbDataContext.SubDivisions on g.SubDivisionId equals subDiv.Id join div in _wpbDataContext.Divisions on subDiv.DivisionId equals div.Id select new GameResultDto { TimeStamp = g.TimeStamp, HomeTeamName = homeTeam.TeamName, HomeTeamCode = homeTeam.TeamCode, HomeTeamHasLogo = homeTeam.HasLogo, HomeTeamLogo = GameResultDto.GetLogolUrl(homeTeam.Logo), AwayTeamName = awayTeam.TeamName, AwayTeamCode = awayTeam.TeamCode, AwayTeamHasLogo = awayTeam.HasLogo, AwayTeamLogo = GameResultDto.GetLogolUrl(awayTeam.Logo), Division = div.DivisionName, DivisionCode = div.DivisionCode, SubDivision = subDiv.SubDivisionTitle, SubDivisionCode = subDiv.SubDivisionCode, Score = g.Score, WinnerTeamName = g.WinningTeamName, WinnerTeamCode = g.WinningTeamCode }); return(query.ToList()); }
/// <summary> /// Checks if one team from new game participates in original game /// </summary> /// <param name="originalGame">Game which teams are compared to new game's teams</param> /// <param name="newGame">Game which teams are compared to original game's teams</param> /// <returns>True if one of new game's teams participates in original game</returns> public static bool IsTheSameTeamInTwoGames(GameResultDto originalGame, Game newGame) { return(originalGame.HomeTeamId == newGame.HomeTeamId || originalGame.HomeTeamId == newGame.AwayTeamId || originalGame.AwayTeamId == newGame.HomeTeamId || originalGame.AwayTeamId == newGame.AwayTeamId); }
private bool ValidateEditingSchemePlayoff(GameResultDto game) { if (game.TournamentId > 0) { var tournamentInfo = _tournamentScheduleDtoByIdQuery .Execute(new TournamentScheduleInfoCriteria { TournamentId = game.TournamentId }); if (tournamentInfo != null) { var gamesInCurrentAndNextRounds = _gamesByTournamentIdInRoundsByNumbersQuery .Execute(new GamesByRoundCriteria { TournamentId = tournamentInfo.Id, RoundNumbers = new List <byte> { game.Round, Convert.ToByte(game.Round + 1) } }); var gameone = new Game { Round = game.Round }; var numbersofRounds = GetNumberOfRounds(gameone, gamesInCurrentAndNextRounds); var nextGameNumber = GetNextGameNumber(game.GameNumber, numbersofRounds); var nextGame = gamesInCurrentAndNextRounds.SingleOrDefault(g => g.GameNumber == nextGameNumber); if (nextGame != null && !nextGame.Result.GameScore.IsEmpty) { return(false); } } } return(true); }
public IActionResult DataEntry(GameResultDto dto) { if (!ModelState.IsValid) { return(View()); } var brainGame = _db.BrainGames.FirstOrDefault(bg => bg.Name == dto.Name); if (brainGame is null) { brainGame = new BrainGame { Name = dto.Name }; _db.BrainGames.Add(brainGame); } var result = new GameResult { Score = dto.Score, Player = User.Identity.Name, DateTime = dto.DateTime }; brainGame.GameResults.Add(result); _db.SaveChanges(); return(RedirectToAction("Details", "Results", new { id = result.Id })); }
/// <summary> /// Initializes a new instance of the <see cref="GameResultDtoBuilder"/> class. /// </summary> public GameResultDtoBuilder() { _gameResult = new GameResultDto { Id = 1, TournamentId = 1, HomeTeamId = 1, AwayTeamId = 2, HomeTeamName = "TeamNameA", AwayTeamName = "AwayTeamName", Result = new Result { GameScore = new Score { Home = 3, Away = 0, IsTechnicalDefeat = false, }, SetScores = new System.Collections.Generic.List <Score> { new Score(25, 20), new Score(26, 24), new Score(30, 28), new Score(0, 0), new Score(0, 0), }, }, GameDate = DateTime.Parse(DATE), Round = 1, GameNumber = 0, UrlToGameVideo = "http://test-url-a.com", }; }
private void ValidateGameInRoundOnDelete(GameResultDto gameToDelete) { if (gameToDelete.HasResult) { throw new ArgumentException(Resources.WrongDeletingGame); } }
private List <GameResultDto> NextGames(List <GameResultDto> allGames, GameResultDto currentGame) { if (allGames == null) { throw new ArgumentNullException(nameof(allGames)); } var numberOfRounds = Convert.ToByte(Math.Sqrt(allGames.Count)); if (currentGame.Round == numberOfRounds) { return(new List <GameResultDto>()); } var games = new List <GameResultDto>(); int nextGameNumber = GetNextGameNumber(currentGame.GameNumber, numberOfRounds); games.Add(allGames.SingleOrDefault(g => g.GameNumber == nextGameNumber)); if (currentGame.Round == numberOfRounds - 1) { games.Add(allGames.SingleOrDefault(g => g.GameNumber == nextGameNumber + 1)); } return(games); }
// POST tables/GameResult public async Task <IHttpActionResult> PostGameResult(GameResultDto item) { GameResult current = await InsertAsync(item.ToGameResult()); var result = CreatedAtRoute("Tables", new { id = current.Id }, current); return(result); }
public static GameResult AsDomain(this GameResultDto gameResult) { return(gameResult switch { GameResultDto.WonByBlack => GameResult.WonByBlack, GameResultDto.WonByWhite => GameResult.WonByWhite, GameResultDto.Draw => GameResult.Draw, _ => throw new ArgumentException("Failed to translate game result dto to domain"), });
public void AddElement(GameResultDto gameResultDto) { var gameResultText = _diContainer.InstantiatePrefab(_settings.GameResultPrefab); gameResultText.transform.SetParent(transform, false); var textMesh = gameResultText.GetComponent <TextMeshProUGUI>(); textMesh.color = gameResultDto.IsHighlighted ? new Color32(100, 255, 100, 255) : new Color32(255, 255, 255, 255); textMesh.text = $"{gameResultDto.Timestamp:HH:mm} {gameResultDto.Score:D4}"; }
public static GameResult ToGameResult(this GameResultDto dto) { return(new GameResult { Id = dto.Id, ChallengeId = dto.ChallengeId, ChallengeeScore = dto.ChallengeeScore, ChallengerScore = dto.ChallengerScore, Index = dto.Index }); }
/// <summary> /// Mapper from GameResult to GameViewModel /// </summary> /// <param name="game">GameResult to map from</param> /// <returns>Complete GameViewModel</returns> public static GameViewModel Map(GameResultDto game) { return(new GameViewModel { Id = game.Id, TournamentId = game.TournamentId, HomeTeamId = game.HomeTeamId, AwayTeamId = game.AwayTeamId, Round = game.Round, GameDate = game.GameDate.Value.Date, GameTime = game.GameDate.Value.TimeOfDay, GameNumber = game.GameNumber }); }
private static (int Home, int Away) GetUpstreamGameNumbers(GameResultDto game, int numberOfRounds) { var gameNumber = (game.Round == numberOfRounds && game.GameNumber % 2 == 0) //Final game - has to be adjusted because of Bronze game ? game.GameNumber - 1 : game.GameNumber; var away = 2 * gameNumber - Convert.ToInt32(Math.Pow(2, numberOfRounds)); var home = away - 1; return(home, away); }
public void SolveBattle_ShouldReturnGameResults() { var expectedResult = new GameResultDto { Message = "Dragon was successful in a glorious battle", Status = "Victory" }; var result = _gameClient.SolveBattle(00001, _dragonDto); Assert.NotNull(result); Assert.Equal(expectedResult.Message, result.Message); Assert.Equal(expectedResult.Status, result.Status); }
/// <summary> /// Deletes game by its identifier. /// </summary> /// <param name="id">Identifier of game.</param> public void Delete(int id) { _authService.CheckAccess(AuthOperations.Games.Delete); GameResultDto game = Get(id); if (game == null) { throw new ArgumentNullException("game"); } ValidateGameInRoundOnDelete(game); _gameRepository.Remove(id); _gameRepository.UnitOfWork.Commit(); }
public void SaveResultToScoreboard(GameResultDto result) { _scoreboard.Add(result); _scoreboard.Sort((dto, resultDto) => dto.Score > resultDto.Score ? -1 : 1); if (_scoreboard.Count > 5) { _scoreboard = _scoreboard.GetRange(0, 5); } var formatter = new BinaryFormatter(); var fileStream = new FileStream(_path, FileMode.Create); formatter.Serialize(fileStream, _scoreboard); fileStream.Close(); }
private static void UpdateTeamNamesIfNotFirstRound(GameResultDto game, int numberOfRounds) { var prefix = IsBronzeGame(game, numberOfRounds) ? LOOSER_PREFIX : WINNER_PREFIX; var(home, away) = GetUpstreamGameNumbers(game, numberOfRounds); if (game.HomeTeamId == null) { game.HomeTeamName = $"{prefix}{home}"; } if (game.AwayTeamId == null) { game.AwayTeamName = $"{prefix}{away}"; } }
public void Copy(GameDto game) { if (GameId != game.GameId) { return; } RoundId = game.RoundId; HomeTeamId = game.HomeTeamId; HomeTeamName = game.HomeTeamName; AwayTeamId = game.AwayTeamId; AwayTeamName = game.AwayTeamName; Date = game.Date; Stadium = game.Stadium; HomeTeamGoals = game.HomeTeamGoals; AwayTeamGoals = game.AwayTeamGoals; Result = game.Result; }
private GameResult MapGameResultDtoToGameResultWithReferences(GameResultDto gameResultDto, Gamer gamer) { GameTable gameTable = null; if (gameResultDto.GameTableId.HasValue) { gameTable = _gameTableRepository.Get(gameResultDto.GameTableId.Value); } var boardGame = _boardGameRepository.Get(gameResultDto.BoardGameId); var gameResult = Mapper.Map <GameResultDto, GameResult>(gameResultDto); Mapper.Map(gamer, gameResult); Mapper.Map(gameTable, gameResult); Mapper.Map(boardGame, gameResult); return(gameResult); }
public ActionResult Post([FromBody] GameResultDto gameResultDto) { try { if (gameResultDto == null) { return(NotFound()); } applicationServiceGameResult.Add(gameResultDto); return(Ok("Game cadastrado!")); } catch (Exception ex) { throw ex; } }
private static void ValidateAreSameTeamsInGames( GameResultDto game, Game newGame, TournamentScheduleDto tournamentScheduleInfo) { string errorMessage = null; var tmpres = (tournamentScheduleInfo.Scheme != TournamentSchemeEnum.PlayOff ? Resources.SameFreeDayGameInRound : string.Format( Resources.SameTeamInRound, game.HomeTeamId)); errorMessage = GameValidation.IsFreeDayGame(newGame) ? tmpres : string.Format( Resources.SameGameInRound, game.HomeTeamName, game.AwayTeamName, game.Round.ToString()); throw new ArgumentException(errorMessage); }
/// <summary> /// Maps domain model of game result to view model of game result. /// </summary> /// <param name="gameResult">Domain model of game result.</param> /// <returns>View model of game result.</returns> public static GameResultViewModel Map(GameResultDto gameResult) { var result = new GameResultViewModel { Id = gameResult.Id, TournamentId = gameResult.TournamentId, HomeTeamId = gameResult.HomeTeamId, AwayTeamId = gameResult.AwayTeamId, HomeTeamName = gameResult.HomeTeamName, AwayTeamName = gameResult.AwayTeamName, GameDate = gameResult.GameDate, GameNumber = gameResult.GameNumber, Round = gameResult.Round, UrlToGameVideo = gameResult.UrlToGameVideo, GameScore = new ScoreViewModel { Home = gameResult.Result.GameScore.Home, Away = gameResult.Result.GameScore.Away }, IsTechnicalDefeat = gameResult.Result.GameScore.IsTechnicalDefeat, AllowEditResult = gameResult.AllowEditResult, SetScores = gameResult.Result.SetScores.Select(item => new ScoreViewModel { Home = item.Home, Away = item.Away, IsTechnicalDefeat = item.IsTechnicalDefeat }).ToList() }; if (gameResult.HasResult && gameResult.Result.Penalty != null) { var penalty = gameResult.Result.Penalty; result.HasPenalty = true; result.IsHomeTeamPenalty = penalty.IsHomeTeam; result.PenaltyAmount = penalty.Amount; result.PenaltyDescrition = penalty.Description; } return(result); }
public IActionResult PostGameResult([FromBody] GameResultDto gameResultDto) { var brainGame = _context.BrainGames.FirstOrDefault(game => game.Name == gameResultDto.Name); if (brainGame == null) { _context.Add(new BrainGame { Name = gameResultDto.Name }); // return BadRequest(); } var gameResult = new GameResult { Player = User.Identity.Name, Score = gameResultDto.Score, DateTime = gameResultDto.DateTime, BrainGame = brainGame }; _context.Results.Add(gameResult); _context.SaveChanges(); return(Ok(gameResult)); }
private static void ValidateIsTheSameTeamInTwoGames( GameResultDto game, Game newGame, TournamentScheduleDto tournamentScheduleInfo) { if (tournamentScheduleInfo.Scheme == TournamentSchemeEnum.PlayOff) { return; } if (GameValidation.IsFreeDayGame(newGame)) { if (game.HomeTeamId != newGame.HomeTeamId && game.AwayTeamId != newGame.HomeTeamId) { throw new ArgumentException(Resources.SameFreeDayGameInRound); } else if (game.HomeTeamId != newGame.HomeTeamId || game.AwayTeamId != newGame.HomeTeamId) { throw new ArgumentException(string.Format( Resources.SameTeamInRound, (game.HomeTeamId == newGame.HomeTeamId) ? game.HomeTeamName : game.AwayTeamName)); } } else { throw new ArgumentException(string.Format( Resources.SameTeamInRound, (game.HomeTeamId == newGame.HomeTeamId || game.HomeTeamId == newGame.AwayTeamId) ? game.HomeTeamName : game.AwayTeamName)); } }
public void AddGameResult(GameResultDto gameResultDto, Gamer gamer) { var gameResult = MapGameResultDtoToGameResultWithReferences(gameResultDto, gamer); _gameResultRepository.Add(gameResult); }