/// <summary>
        /// Replaces ALL runJudgings for all contestants represented in the list passed in. Recalculates totals.
        /// This means that if only judgements for 3 of 5 criteria are sent in for a given contestant,
        /// all 5 existing will still be deleted.
        /// </summary>
        public virtual void ReplaceAllRunJudgings(List <RunJudging> list, Tournament tourney)
        {
            var expectedJudgeEntriesPerRun = tourney.GetExpectedJudgementCountPerRun();
            // Delete the ones we're replacing
            var rcIds         = list.Select(p => p.RoundContestantId).Distinct().ToList();
            var oldJudgements = RunJudgings.Where(p => rcIds.Contains(p.RoundContestantId)).ToList();

            foreach (var old in oldJudgements)
            {
                RunJudgings.Remove(old);
            }

            // Insert new ones
            foreach (var score in list)
            {
                RunJudgings.Add(score);
            }

            // Update total score for all round contestants
            foreach (long rcId in rcIds)
            {
                RoundContestant contestant = GetRoundContestantGuarded(rcId);
                contestant.CalculateTotalScore(expectedJudgeEntriesPerRun, contestant.Round.RoundNo, contestant.Round.RunsPerContestant);
            }
            SaveChanges();
        }
        /// <summary>
        /// Replaces list of runJudging scores as well as calculates total on RoundContestant if done.
        /// Less optimized than ReplaceRunJudgings(ContestantRunViewModel model), as it fetches roundContestant for each runJudging line
        /// </summary>
        public virtual void ReplaceRunJudgings(List <RunJudging> list, Tournament tourney)
        {
            var expectedJudgeEntriesPerRun = tourney.GetExpectedJudgementCountPerRun();

            foreach (var score in list)
            {
                RunJudgings.Replace(score);
                RoundContestant contestant = GetRoundContestantGuarded(score.RoundContestantId);
                contestant.CalculateTotalScore(expectedJudgeEntriesPerRun, contestant.Round.RunsPerContestant);
            }
            SaveChanges();
        }
        /// <summary>
        /// Replaces list of runJudging scores as well as calculates total on RoundContestant if done
        /// </summary>
        /// <param name="model"></param>
        public virtual void ReplaceRunJudgings(ContestantRunViewModel model)
        {
            Tournament      tourney    = GetTournamentGuarded(model.TournamentId);
            RoundContestant contestant = GetRoundContestantGuarded(model.RoundContestantId);

            foreach (var score in model.Scores)
            {
                RunJudgings.Replace(score);
            }
            var expectedJudgeEntriesPerRun = tourney.GetExpectedJudgementCountPerRun();

            contestant.CalculateTotalScore(expectedJudgeEntriesPerRun, contestant.Round.RunsPerContestant);
            SaveChanges();
        }
        /// <summary>
        /// Replaces list of runJudging scores for a single round consteants. Calculates total on RoundContestant if all scores registerd.
        /// </summary>
        public virtual void ReplaceRunJudgings(long tournamentId, long roundContestantId, List <RunJudging> runJudgings)
        {
            Tournament      tourney    = GetTournamentGuarded(tournamentId);
            RoundContestant contestant = GetRoundContestantGuarded(roundContestantId);

            foreach (var score in runJudgings)
            {
                RunJudgings.Replace(score);
            }
            var expectedJudgeEntriesPerRun = tourney.GetExpectedJudgementCountPerRun();

            contestant.CalculateTotalScore(expectedJudgeEntriesPerRun, contestant.Round.RoundNo, contestant.Round.RunsPerContestant);
            SaveChanges();
        }
 /// <summary>
 /// Adds or replaces juding for particular run
 /// </summary>
 /// <param name="judging"></param>
 public void ReplaceRunJudging(RunJudging judging)
 {
     RunJudgings.Replace(judging);
     SaveChanges();
 }