示例#1
0
        public int GenerateOlympic(string name, int teamsCount)
        {
            var teamNames = Enumerable.Range(1, teamsCount).Select(i => $"team №{i}").ToArray();
            var stages    = new List <List <Game> > {
                new List <Game>()
            };
            var stageIndex          = PlayMatches(teamsCount, teamNames, stages);
            var tournament          = BuildTournament(stages, stageIndex);
            var tournamentJson      = tournament.ToJson();
            var generatedTournament = context.Tournaments.Add(new Tournament {
                Name = name, TournamentTree = tournamentJson, Type = TournamentType.Olympic
            }).Entity;

            context.SaveChanges();
            return(generatedTournament.TournamentId);
        }
        private void ClearAndGenerateTournaments(int olympicTournamentsCount, int groupTournamentsCount)
        {
            context.Teams.RemoveRange(context.Teams);
            context.Results.RemoveRange(context.Results);
            context.TeamGameResults.RemoveRange(context.TeamGameResults);
            context.Games.RemoveRange(context.Games);
            context.Tournaments.RemoveRange(context.Tournaments);
            context.SaveChanges();

            var result = new Dictionary <string, int>();

            for (var i = 0; i < olympicTournamentsCount; i++)
            {
                result[$"Test olympic tournament №{i}"] = tournamentGenerator.GenerateOlympic($"Test olympic tournament №{i}", 8);
            }
            for (var i = 0; i < groupTournamentsCount; i++)
            {
                result[$"Test group tournament №{i + groupTournamentsCount}"] = tournamentGenerator.GenerateGroup($"Test group tournament №{i+ groupTournamentsCount}", 4);
            }
        }
示例#3
0
        private void AddRandomData()
        {
            var gameResult = new Game {
                GameName = RandomString(random.Next(8, 20)), PathToLog = "C:/"
            };
            var firstTeam = new Team {
                CvarcTag = Guid.NewGuid(), LinkToImage = "qwe", Name = RandomString(random.Next(8, 20))
            };
            var secondTeam = new Team {
                CvarcTag = Guid.NewGuid(), LinkToImage = "qwer", Name = RandomString(random.Next(8, 20))
            };
            var firstTeamGameResult = new TeamGameResult {
                Team = firstTeam, Game = gameResult
            };
            var secondTeamGameResult = new TeamGameResult {
                Team = secondTeam, Game = gameResult
            };
            var result1 = new Result {
                TeamGameResult = firstTeamGameResult, Scores = random.Next(100), ScoresType = "MainScores"
            };
            var result2 = new Result {
                TeamGameResult = firstTeamGameResult, Scores = random.Next(100), ScoresType = "OtherScores"
            };
            var result3 = new Result {
                TeamGameResult = secondTeamGameResult, Scores = random.Next(100), ScoresType = "MainScores"
            };
            var result4 = new Result {
                TeamGameResult = secondTeamGameResult, Scores = random.Next(100), ScoresType = "OtherScores"
            };

            context.Games.Add(gameResult);
            context.Teams.Add(firstTeam);
            context.Teams.Add(secondTeam);
            context.TeamGameResults.Add(firstTeamGameResult);
            context.TeamGameResults.Add(secondTeamGameResult);
            context.Results.Add(result1);
            context.Results.Add(result2);
            context.Results.Add(result3);
            context.Results.Add(result4);
            context.SaveChanges();
        }