Beispiel #1
0
        public JumpDTO GetBestResultForAthlete(int idAthlete)
        {
            ICompetitionRepository competitionRepository = new CompetitionRepository(context: _context);
            IEliminationRepository eliminationRepository = new EliminationRepository(_context);
            IContestRepository     contestRepository     = new ContestRepository(_context);

            JumpDTO jump          = new JumpDTO();
            var     jumps         = GetAllForAthlete(idAthlete).OrderByDescending(x => x.Height);
            var     onlyGoodJumps = jumps.Where(x => x.IdJumpStatus1 == 1 || x.IdJumpStatus2 == 1 || x.IdJumpStatus3 == 1).FirstOrDefault();

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

            jump.Height = onlyGoodJumps.Height;
            if (onlyGoodJumps.IdContest != null)
            {
                jump.IsContest     = true;
                jump.IsElimination = false;
                var contest     = contestRepository.FindById(onlyGoodJumps.IdContest.Value);
                var competition = competitionRepository.GetAllForAthlete(idAthlete).Where(x => x.IdCompetition == contest.IdCompetition).FirstOrDefault();

                jump.DateOfRecord    = contest.ContestDate;
                jump.CompetitionName = competition.Name;
            }
            else if (onlyGoodJumps.IdElimination != null)
            {
                jump.IsContest     = false;
                jump.IsElimination = true;
                var elimination = eliminationRepository.FindById(onlyGoodJumps.IdElimination.Value);
                var competition = competitionRepository.GetAllForAthlete(idAthlete).Where(x => x.IdCompetition == elimination.IdCompetition).FirstOrDefault();

                jump.DateOfRecord    = elimination.EliminationDate;
                jump.CompetitionName = competition.Name;
            }
            return(jump);
        }