예제 #1
0
        protected override Contest GetItemFromDataReader(IDataReader reader)
        {
            int      id               = Convert.ToInt32(reader.GetColumnValue(ID));
            string   name             = reader.GetColumnValue(NAME).ToString();
            string   timeKeeperId     = reader.GetColumnValue(TIME_KEEPER_ID).ToString();
            long?    maxDurationTicks = reader.GetColumnValue(MAX_DURATION) as long?;
            TimeSpan maxDuration      = new TimeSpan((maxDurationTicks ?? 0));
            string   description      = reader.GetColumnValue(DESCRIPTION).ToString();
            string   status           = reader.GetColumnValue(STATUS).ToString();

            Contest contest = new Contest(id, name, description, timeKeeperId, maxDuration, status);

            var contestants = new ContestantRepo().GetWhereParentForeignKeyIs(contest.Id);

            foreach (var contestant in contestants)
            {
                contest.Contestants.Add(contestant);
            }

            var judges = new JudgeRepo().GetWhereParentForeignKeyIs(contest.Id);

            foreach (var judge in judges)
            {
                contest.Judges.Add(judge);
            }

            var contestScoreCardCollection = new ContestScoreCardRepo().GetWhereForeignKeyIs(contest.Id);
            var scoreCardRepo = new ScoreCardRepo();

            foreach (var sc in contestScoreCardCollection)
            {
                if (scoreCardRepo.Exists(sc.ScoreCardId))
                {
                    contest.ScoreCards.Add(scoreCardRepo.Get(sc.ScoreCardId));
                }
            }

            var scoreCriteria = new ScoreCriterionRepo().GetWhereParentForeignKeyIs(contest.Id);

            foreach (var scoreCriterion in scoreCriteria)
            {
                contest.ScoreCriteria.Add(scoreCriterion);
            }

            return(contest);
        }
예제 #2
0
        public override void Delete(int id)
        {
            var contestContestantRepo       = new ContestContestantRepo();
            var contestContestantCollection = contestContestantRepo.GetWhereForeignKeyIs(id);
            var contestantRepo = new ContestantRepo();

            foreach (var contestContestant in contestContestantCollection)
            {
                contestantRepo.Delete(contestContestant.ContestantId);
                contestContestantRepo.Delete(contestContestant.Id);
            }

            var contestJudgeRepo       = new ContestJudgeRepo();
            var contestJudgeCollection = contestJudgeRepo.GetWhereForeignKeyIs(id);
            var judgeRepo = new JudgeRepo();

            foreach (var contestJudge in contestJudgeCollection)
            {
                judgeRepo.Delete(contestJudge.JudgeId);
                contestJudgeRepo.Delete(contestJudge.Id);
            }

            var contestScoreCardRepo       = new ContestScoreCardRepo();
            var contestScoreCardCollection = contestScoreCardRepo.GetWhereForeignKeyIs(id);
            var scoreCardRepo = new ScoreCardRepo();

            foreach (var contestScoreCard in contestScoreCardCollection)
            {
                scoreCardRepo.Delete(contestScoreCard.ScoreCardId);
                contestScoreCardRepo.Delete(contestScoreCard.Id);
            }

            var contestScoreCriterionRepo       = new ContestScoreCriterionRepo();
            var contestScoreCriterionCollection = contestScoreCriterionRepo.GetWhereForeignKeyIs(id);
            var scoreCriterionRepo = new ScoreCriterionRepo();

            foreach (var contestScoreCriterion in contestScoreCriterionCollection)
            {
                scoreCriterionRepo.Delete(contestScoreCriterion.ScoreCriterionId);
                contestScoreCriterionRepo.Delete(contestScoreCriterion.Id);
            }

            base.Delete(id);
        }