public bool Exists(Contest.model.Tuple <long, long> id) { log.InfoFormat("Entering Exists with value {0}", id); if (FindOne(id) == null) { log.InfoFormat("Exiting Exists with value {0}", false); return(false); } log.InfoFormat("Exiting Exists with value {0}", true); return(true); }
public Entry FindOne(Contest.model.Tuple <long, long> id) { log.InfoFormat("Entering FindOne with value {0}", id); IDbConnection con = DBUtils.getConnection(); using (var comm = con.CreateCommand()) { comm.CommandText = "select kid , cid , date from Entries where kid = @kid and cid = @cid"; IDbDataParameter paramKId = comm.CreateParameter(); paramKId.ParameterName = "@kid"; paramKId.Value = id.Left; comm.Parameters.Add(paramKId); IDbDataParameter paramCId = comm.CreateParameter(); paramCId.ParameterName = "@cid"; paramCId.Value = id.Right; comm.Parameters.Add(paramCId); using (var dataR = comm.ExecuteReader()) { if (dataR.Read()) { long kidE = dataR.GetInt64(0); long cidE = dataR.GetInt64(1); DateTime date = dataR.GetDateTime(2); Contest.model.Tuple <long, long> idE = new Contest.model.Tuple <long, long>(kidE, cidE); Child child = childRepo.FindOne(kidE); Challenge challenge = challengeRepo.FindOne(cidE); Entry entry = new Entry(date, child, challenge); entry.Id = idE; log.InfoFormat("Exiting FindOne with value {0}", entry); return(entry); } } } log.InfoFormat("Exiting FindOne with value {0}", null); return(null); }
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 ! "); } Contest.model.Tuple <int, int> ageInterval = CreateAgeInterval(age); Challenge challengeFound1 = challengeRepo.FindByProperties(ageInterval.Left, ageInterval.Right, challenge1); if (challengeFound1 != null && entriesRepo.Exists(new Contest.model.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 Contest.model.Tuple <long, long>(foundChild.Id, challengeFound1.Id); if (entriesRepo.Save(entry) != null) { return(foundChild); } } return(null); } Child added = childRepo.Save(child); foundChild = childRepo.FindByProperties(name, age); if (challenge1 != "") { Contest.model.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 Contest.model.Tuple <long, long>(foundChild.Id, foundChallenge1.Id); if (entriesRepo.Save(entry) != null) { return(foundChild); } } } if (challenge2 != "") { Contest.model.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 Contest.model.Tuple <long, long>(foundChild.Id, foundChallenge2.Id); if (entriesRepo.Save(entry) != null) { return(foundChild); } } } return(added); }