public void RegisterParticipant(String participantName, Int32 age, List <String> trialName)
        {
            AgeCategory ageCategory = _ageCategoryRepository.FindSuitableAgeCategory(age);

            Participant p = null;

            if (!_repository.ExistsItem(participantName))
            {
                _repository.AddItem(new Participant(participantName, age, ageCategory));
            }
            p = _repository.GetItem(participantName);

            if (p.Age != age)
            {
                throw new RepositoryException("Participant already exists in database with a different age!\n");
            }


            List <String> trials = _repository.GetTrialsForParticipant(participantName);

            if (trials.Count + trialName.Count > 2)
            {
                throw new ServiceException("A participant can be registered only at 2 trials!\n");
            }

            foreach (string t in trialName)
            {
                if (trials.Contains(t))
                {
                    throw new ServiceException(participantName + " already participates at " + t + "!\n");
                }
            }

            foreach (string t in trialName)
            {
                _repository.RegisterParticipant(p, t);
            }
        }
Пример #2
0
        public AgeCategory FindSuitableAgeCategory(String age)
        {
            Int32 ageArgument = Converter.ConvertToInt32(age);

            return(_repository.FindSuitableAgeCategory(ageArgument));
        }