Example #1
0
        private void FillRelations(IEnumerable <PersonStatistics> personStatistics)
        {
            IEnumerable <Team>    teams   = new Team[0];
            IEnumerable <Tourney> toureys = new Tourney[0];

            if (FillTeams)
            {
                var teamDal = new TeamDal();
                teamDal.SetContext(Context);

                var teamIds = new List <int>();
                teamIds.AddRange(personStatistics.Select(r => r.teamId).Distinct());

                teams = teamDal.GetTeams(teamIds).ToList();
            }

            if (FillTourneys)
            {
                var tourneyDal = new TourneyDal();
                tourneyDal.SetContext(Context);

                var tourneyIds = new List <int>();
                tourneyIds.AddRange(personStatistics.Select(r => (int)r.tourneyId).Distinct());

                toureys = tourneyDal.GetTourneys(tourneyIds).ToList();
            }

            if (teams.Any() || toureys.Any())
            {
                foreach (PersonStatistics ps in personStatistics)
                {
                    if (FillTeams && teams.Any())
                    {
                        ps.team = teams.FirstOrDefault(t => t.Id == ps.teamId);

                        if (ps.team == null)
                        {
                            throw new DalMappingException(nameof(ps.team), typeof(PersonStatistics));
                        }
                    }

                    if (FillTourneys && toureys.Any())
                    {
                        ps.tourney = toureys.FirstOrDefault(t => t.Id == ps.tourneyId);

                        if (ps.tourney == null)
                        {
                            throw new DalMappingException(nameof(ps.tourney), typeof(PersonStatistics));
                        }
                    }
                }
            }
        }
Example #2
0
        private void FillRelations(IEnumerable <TableRecord> tableRecords)
        {
            if (Guard.IsEmptyIEnumerable(tableRecords))
            {
                return;
            }

            Tourney            tourney = null;
            IEnumerable <Team> teams   = new Team[0];

            if (FillTeams)
            {
                var teamDal = new TeamDal();
                teamDal.SetContext(Context);

                teams = teamDal.GetTeams(tableRecords.Select(r => r.teamId));
            }

            if (FillTourney)
            {
                var tourneyDal = new TourneyDal();
                tourneyDal.SetContext(Context);

                tourney = tourneyDal.GetTourney(tableRecords.First().tourneyId);

                if (tourney == null)
                {
                    throw new DalMappingException(nameof(tourney), typeof(TableRecord));
                }
            }

            if (teams.Any() || tourney != null)
            {
                foreach (TableRecord record in tableRecords)
                {
                    if (FillTeams && teams.Any())
                    {
                        record.Team = teams.FirstOrDefault(t => t.Id == record.teamId);

                        if (record.Team == null)
                        {
                            throw new DalMappingException(nameof(record.Team), typeof(TableRecord));
                        }
                    }

                    record.tourney = FillTourney ? tourney : null;
                }
            }
        }
Example #3
0
        private void FillRelations(IEnumerable <Round> rounds)
        {
            if (Guard.IsEmptyIEnumerable(rounds))
            {
                return;
            }

            IEnumerable <Tourney> tourneys = new Tourney[0];
            GameDal dalGames = null;

            if (FillTourneys)
            {
                var tourneyDal = new TourneyDal();
                tourneyDal.SetContext(Context);

                var tourneyIds = new List <int>();
                tourneyIds.AddRange(rounds.Select(r => (int)r.tourneyId));

                tourneys = tourneyDal.GetTourneys(tourneyIds.Distinct()).ToList();

                if (!tourneys.Any())
                {
                    throw new DalMappingException(nameof(tourneys), typeof(Round));
                }
            }

            if (FillProtocols)
            {
                FillGames = true;
            }

            if (FillGames)
            {
                dalGames = new GameDal();
                dalGames.FillProtocols = FillProtocols;
                dalGames.SetContext(Context);
            }

            if (tourneys.Any() || dalGames != null)
            {
                foreach (Round round in rounds)
                {
                    if (FillTourneys && tourneys.Any())
                    {
                        round.tourney = tourneys.FirstOrDefault(t => t.Id == round.tourneyId);

                        if (round.tourney == null)
                        {
                            throw new DalMappingException(nameof(round.tourney), typeof(Round));
                        }
                    }
                    else
                    {
                        round.tourney = null;
                    }

                    if (dalGames != null)
                    {
                        round.Game = dalGames.GetRoundGames(round.Id).ToArray();
                    }
                    else
                    {
                        round.Game = null;
                    }
                }
            }
        }