コード例 #1
0
ファイル: PersonCareerDal.cs プロジェクト: DelLitt/FCWebSite
        private void FillRelations(IEnumerable <PersonCareer> personCareers)
        {
            IEnumerable <Team> teams = new Team[0];

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

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

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

            if (teams.Any())
            {
                foreach (PersonCareer pc in personCareers)
                {
                    if (FillTeams && teams.Any())
                    {
                        pc.team = teams.FirstOrDefault(t => t.Id == pc.teamId);

                        if (pc.team == null)
                        {
                            throw new DalMappingException(nameof(pc.team), typeof(PersonCareer));
                        }
                    }
                }
            }
        }
コード例 #2
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));
                        }
                    }
                }
            }
        }
コード例 #3
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;
                }
            }
        }
コード例 #4
0
ファイル: PersonDal.cs プロジェクト: DelLitt/FCWebSite
        private void FillRelations(IEnumerable <Person> persons)
        {
            if (Guard.IsEmptyIEnumerable(persons))
            {
                return;
            }

            IEnumerable <Team>         teams         = new Team[0];
            IEnumerable <City>         cities        = new City[0];
            IEnumerable <PersonRole>   personRoles   = new PersonRole[0];
            IEnumerable <PersonCareer> personCareers = new PersonCareer[0];

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

                var teamIds = new List <int>();
                teamIds.AddRange(persons.Where(p => p.teamId.HasValue).Select(p => p.teamId.Value).Distinct());

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

            if (FillCities)
            {
                var cityDal = new CityDal();
                cityDal.FillCountries = true;
                cityDal.SetContext(Context);

                var cityIds = new List <int>();
                cityIds.AddRange(persons.Where(p => p.cityId.HasValue).Select(p => p.cityId.Value).Distinct());

                cities = cityDal.GetCities(cityIds).ToList();
            }

            if (FillPersonRoles)
            {
                var personRoleDal = new PersonRoleDal();
                personRoleDal.SetContext(Context);

                var personRoleIds = new List <int>();
                personRoleIds.AddRange(persons.Where(p => p.roleId.HasValue).Select(p => (int)p.roleId.Value).Distinct());

                personRoles = personRoleDal.GetPersonRoles(personRoleIds).ToList();
            }

            if (FillPersonCareer)
            {
                var personCareerDal = new PersonCareerDal();
                personCareerDal.SetContext(Context);

                var personIds = new List <int>();
                personIds.AddRange(persons.Select(p => p.Id).Distinct());

                personCareers = personCareerDal.GetPersonCareer(personIds).ToList();
            }

            if (teams.Any() || cities.Any() || personRoles.Any() || personCareers.Any())
            {
                foreach (Person person in persons)
                {
                    if (FillTeams && teams.Any())
                    {
                        person.team = teams.FirstOrDefault(t => t.Id == person.teamId);
                        if (person.teamId.HasValue && person.team == null)
                        {
                            throw new DalMappingException(nameof(person.team), typeof(Person));
                        }
                    }

                    if (FillCities && cities.Any())
                    {
                        person.city = cities.FirstOrDefault(c => c.Id == person.cityId);
                        if (person.cityId.HasValue && person.city == null)
                        {
                            throw new DalMappingException(nameof(person.city), typeof(Person));
                        }
                    }

                    if (FillPersonRoles && personRoles.Any())
                    {
                        person.role = personRoles.FirstOrDefault(pr => pr.Id == person.roleId);
                        if (person.roleId.HasValue && person.role == null)
                        {
                            throw new DalMappingException(nameof(person.role), typeof(Person));
                        }
                    }

                    if (FillPersonCareer && personCareers.Any())
                    {
                        person.PersonCareer = personCareers.Where(pc => pc.personId == person.Id).ToList();
                    }
                }
            }
        }
コード例 #5
0
ファイル: GameDal.cs プロジェクト: DelLitt/FCWebSite
        private void FillRelations(IEnumerable <Game> games)
        {
            if (Guard.IsEmptyIEnumerable(games))
            {
                return;
            }

            IEnumerable <Team>           teams     = new Team[0];
            IEnumerable <Round>          rounds    = new Round[0];
            IEnumerable <Stadium>        stadiums  = new Stadium[0];
            IEnumerable <ProtocolRecord> protocols = new ProtocolRecord[0];

            if (FillTourneys)
            {
                FillRounds = true;
            }

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

                var teamIds = new List <int>();
                teamIds.AddRange(games.Select(g => g.homeId));
                teamIds.AddRange(games.Select(g => g.awayId));

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

                if (!teams.Any())
                {
                    throw new DalMappingException(nameof(teams), typeof(Game));
                }
            }

            if (FillRounds)
            {
                var roundDal = new RoundDal();
                roundDal.SetContext(Context);
                roundDal.FillTourneys = FillTourneys;

                var roundIds = new List <int>();
                roundIds.AddRange(games.Select(g => (int)g.roundId));

                rounds = roundDal.GetRounds(roundIds.Distinct()).ToList();

                if (!rounds.Any())
                {
                    throw new DalMappingException(nameof(rounds), typeof(Game));
                }
            }

            if (FillStadiums)
            {
                var stadiumDal = new StadiumDal();
                stadiumDal.SetContext(Context);
                stadiumDal.FillCities = true;

                var stadiumIds = new List <int>();
                stadiumIds.AddRange(games.Where(s => s.stadiumId.HasValue).Select(g => (int)g.stadiumId));

                stadiums = stadiumDal.GetStadiums(stadiumIds.Distinct()).ToList();
            }

            if (FillProtocols)
            {
                var protocolRecordDal = new ProtocolRecordDal();

                var gameIds = new List <int>();
                gameIds.AddRange(games.Select(g => g.Id).Distinct());

                protocols = protocolRecordDal.GetProtocol(gameIds).ToList();
            }

            foreach (Game game in games)
            {
                if (FillTeams && teams.Any())
                {
                    game.home = teams.FirstOrDefault(t => t.Id == game.homeId);
                    if (game.home == null)
                    {
                        throw new DalMappingException(nameof(game.home), typeof(Game));
                    }

                    game.away = teams.FirstOrDefault(t => t.Id == game.awayId);
                    if (game.away == null)
                    {
                        throw new DalMappingException(nameof(game.away), typeof(Game));
                    }
                }
                else
                {
                    game.home = null;
                    game.away = null;
                }

                if (FillRounds && rounds.Any())
                {
                    game.round = rounds.FirstOrDefault(r => r.Id == game.roundId);
                    if (game.round == null)
                    {
                        throw new DalMappingException(nameof(game.round), typeof(Game));
                    }
                }
                else
                {
                    game.round = null;
                }

                if (FillStadiums && stadiums.Any())
                {
                    game.stadium = stadiums.FirstOrDefault(r => r.Id == game.stadiumId);
                }
                else
                {
                    game.stadium = null;
                }

                if (FillProtocols && protocols.Any())
                {
                    game.ProtocolRecord = protocols.Where(p => p.gameId == game.Id).ToList();
                }
                else
                {
                    game.ProtocolRecord = null;
                }
            }
        }