public Child RegisterChild(String name, int age, String challenge1, String challenge2) { if (challenge1.CompareTo(challenge2) == 0) { throw new ValidationException("Participantul nu poate fi inscris de 2 ori la aceeasi proba ! "); } Child child = new Child(name, age); Child foundChild; if (childRepo.FindByProperties(name, age) != null) { foundChild = childRepo.FindByProperties(name, age); if (entriesRepo.FindChallengeNumber(foundChild.Id) == 1 && challenge2 != "") { throw new ValidationException("Participantul mai poate fi inscris la o singura proba ! "); } else if (entriesRepo.FindChallengeNumber(foundChild.Id) == 2) { throw new ValidationException("Participantul nu mai poate fi inscris la nici o proba ! "); } Models.Tuple <int, int> ageInterval = CreateAgeInterval(age); Challenge challengeFound1 = challengeRepo.FindByProperties(ageInterval.Left, ageInterval.Right, challenge1); if (challengeFound1 != null && entriesRepo.Exists(new Models.Tuple <long, long>(foundChild.Id, challengeFound1.Id))) { throw new ValidationException("Participantul nu mai poate fi inscris la aceeasi proba ! "); } Entry entry = new Entry(DateTime.Now, foundChild, challengeFound1); if (challengeFound1 != null) { entry.Id = new Models.Tuple <long, long>(foundChild.Id, challengeFound1.Id); if (entriesRepo.Save(entry) != null) { return(foundChild); } } notifyRegisterChild(foundChild); return(null); } Child added = childRepo.Save(child); foundChild = childRepo.FindByProperties(name, age); if (challenge1 != "") { Models.Tuple <int, int> ageInterval = CreateAgeInterval(age); Challenge foundChallenge1 = challengeRepo.FindByProperties(ageInterval.Left, ageInterval.Right, challenge1); Entry entry = new Entry(DateTime.Now, foundChild, foundChallenge1); if (foundChallenge1 != null) { entry.Id = new Models.Tuple <long, long>(foundChild.Id, foundChallenge1.Id); if (entriesRepo.Save(entry) != null) { return(foundChild); } } } if (challenge2 != "") { Models.Tuple <int, int> ageInterval = CreateAgeInterval(age); Challenge foundChallenge2 = challengeRepo.FindByProperties(ageInterval.Left, ageInterval.Right, challenge2); Entry entry = new Entry(DateTime.Now, foundChild, foundChallenge2); if (foundChallenge2 != null) { entry.Id = new Models.Tuple <long, long>(foundChild.Id, foundChallenge2.Id); if (entriesRepo.Save(entry) != null) { return(foundChild); } } } if (added == null) { notifyRegisterChild(foundChild); } return(added); }