public IHttpActionResult PostOwPlayerRecFilter(int PlayerID, owFilter filter)
        {
            var Ows = OwMatchFilter(PlayerID, filter);
            List <PlayerRecomendation> recom = new List <PlayerRecomendation>();
            List <Match> playerMatches       = db.Matches.Where(x => x.IdPlayer1 == PlayerID || x.IdPlayer2 == PlayerID).AsEnumerable().ToList();

            if (Ows == null)
            {
                return(BadRequest("Jogador que requisitou o match não consta no banco"));
            }
            else
            {
                foreach (OwPlayer ow in Ows)
                {
                    if (playerMatches.Find(pm => pm.IdPlayer1 == ow.idHalf || pm.IdPlayer2 == ow.idHalf) != null)
                    {
                        continue;
                    }
                    PlayerRecomendation reco = new PlayerRecomendation()
                    {
                        playerFound   = db.Gamers.Find(ow.idHalf),
                        PlayerRecName = "filtro Overwatch",
                        aproximity    = 0f
                    };
                    recom.Add(reco);
                }
            }

            return(Ok(recom));
        }
Esempio n. 2
0
        private List <PlayerRecomendation> adjPlayersConnections(Player logado)
        {
            List <Match> logadoMatches = db.Matches
                                         .Where(x => x.IdPlayer1 == logado.ID || x.IdPlayer2 == logado.ID)
                                         .AsEnumerable().ToList();
            List <PlayerRecomendation> players = new List <PlayerRecomendation>();

            foreach (Match m in logadoMatches)
            {
                Player found = m.IdPlayer1 == logado.ID ? m.Player2 : m.Player1;//await db.Gamers.FindAsync(idToFind);
                if (found != null)
                {
                    List <Match> matchesAdj = db.Matches
                                              .Where(y => (y.IdPlayer1 != logado.ID && y.IdPlayer2 != logado.ID) &&
                                                     (y.IdPlayer1 == found.ID || y.IdPlayer2 == found.ID))
                                              .AsEnumerable().ToList();
                    foreach (Match m2 in matchesAdj)
                    {
                        PlayerRecomendation recomendation = new PlayerRecomendation()
                        {
                            PlayerRecName = found.Nickname, aproximity = 0
                        };
                        Player adj = m2.IdPlayer1 == found.ID ? m2.Player2 : m2.Player1;
                        if (adj != null && logadoMatches.FirstOrDefault(x => x.IdPlayer1 == adj.ID || x.IdPlayer2 == adj.ID) == null && players.FirstOrDefault(p => p.playerFound.ID == adj.ID) == null)
                        {
                            recomendation.playerFound = adj;
                            players.Add(recomendation);
                        }
                    }
                }
            }

            return(players);
        }