Esempio n. 1
0
        public IActionResult ViewBallot(int id)
        {
            var            teams           = BuildTeamList(id);
            Ballot         ballot          = _context.Ballot.FirstOrDefault(b => b.BallotId == id);
            Debate         debate          = _context.Debate.FirstOrDefault(d => d.DebateId == ballot.DebateId);
            IndividualTeam affirmativeTeam = _context.IndividualTeam.FirstOrDefault(i => i.IndividualTeamId == debate.AffirmativeTeamId);
            IndividualTeam negativeTeam    = _context.IndividualTeam.FirstOrDefault(i => i.IndividualTeamId == debate.NegativeTeamId);
            var            currentUserId   = this.User.FindFirstValue(ClaimTypes.NameIdentifier).ToString();
            Judge          judge           = _context.Judge.FirstOrDefault(t => t.ApplicationUserId == currentUserId);
            Round          round           = _context.Round.FirstOrDefault(r => r.RoundId == ballot.RoundId);

            JudgesBallotViewModel ballotVM = new JudgesBallotViewModel()
            {
                Ballot          = ballot,
                AffirmativeTeam = affirmativeTeam,
                NegativeTeam    = negativeTeam,
                Round           = round,
                Debate          = debate,
                Judge           = judge,
                Winner          = "Team",
                Loser           = "Team",
                TeamsInRound    = teams,
            };

            return(View(ballotVM));
        }
Esempio n. 2
0
        public IActionResult ViewBallot(JudgesBallotViewModel data)
        {
            Pairing        pairing          = _context.Pairing.Where(p => p.JudgeId == data.Ballot.JudgeId && p.RoundId == data.Ballot.RoundId).Single();
            IndividualTeam affTeam          = _context.IndividualTeam.FirstOrDefault(i => i.IndividualTeamId == pairing.AffirmativeTeamId);
            IndividualTeam negTeam          = _context.IndividualTeam.FirstOrDefault(i => i.IndividualTeamId == pairing.NegativeTeamId);
            Debater        firstAffSpeaker  = _context.Debater.FirstOrDefault(d => d.IndividualTeamId == affTeam.IndividualTeamId && d.SpeakerPosition == 1);
            Debater        secondAffSpeaker = _context.Debater.FirstOrDefault(d => d.IndividualTeamId == affTeam.IndividualTeamId && d.SpeakerPosition == 2);
            Debater        firstNegSpeaker  = _context.Debater.FirstOrDefault(d => d.IndividualTeamId == negTeam.IndividualTeamId && d.SpeakerPosition == 1);
            Debater        secondNegSpeaker = _context.Debater.FirstOrDefault(d => d.IndividualTeamId == negTeam.IndividualTeamId && d.SpeakerPosition == 2);
            Ballot         ballot           = data.Ballot;
            Round          round            = _context.Round.Where(r => r.RoundId == ballot.RoundId).Single();
            var            winnerId         = int.Parse(data.Winner);
            var            loserId          = int.Parse(data.Loser);
            IndividualTeam winningTeam      = _context.IndividualTeam.FirstOrDefault(i => i.IndividualTeamId == winnerId);
            IndividualTeam losingTeam       = _context.IndividualTeam.FirstOrDefault(i => i.IndividualTeamId == loserId);

            firstAffSpeaker.IndividualTournamentSpeakerPoints  += data.Ballot.FirstAffSpeakerPoints;
            secondAffSpeaker.IndividualTournamentSpeakerPoints += data.Ballot.SecondAffSpeakerPoints;
            firstNegSpeaker.IndividualTournamentSpeakerPoints  += data.Ballot.FirstNegSpeakerPoints;
            secondNegSpeaker.IndividualTournamentSpeakerPoints += data.Ballot.SecondNegSpeakerPoints;
            affTeam.SingleTournamentSpeakerPoints += (data.Ballot.FirstAffSpeakerPoints + data.Ballot.SecondAffSpeakerPoints);
            negTeam.SingleTournamentSpeakerPoints += (data.Ballot.FirstNegSpeakerPoints + data.Ballot.SecondNegSpeakerPoints);
            ballot.WinnerId  = winnerId;
            pairing.WinnerId = winnerId;
            if (round.RoundNumber > 4)
            {
                winningTeam.CumulativeAnnualElminationRoundWins++;
                losingTeam.SingleTournamentSpeakerPoints = 0;
                losingTeam.SingleTournamentWins          = 0;
                losingTeam.SingleTournamentLosses        = 0;
                losingTeam.TournamentAffirmativeRounds   = 0;
                losingTeam.TournamentNegativeRounds      = 0;
            }
            if (round.RoundNumber == 7)
            {
                TournamentResults result = _context.TournamentResults.Where(t => t.TournamentId == pairing.TournamentId && t.IndividualTeamId == winningTeam.IndividualTeamId).Single();
                result.EliminationRoundResult = "winner";
                _context.Update(result);
                winningTeam.CumulativeAnnualElminationRoundWins++;
                winningTeam.SingleTournamentSpeakerPoints = 0;
                winningTeam.SingleTournamentWins          = 0;
                winningTeam.SingleTournamentLosses        = 0;
                winningTeam.TournamentAffirmativeRounds   = 0;
                winningTeam.TournamentNegativeRounds      = 0;
                losingTeam.SingleTournamentSpeakerPoints  = 0;
                losingTeam.SingleTournamentWins           = 0;
                losingTeam.SingleTournamentLosses         = 0;
                losingTeam.TournamentAffirmativeRounds    = 0;
                losingTeam.TournamentNegativeRounds       = 0;
            }
            if (round.RoundNumber <= 4)
            {
                winningTeam.SingleTournamentWins++;
                losingTeam.SingleTournamentLosses++;
            }
            winningTeam.CumulativeAnnualWins++;
            losingTeam.CumulativeAnnualLosses++;
            ballot.BallotTurnedIn = true;
            _context.Update(ballot);
            _context.Update(pairing);
            _context.Update(winningTeam);
            _context.Update(losingTeam);
            _context.Update(firstAffSpeaker);
            _context.Update(secondAffSpeaker);
            _context.Update(firstNegSpeaker);
            _context.Update(secondNegSpeaker);
            _context.SaveChanges();
            return(RedirectToAction("BallotSubmission", "Judges"));
        }