public async Task <List <RoundViewModel> > GetAllMovesForCurrentGame(Guid id) { List <Move> moves = (await _moveRepository.GetAllMovesForOneGame(id)).ToList(); List <Player> allPlayersExist = (await _playerRepository.GetAll()).ToList(); var rounds = new List <RoundViewModel>(); foreach (var item in moves) { rounds.Add(new RoundViewModel { CardValue = item.CardName, Id = item.Id, GameId = item.GameId, PlayerNickName = allPlayersExist.FirstOrDefault(p => p.Id == item.PlayerId)?.NickName, RoundNumber = item.MoveNumber }); } return(rounds); }
public async Task <GameViewModel> ShowPlayerMoves(Guid id) { IOrderedEnumerable <Move> listOfMoves = (await _moveRepository.GetAllMovesForOneGame(id)).OrderBy(p => p.PlayerId); var allPlayers = await _playerRepository.GetAll(); var gameViewModel = new GameViewModel { Rounds = listOfMoves.Select(p => new RoundViewModel { Id = p.Id, CardValue = p.CardName, GameId = p.GameId, RoundNumber = p.MoveNumber, PlayerNickName = allPlayers.SingleOrDefault(m => m.Id == p.PlayerId).NickName }).ToList() }; return(gameViewModel); }