示例#1
0
        public async Task <RoboFanEntity> AddAsync(RoboFanEntity newFan, CancellationToken ct = default)
        {
            _context.RoboFan.Add(newFan);
            await _context.SaveChangesAsync(ct);

            return(newFan);
        }
示例#2
0
        public async Task <bool> UpdateAsync(RoboFanEntity fan, CancellationToken ct = default)
        {
            // ensure record exists
            if (!await RoboFanExists(fan.Id, ct))
            {
                return(false);
            }

            // update the record
            _context.RoboFan.Update(fan);
            await _context.SaveChangesAsync(ct);

            return(true);
        }
示例#3
0
        public static List <RoboFanTeamRanking> GenerateTeamRankings(RoboFanEntity robofan, List <LeagueTeam> leagueTeams)
        {
            const int maxposteams = 2;
            const int maxnegteams = 3;
            List <RoboFanTeamRanking> listRankings = new List <RoboFanTeamRanking>();

            // get a list of available team ids to use for fan rankings
            var teams = (from team in leagueTeams
                         where (team.Id != robofan.PrimaryTeamId)
                         select team.Id).ToList <int>();

            // select the positive and negative teams for this fan
            SelectRandomTeams(maxposteams, 1, robofan, leagueTeams, ref teams, ref listRankings);
            SelectRandomTeams(maxnegteams, -1, robofan, leagueTeams, ref teams, ref listRankings);

            return(listRankings);
        }
示例#4
0
        private static void SelectRandomTeams(int numteams, int teamranking, RoboFanEntity robofan, List <LeagueTeam> leagueTeams, ref List <int> teamids, ref List <RoboFanTeamRanking> listRankings)
        {
            // select the number of requested teams
            Random randNum = new Random();

            for (int index = 0; index < numteams; index++)
            {
                // create a new object to save the results int
                var ranking = new RoboFanTeamRanking();
                ranking.RobotFanId = robofan.Id;
                ranking.Ranking    = teamranking;

                // select a random index from the remaining teams and save in the object
                var teampos = randNum.Next(teamids.Count - 1);
                ranking.LeagueTeamId = teamids[teampos];
                ranking.LeagueTeam   = (from team in leagueTeams
                                        where team.Id == ranking.LeagueTeamId
                                        select team).SingleOrDefault();

                // add the object to the return list
                listRankings.Add(ranking);
                teamids.RemoveAt(teampos);
            }
        }