Exemple #1
0
        public IActionResult Index()
        {
            List <Competition>    allCompetitions      = _competitionRepository.GetAll();
            List <SportsComplex>  allSportsComplexes   = _sportsComplexRepository.GetAll();
            Dictionary <int, int> numberOfParticipants = (
                from athlete in _athletePerformanceRepository.GetAll()
                group athlete by athlete.CompetitionId into athleteGroup
                select new {
                CompetitionId = athleteGroup.Key,
                NumberOfParticipants = athleteGroup.Count()
            }).ToDictionary(
                pair => pair.CompetitionId,
                pair => pair.NumberOfParticipants);
            List <CompetitionDto> result = (from competition in allCompetitions
                                            join sportsComplex in allSportsComplexes on competition.SportsComplexId equals sportsComplex.Id
                                            select new CompetitionDto
            {
                Id = competition.Id,
                Name = competition.Name,
                StartDate = competition.StartDate,
                EndDate = competition.EndDate,
                SportsComplexName = sportsComplex.Name,
                NumberOfParticipants = numberOfParticipants.ContainsKey(competition.Id)
                        ? numberOfParticipants[competition.Id]
                        : 0
            }).ToList();

            return(View(result));
        }
Exemple #2
0
        public IActionResult Index()
        {
            List <Athlete>               allAthletes     = _athleteRepository.GetAll();
            List <AthletePerformance>    allPerformances = _athletePerformanceRepository.GetAll();
            List <Competition>           allCompetitions = _competitionRepository.GetAll();
            List <AthletePerformanceDto> result          = (from performance in allPerformances
                                                            join competition in allCompetitions on performance.CompetitionId equals competition.Id
                                                            join athlete in allAthletes on performance.AthleteId equals athlete.Id
                                                            select new AthletePerformanceDto
            {
                Id = performance.Id,
                AthleteName = athlete.Name,
                AthleteSurname = athlete.Surname,
                AthletePatronymicName = athlete.PatronymicName,
                CompetitionName = competition.Name,
                PerformanceDate = performance.PerformanceDate,
                Score = performance.Score
            }).ToList();

            return(View(result));
        }