Пример #1
0
        public TeammatesDTO getTeammates(int pid1, int pid2)
        {
            int wins   = 0;
            int losses = 0;

            var p1 = getPlayerName(pid1);
            var p2 = getPlayerName(pid2);

            var pid1Games = getAllGameInfoByPid(pid1);
            var pid2Games = getAllGameInfoByPid(pid2);

            var games = (from g1 in pid1Games join g2 in pid2Games
                         on g1.gid equals g2.gid
                         where (g1.teamOne == true && g2.teamOne == true) || (g1.teamTwo == true && g2.teamTwo == true)
                         select new TeammatesGames
            {
                gid = g1.gid,
                teamOneScore = g1.teamOneScore,
                teamTwoScore = g1.teamTwoScore,
                teamOne = g1.teamOne,
                teamTwo = g1.teamTwo,
                victory = false
            }).ToList();

            foreach (TeammatesGames game in games)
            {
                game.teamOneList = getTeamOneList(game.gid);
                game.teamTwoList = getTeamTwoList(game.gid);

                if (game.teamOne)
                {
                    if (game.teamOneScore > game.teamTwoScore)
                    {
                        game.victory = true;
                        wins++;
                    }
                    else
                    {
                        losses++;
                    }
                }
                else
                {
                    if (game.teamTwoScore > game.teamOneScore)
                    {
                        game.victory = true;
                        wins++;
                    }
                    else
                    {
                        losses++;
                    }
                }
            }

            var teammates = new TeammatesDTO
            {
                p1             = p1,
                p2             = p2,
                wins           = wins,
                losses         = losses,
                count          = games.Count,
                TeammatesGames = games
            };

            return(teammates);
        }