Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        private RankGroup CreateGroupRank(Group group, List <Stage> stages, int index, int?seasonId)
        {
            RankGroup rGroup = new RankGroup();

            rGroup.Title          = group.Name;
            rGroup.PointsEditType = group.PointEditType;
            var listGroup = db.GroupsTeams.Where(x => x.GroupId == group.GroupId).ToList();
            var teams     = new List <RankTeam>();

            foreach (var team in listGroup)
            {
                if (seasonId.HasValue)
                {
                    var details = team.Team?.TeamsDetails.FirstOrDefault(t => t.SeasonId == seasonId.Value);
                    if (details != null)
                    {
                        team.Team.Title = details.TeamName;
                    }
                }
                var points = group.PointEditType == 2 && team.Points != null ? (int)team.Points : 0;
                var res    = AddTeamIfNotExist(team.TeamId, teams, points, seasonId);
            }
            rGroup.Teams = teams;
            var rGroupsList = rGroup.Teams.ToList();

            GetPoints(rGroupsList, group, stages, index);

            rGroup.Teams      = @group.TypeId == 3 ? SetTeamsOrderPlayOff(rGroupsList, @group) : SetTeamsOrder(rGroupsList, @group);
            rGroup.IsAdvanced = group.IsAdvanced;

            if (group.PlayoffBrackets.Any())
            {
                rGroup.PlayoffBrackets = group.PlayoffBrackets.OrderBy(x => x.MaxPos).First().MinPos / 2;
            }
            else
            {
                rGroup.PlayoffBrackets = 0;
            }

            return(rGroup);
        }
Exemplo n.º 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);
        }