예제 #1
0
        private IEnumerable <GameDataModel> GetResult(int id)
        {
            var data = from g in GameRepository.GetAll().ToList()
                       join p1 in PlayerRepository.GetAll().ToList() on g.playerOneId equals p1.id
                       join p2 in PlayerRepository.GetAll().ToList() on g.playerTwoId equals p2.id
                       where id == 0 || g.id == id
                       select new GameDataModel
            {
                id          = g.id,
                playerOneId = g.playerOneId,
                playerOne   = new PlayerDataModel
                {
                    id    = p1.id,
                    name  = p1.name,
                    score = RoundRepository.FindBy(r => r.gameId == g.id && g.playerOneId == r.roundWinnerId).Count()
                },
                playerTwoId = g.playerTwoId,
                playerTwo   = new PlayerDataModel
                {
                    id    = p2.id,
                    name  = p2.name,
                    score = RoundRepository.FindBy(r => r.gameId == g.id && g.playerTwoId == r.roundWinnerId).Count()
                },
                gameWinnerId = g.gameWinnerId.HasValue ? g.gameWinnerId.Value : 0,
                gameWinner   = (from w in PlayerRepository.FindBy(f => f.id == g.gameWinnerId.Value).ToList()
                                select new PlayerDataModel
                {
                    id = w.id,
                    name = w.name
                }).FirstOrDefault(),
                createdOn = g.createdOn,
                rounds    = (from r in RoundRepository.GetAll().ToList()
                             where r.gameId == g.id
                             select new RoundDataModel
                {
                    id = r.id,
                    gameId = r.gameId,
                    roundWinnerId = r.roundWinnerId.HasValue ? r.roundWinnerId.Value : 0,
                    playerOneMoveId = r.playerOneMoveId,
                    playerTwoMoveId = r.playerTwoMoveId
                })
            };

            return(data);
        }