private void CloseGame() { Game gameToBeClosed = _repoG.FindById(actualGameId); IQueryable <GamePlayer> GamePlayersByGameId_IQueryable = _repoP.FindByGameId(actualGameId); ICollection <GamePlayer> GamePlayersByGameId_List = new List <GamePlayer>(); // trecho necessário para converter de IQueryable para List foreach (GamePlayer gamePlayer in GamePlayersByGameId_IQueryable) // { // GamePlayersByGameId_List.Add(gamePlayer); // } // gameToBeClosed.KillMethods = _repoKM.GetAll() .Where(i => i.GameId == actualGameId) .ToList(); gameToBeClosed.GamePlayers = GamePlayersByGameId_List; gameToBeClosed.TotalKills = GamePlayersByGameId_List.Select(k => k.Kills).Sum(); _repoG.Update(gameToBeClosed); }
public ActionResult <GameViewModel> GetById(int id) { if (_repoG.GetAll().Count < id) { return(NotFound()); } var result = _mapper.Map <GameViewModel>(_repoG.FindById(id)); result.Players = _mapper.Map <List <PlayerViewModel> >(_repoP.FindByGameId(id).Select(p => p.Player)); result.KillMethods = _mapper.Map <List <KillMethodViewModel> >(_repoKM.GetAll().Where(i => i.GameId == result.Id).ToList()); result.Players.RemoveAll(x => x.Name == "<world>"); return(Ok(result)); }