示例#1
0
        /// <summary>
        /// Generates teams
        /// </summary>
        /// <param name="clubs"></param>
        /// <returns></returns>
        public async Task <List <Team> > GenerateTeamsAsync(List <Club> clubs, ClubGenerationMode mode = ClubGenerationMode.AllTeams)
        {
            List <Team> results = new List <Team>();

            for (int i = 0; i < clubs.Count; i++)
            {
                Club club = clubs[i];

                if ((int)mode <= 3)
                {
                    // First team
                    Team firstTeam = new Team()
                    {
                        TeamId = club.FirstTeamId,
                        ClubId = club.ClubId,
                        Name   = club.Name,
                    };

                    results.Add(firstTeam);
                }

                // Second team
                Team secondTeam = new Team()
                {
                    TeamId = club.ReservesTeamId,
                    ClubId = club.ClubId,
                    Name   = club.Name + " II",
                };

                // Youth team
                Team youthTeam = new Team()
                {
                    TeamId = club.YouthTeamId,
                    ClubId = club.ClubId,
                    Name   = club.Name + " U19",
                };


                results.Add(secondTeam);
                results.Add(youthTeam);
            }

            await this.teams.InsertManyAsync(results);

            return(results);
        }
示例#2
0
        /// <summary>
        /// Generate players into the current database.
        /// </summary>
        /// <param name="count"></param>
        /// <param name="countryId"></param>
        /// <returns></returns>
        public async Task <List <Player> > GeneratePlayersAsync(List <Club> clubs, ClubGenerationMode mode = ClubGenerationMode.AllTeams)
        {
            List <Player> results = new List <Player>();
            Random        r       = new Random();

            for (int i = 0; i < clubs.Count; i++)
            {
                Club club = clubs[i];

                // ToDo: Handle all generation modes.
                if ((int)mode <= 3)
                {
                    // First team
                    for (int j = 0; j < r.Next(20, 28); j++)
                    {
                        Player player = new Player()
                        {
                            PlayerId  = Guid.NewGuid().ToString(),
                            ClubId    = club.ClubId,
                            TeamId    = club.FirstTeamId,
                            Name      = "M. Lohr " + i,
                            ShirtName = "Lohr" + i,
                            Overall   = r.Next(40, 99),
                        };
                        results.Add(player);
                    }
                }

                // Second team
                for (int j = 0; j < r.Next(20, 28); j++)
                {
                    Player player = new Player()
                    {
                        PlayerId  = Guid.NewGuid().ToString(),
                        ClubId    = club.Id,
                        TeamId    = club.ReservesTeamId,
                        Name      = "M. Lohr " + i,
                        ShirtName = "Lohr" + i,
                        Overall   = r.Next(40, 99),
                    };
                    results.Add(player);
                }

                // Youth team
                for (int j = 0; j < r.Next(20, 28); j++)
                {
                    Player player = new Player()
                    {
                        PlayerId  = Guid.NewGuid().ToString(),
                        ClubId    = club.Id,
                        TeamId    = club.YouthTeamId,
                        Name      = "M. Lohr " + i,
                        ShirtName = "Lohr" + i,
                        Overall   = r.Next(40, 99),
                    };
                    results.Add(player);
                }
            }

            await this.players.InsertManyAsync(results);

            return(results);
        }