public JsonResult FindThreeForOneTrades(int leagueId, int myTeamId, int otherTeamId)
        {
            //create player pools to find trades
            LeaguePlayerPool leaguePlayerPool = new LeaguePlayerPool(leagueId);
            TeamPlayerPool myTeamPlayerPool = new TeamPlayerPool(myTeamId);
            TeamPlayerPool theirTeamPlayerPool = new TeamPlayerPool(otherTeamId);

            //find trades
            List<TradeView> trades = leaguePlayerPool.FindTrades(myTeamPlayerPool, theirTeamPlayerPool, myTeamPlayerPool.ThreePlayerTradePool, theirTeamPlayerPool.OnePlayerTradePool);

            //return Json object with found trades
            return Json(new { Trades = trades });
        }
        private void FindTradesOld(ref List<Trade> allTrades,
                                TeamPlayerPool myTeamPlayerPool, TeamPlayerPool theirTeamPlayerPool,
                                IEnumerable<IEnumerable<Player>> myTradePool, IEnumerable<IEnumerable<Player>> theirTradePool)
        {
            IEnumerable<Trade> trades = from mySideOfTrade in myTradePool
                                        from theirSideOfTrade in theirTradePool
                                        select (new Trade(mySideOfTrade, theirSideOfTrade));

            foreach (Trade trade in trades)
            {
                if (Math.Abs(trade.Fairness) <= 5)
                {
                    trade.CalculateDifferentials(this, myTeamPlayerPool, theirTeamPlayerPool);
                    if (trade.MyDifferential > 0) { allTrades.Add(trade); }
                }
            }
        }
        public List<Trade> FindAllTrades(int myTeamId, int? otherTeamId)
        {
            //create table list to store each trade
            List<Trade> trades = new List<Trade>();

            //get my team and create team player pool
            TeamPlayerPool myTeamPlayerPool = new TeamPlayerPool(myTeamId);

            //create other team list
            List<Team> otherTeams = new List<Team>();
            if (otherTeamId != null && otherTeamId > 0)
            {
                otherTeams.Add(League.Teams.Where(t => t.TeamId == otherTeamId).FirstOrDefault());
            }
            else
            {
                otherTeams = League.Teams.ToList();
                otherTeams.Remove(League.Teams.Where(t => t.TeamId == otherTeamId).FirstOrDefault());
            }

            //for each other team, find trades
            foreach (Team otherTeam in otherTeams)
            {
                //load team player pool for this team
                TeamPlayerPool otherTeamPlayerPool = new TeamPlayerPool(otherTeam.TeamId);

                //find trades with this team
                FindTradesOld(ref trades, myTeamPlayerPool, otherTeamPlayerPool, myTeamPlayerPool.OnePlayerTradePool, otherTeamPlayerPool.OnePlayerTradePool); //1 for 1
                FindTradesOld(ref trades, myTeamPlayerPool, otherTeamPlayerPool, myTeamPlayerPool.OnePlayerTradePool, otherTeamPlayerPool.TwoPlayerTradePool); //1 for 2
                FindTradesOld(ref trades, myTeamPlayerPool, otherTeamPlayerPool, myTeamPlayerPool.OnePlayerTradePool, otherTeamPlayerPool.ThreePlayerTradePool); //1 for 3
                FindTradesOld(ref trades, myTeamPlayerPool, otherTeamPlayerPool, myTeamPlayerPool.TwoPlayerTradePool, otherTeamPlayerPool.OnePlayerTradePool); //2 for 1
                FindTradesOld(ref trades, myTeamPlayerPool, otherTeamPlayerPool, myTeamPlayerPool.TwoPlayerTradePool, otherTeamPlayerPool.TwoPlayerTradePool); //2 for 2
                FindTradesOld(ref trades, myTeamPlayerPool, otherTeamPlayerPool, myTeamPlayerPool.TwoPlayerTradePool, otherTeamPlayerPool.ThreePlayerTradePool); //2 for 3
                FindTradesOld(ref trades, myTeamPlayerPool, otherTeamPlayerPool, myTeamPlayerPool.ThreePlayerTradePool, otherTeamPlayerPool.OnePlayerTradePool); //3 for 1
                FindTradesOld(ref trades, myTeamPlayerPool, otherTeamPlayerPool, myTeamPlayerPool.ThreePlayerTradePool, otherTeamPlayerPool.TwoPlayerTradePool); //3 for 2
                FindTradesOld(ref trades, myTeamPlayerPool, otherTeamPlayerPool, myTeamPlayerPool.ThreePlayerTradePool, otherTeamPlayerPool.ThreePlayerTradePool); //3 for 3
            }

            return trades.OrderByDescending(t => t.CompositeDifferential).Distinct().ToList();
        }
        //private void FindOneForOneTrades(ref List<Trade> allTrades, TeamPlayerPool myTeamPlayerPool, TeamPlayerPool theirTeamPlayerPool)
        //{
        //    //get team trade pools
        //    IEnumerable<IEnumerable<Player>> myTradePool = myTeamPlayerPool.OnePlayerTradePool();
        //    IEnumerable<IEnumerable<Player>> theirTradePool = theirTeamPlayerPool.OnePlayerTradePool();
        //    //find trades with trade pools
        //    FindTrades(ref allTrades, myTradePool, theirTradePool, myTeamPlayerPool, theirTeamPlayerPool);
        //}
        public List<TradeView> FindTrades(TeamPlayerPool myTeamPlayerPool, TeamPlayerPool theirTeamPlayerPool,
                               IEnumerable<IEnumerable<Player>> myTradePool, IEnumerable<IEnumerable<Player>> theirTradePool)
        {
            List<TradeView> foundTrades = new List<TradeView>();
            IEnumerable<Trade> trades = from mySideOfTrade in myTradePool
                                        from theirSideOfTrade in theirTradePool
                                        select (new Trade(mySideOfTrade, theirSideOfTrade));
            trades = trades.Distinct();

            foreach (Trade trade in trades)
            {
                if (Math.Abs(trade.Fairness) <= 5)
                {
                    trade.CalculateDifferentials(this, myTeamPlayerPool, theirTeamPlayerPool);
                    if (trade.MyDifferential > 0) {
                        foundTrades.Add(trade.GetTradeView());
                    }
                }
            }

            return foundTrades;
        }