public IHttpActionResult GetFutureMatchesByLeagueId(long leagueId)
        {
            DateTime now = DateTime.Now;
            long seasonId = GetCurrentSeasonId(leagueId, now);
            if (seasonId < 0)
                return Ok();

            season _season = null;
            List<WeekDTO> weeks = new List<WeekDTO>();
            using (var context = new escorcenterdbEntities())
            {
                week[] _weeks = (from w in context.weeks where w.enabled == true && w.season == seasonId && now <= w.dateTo select w).OrderBy(w => w.dateFrom).ToArray<week>();
                foreach (week _week in _weeks)
                {
                    WeekDTO week = GetFutureMatchesByWeekId(_week.id, now);
                    if (week != null)
                    {
                        weeks.Add(week);
                    }
                }
                _season = (from s in context.seasons where s.id == seasonId select s).FirstOrDefault<season>();
            }
            if (_season == null)
            {
                return Ok();
            }
            SeasonDTO season = new SeasonDTO();
            season.Title = _season.title;
            season.DateFrom = _season.dateFrom.ToString();
            season.DateTo = _season.dateTo.ToString();
            season.Description = _season.description;
            season.Id = _season.id;
            season.League = _season.league;
            season.Weeks.AddRange(weeks);
            return Ok(season);
        }
        public IHttpActionResult GetResultTable(int leagueId)
        {
            long seasonId = GetCurrentSeasonId(leagueId, DateTime.Now);
            if (seasonId == 0)
            {
                return Ok();
            }

            scoretableview[] _scoreTable = null;
            season _season = null;
            List<ScoreTableResultDTO> scoreTable = new List<ScoreTableResultDTO>();

            using (var context = new escorcenterdbEntities())
            {
                _scoreTable = (from st in context.scoretableviews where st.season == seasonId select st).OrderBy(st => st.GamesWon.Value * 3 + st.GamesDrawn.Value * 1).ToArray<scoretableview>();
                _season = (from s in context.seasons where s.id == seasonId && s.enabled == true select s).FirstOrDefault<season>();

                if (_scoreTable == null || _season == null)
                {
                    return NotFound();
                }

                foreach (scoretableview st in _scoreTable)
                {
                    team _team = (from t in context.teams where t.Id == st.team select t).FirstOrDefault<team>();

                    String leagueName = getLeagueNameById(_team.League);
                    ScoreTableResultDTO result = new ScoreTableResultDTO
                    {
                        Team = AutoMapper.Mapper.Map<team, TeamDTO>(_team),
                        GamesDrawn = st.GamesDrawn.Value,
                        GamesLost = st.GamesLost.Value,
                        GamesPlayed = st.GamesPlayed.Value,
                        GamesWined = st.GamesWon.Value,
                        //Cambiar esto a hacerlo dinamico, no solo para el fut
                        Points = st.GamesWon.Value * 3 + st.GamesDrawn.Value * 1,
                        ScoreAgainst = (long)st.ScoreAgainst.Value,
                        ScoreDifference = (long)st.ScoreDifference.Value,
                        ScoreFavor = (long)st.ScoreFavor.Value,
                        League = leagueName
                    };

                    scoreTable.Add(result);
                }
            }
            if (_season == null)
            {
                return Ok();
            }

            scoreTable.OrderBy(r => r.Points);

            SeasonDTO season = new SeasonDTO
            {
                DateFrom = _season.dateFrom.ToString(),
                DateTo = _season.dateTo.ToString(),
                Description = _season.description,
                Id = _season.id,
                League = _season.league,
                Title = _season.title
            };

            season.ScoreTableResult.AddRange(scoreTable);
            return Ok(season);
        }