Пример #1
0
        public List <RankTeam> GetRankedTeams(int leagueId, int teamId)
        {
            var resList = new List <RankTeam>();

            RankLeague rLeague = CreateLeagueRankTable();

            if (rLeague != null)
            {
                var stages = rLeague.Stages.OrderByDescending(t => t.Number);
                var stage  = stages.Count() > 1 ? stages.ToArray()[1] : null;
                if (stage == null)
                {
                    return(null);
                }

                var group = stage.Groups.Where(gr => gr.Teams.Any(t => t.Id == teamId)).FirstOrDefault();
                if (group == null)
                {
                    return(null);
                }

                var teams = group.Teams.OrderBy(t => t.Position).ToList();
                for (int i = 0; i < teams.Count; i++)
                {
                    if (teams[i].Id == teamId)
                    {
                        resList.Add(teams[i]);
                    }
                }
            }

            return(resList);
        }
Пример #2
0
        public RankLeague CreateEmptyRankTable(int?seasonId = null)
        {
            var league = leagueRepo.GetById(this._leagueId);

            if (league == null)
            {
                return(null);
            }

            //Get game settings
            this.settings = league.Games.ToList();
            if (this.settings == null)
            {
                return(null);
            }
            RankLeague rLeague = new RankLeague();

            rLeague.LeagueId        = league.LeagueId;
            rLeague.Name            = league.Name;
            rLeague.Logo            = league.Logo;
            rLeague.AboutLeague     = league.AboutLeague;
            rLeague.LeagueStructure = league.LeagueStructure;
            var stages           = league.Stages;
            var index            = 0;
            var stagesNotArchive = stages.Where(e => e.IsArchive == false).ToList();

            foreach (var stage in stages.Where(e => e.IsArchive == false))
            {
                RankStage rStage = new RankStage();
                rStage.Number = stage.Number;
                foreach (var group in stage.Groups.Where(e => e.IsArchive == false))
                {
                    //LLCMS-191 don't show playoff or knockout type
                    if (group.GamesType.Name.Equals(GameType.Knockout) || group.GamesType.Name.Equals(GameType.Playoff))
                    {
                        continue;
                    }

                    RankGroup rGroup = CreateGroupRank(group, stagesNotArchive, index, seasonId);

                    SetTeamOrderByPosition(rGroup.Teams);
                    rStage.Groups.Add(rGroup);
                }

                rLeague.Stages.Add(rStage);
                index++;
            }
            return(rLeague);
        }
Пример #3
0
        public RankLeague CreateLeagueRankTable(int?seasonId = null)
        {
            //Get League
            var league = leagueRepo.GetByIdForRanks(_leagueId);

            if (league == null)
            {
                return(null);
            }

            //Get game settings
            this.settings = league.Games.ToList();
            if (this.settings == null)
            {
                return(null);
            }

            RankLeague rLeague = new RankLeague();

            rLeague.LeagueId        = league.LeagueId;
            rLeague.AboutLeague     = league.AboutLeague;
            rLeague.LeagueStructure = league.LeagueStructure;
            rLeague.Name            = league.Name;
            rLeague.Logo            = league.Logo;
            var stages           = league.Stages;
            var index            = 0;
            var stagesNotArchive = stages.Where(e => !e.IsArchive).ToList();

            foreach (var stage in stagesNotArchive)
            {
                RankStage rStage = new RankStage();
                rStage.Number = stage.Number;
                foreach (var group in stage.Groups.Where(e => !e.IsArchive))
                {
                    //LLCMS-191 don't show playoff or knockout type
                    if (group.GamesType.Name.Equals(GameType.Knockout) || group.GamesType.Name.Equals(GameType.Playoff))
                    {
                        continue;
                    }

                    RankGroup rGroup = CreateGroupRank(group, stagesNotArchive, index, seasonId);
                    rStage.Groups.Add(rGroup);
                    rGroup.GameType = group.GamesType.Name;
                    var result = CreateExtendedTable(group, rGroup.Teams);

                    rGroup.ExtendedTables.AddRange(result);
                }
                if (rStage.Groups.Any())
                {
                    rLeague.Stages.Add(rStage);
                }
                index++;
            }
            //  Update extended tables for all groups having "With their records" Point edit type
            //  in Netball (Catchball) leagues
            if (league.Union.Section.Alias == GamesAlias.NetBall)
            {
                foreach (var stage in rLeague.Stages.OrderByDescending(s => s.Number))
                {
                    if (stage.Groups.Any(g => g.PointsEditType == PointEditType.WithTheirRecords))
                    {
                        var extTables = rLeague.Stages.Where(s => s.Number < stage.Number)
                                        .SelectMany(s => s.Groups, (s, g) => g)
                                        .SelectMany(g => g.ExtendedTables, (g, et) => et);
                        foreach (var group in stage.Groups.Where(gr => gr.PointsEditType == PointEditType.WithTheirRecords))
                        {
                            foreach (var extTab in group.ExtendedTables)
                            {
                                var prevStagesScores = extTables.Where(et => et.TeamId == extTab.TeamId)
                                                       .SelectMany(et => et.Scores, (et, s) => s)
                                                       .Where(s => group.Teams.Any(gt => gt.Id == s.OpponentTeamId)).ToList();
                                prevStagesScores.AddRange(extTab.Scores);
                                extTab.Scores = prevStagesScores;
                            }
                        }
                    }
                }
            }

            SetTeamOrderByPosition(rLeague.Stages);

            return(rLeague);
        }