public IEnumerable<TeamRanking> GetStandings(int id)
        {
            var teamRanking = new List<TeamRanking>();

            var allTeams = db.Teams.ToList();
            var teams = new List<Team>();
            foreach (var team in allTeams)
            {
                foreach (var season in team.Seasons)
                {
                    if (season.Id.Equals(id))
                    {
                        teams.Add(team);
                    }
                }
            }
            var weeks = db.Weeks.Where(x => x.SeasonId.Equals(id)).ToList();

            foreach (var team in teams)
            {
                var recentMatchForm = new List<MatchFormModel>();
                var tamRank = new TeamRanking(team.Id, team.Name);
                foreach (var week in weeks)
                {

                    var matches = db.Matches.OrderBy(x => x.Date).Where(x => x.WeekId.Equals(week.Id)).ToList();
                    if (matches == null)
                        continue;
                    foreach (var match in matches)
                    {
                        if (match.Played == false)
                            continue;

                        if (team.Id.Equals(match.HomeId))
                        {
                            var matchForm = Mapper.Map<MatchFormModel>(match);
                            matchForm.GoalsFor = match.HomeGoals;
                            matchForm.GoalsAgainst = match.AwayGoals;
                            tamRank.Games++;
                            tamRank.GoalsFor += match.HomeGoals;
                            tamRank.GoalsAgainst += match.AwayGoals;
                            tamRank.GoalsDifference += (match.HomeGoals - match.AwayGoals);
                            if (match.HomeGoals > match.AwayGoals)
                            {
                                matchForm.ResultClass = "win";
                                matchForm.Result = "נצחון";
                                tamRank.Wins++;
                                tamRank.Points += 3;
                            }
                            else if (match.HomeGoals == match.AwayGoals)
                            {
                                matchForm.ResultClass = "draw";
                                matchForm.Result = "תיקו";
                                tamRank.Draws++;
                                tamRank.Points += 1;
                            }
                            else if (match.HomeGoals < match.AwayGoals)
                            {
                                matchForm.ResultClass = "loss";
                                matchForm.Result = "הפסד";
                                tamRank.Losses++;

                            }
                            recentMatchForm.Add(matchForm);
                        }
                        else if (team.Id.Equals(match.AwayId))
                        {
                            var matchForm = Mapper.Map<MatchFormModel>(match);
                            matchForm.GoalsFor = match.AwayGoals;
                            matchForm.GoalsAgainst = match.HomeGoals;
                            tamRank.Games++;
                            tamRank.GoalsFor += match.AwayGoals;
                            tamRank.GoalsAgainst += match.HomeGoals;
                            tamRank.GoalsDifference += (match.AwayGoals - match.HomeGoals);
                            if (match.HomeGoals < match.AwayGoals)
                            {
                                matchForm.ResultClass = "win";
                                matchForm.Result = "נצחון";
                                tamRank.Wins++;
                                tamRank.Points += 3;
                            }
                            else if (match.HomeGoals == match.AwayGoals)
                            {
                                matchForm.ResultClass = "draw";
                                matchForm.Result = "תיקו";
                                tamRank.Draws++;
                                tamRank.Points += 1;
                            }
                            else if (match.HomeGoals > match.AwayGoals)
                            {
                                matchForm.ResultClass = "loss";
                                matchForm.Result = "הפסד";
                                tamRank.Losses++;
                            }
                            recentMatchForm.Add(matchForm);

                        }

                    }////matches
                }////////////weeks
                tamRank.MatchForm = recentMatchForm;
                teamRanking.Add(tamRank);
            }///////teams
            teamRanking = teamRanking.OrderByDescending(x => x.Points).ToList();
            var position = 1;
            foreach (var team in teamRanking)
            {
                team.Position = position++;
            }
            return teamRanking;
        }
        // GET api/Team/5
        public TeamRanking GetTeam(int id)
        {
            Team team = db.Teams.Find(id);
            if (team == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            var currentSeason = db.Seasons.OrderByDescending(x => x.Priority).FirstOrDefault();
            //var goals = db.Goals.Select(x => x.Player.TeamId.Equals(teamsModel.Id) && x.SeasonId.Equals(currentSeason.Id));


            var weeks = db.Weeks.Where(x => x.SeasonId.Equals(currentSeason.Id)).ToList();
            var recentMatchForm = new List<MatchFormModel>();
            var tamRank = new TeamRanking(team.Id, team.Name);
            foreach (var week in weeks)
            {
                
                var matches = db.Matches.OrderBy(x => x.Date).Where(x => x.WeekId.Equals(week.Id)).ToList();
                if (matches == null)
                    continue;
                foreach (var match in matches)
                {
                    if (match.Played == false)
                        continue;

                    if (team.Id.Equals(match.HomeId))
                    {
                        var matchForm = Mapper.Map<MatchFormModel>(match);
                        matchForm.GoalsFor = match.HomeGoals;
                        matchForm.GoalsAgainst = match.AwayGoals;
                        tamRank.Games++;
                        tamRank.GoalsFor += match.HomeGoals;
                        tamRank.GoalsAgainst += match.AwayGoals;
                        tamRank.GoalsDifference += (match.HomeGoals - match.AwayGoals);
                        if (match.HomeGoals > match.AwayGoals)
                        {
                            matchForm.ResultClass = "win";
                            matchForm.Result = "נצחון";
                            tamRank.Wins++;
                            tamRank.Points += 3;
                        }
                        else if (match.HomeGoals == match.AwayGoals)
                        {
                            matchForm.ResultClass = "draw";
                            matchForm.Result = "תיקו";
                            tamRank.Draws++;
                            tamRank.Points += 1;
                        }
                        else if (match.HomeGoals < match.AwayGoals)
                        {
                            matchForm.ResultClass = "loss";
                            matchForm.Result = "הפסד";
                            tamRank.Losses++;

                        }
                        recentMatchForm.Add(matchForm);
                    }
                    else if (team.Id.Equals(match.AwayId))
                    {
                        var matchForm = Mapper.Map<MatchFormModel>(match);
                        matchForm.GoalsFor = match.AwayGoals;
                        matchForm.GoalsAgainst = match.HomeGoals;
                        tamRank.Games++;
                        tamRank.GoalsFor += match.AwayGoals;
                        tamRank.GoalsAgainst += match.HomeGoals;
                        tamRank.GoalsDifference += (match.AwayGoals - match.HomeGoals);
                        if (match.HomeGoals < match.AwayGoals)
                        {
                            matchForm.ResultClass = "win";
                            matchForm.Result = "נצחון";
                            tamRank.Wins++;
                            tamRank.Points += 3;
                        }
                        else if (match.HomeGoals == match.AwayGoals)
                        {
                            matchForm.ResultClass = "draw";
                            matchForm.Result = "תיקו";
                            tamRank.Draws++;
                            tamRank.Points += 1;
                        }
                        else if (match.HomeGoals > match.AwayGoals)
                        {
                            matchForm.ResultClass = "loss";
                            matchForm.Result = "הפסד";
                            tamRank.Losses++;
                        }
                        recentMatchForm.Add(matchForm);

                    }

                }////matches
            }
            tamRank.MatchForm = recentMatchForm;
            return tamRank;
        }