public void AddTrainee(Trainee trainee) { if (trainee.Id.ToString().Length != 9) { throw new Exception(string.Format("id {0} is invalid. because it has {1} digits and normal id has 9.", trainee.Id, trainee.Id.ToString().Length)); } if (!CheckIfIDisValid(trainee.Id)) { throw new Exception(string.Format("id {0} is invalid israeli number. by the rules of ID numbers", trainee.Id)); } if (dal.GetTraineeById(trainee.Id) != null) { throw new Exception(string.Format("The trainee {0} already exists", trainee.ToString())); } if (trainee.LessonsNumber < 0) { throw new Exception("A negative number of lessons is impossible"); } if (trainee.PhoneNumber.ToString().StartsWith("05") && trainee.PhoneNumber.ToString().Length == 10) { throw new Exception("The number phone has to be valid israeli number"); } if (GetAgeByBirthday(trainee.Birthday) < Configuration.MIN_STUDENT_AGE) { throw new Exception(string.Format("The trainee {0} is too young to driving test, The minimum is {1} and the trainee only {2}.", trainee.ToString(), Configuration.MIN_STUDENT_AGE, GetAgeByBirthday(trainee.Birthday))); } dal.AddTrainee(trainee); }
//Data manipulations on TRAINEES /// <summary> /// Adds a trainee to the trainee list in the Data Source /// </summary> /// <param name="trainee">Trainee to be added</param> public string AddTrainee(Trainee trainee) { string error = "Failed to add " + trainee.GetName(); if (IsTraineeIdFound(trainee.Id) == true) { return("Id " + trainee.Id + " was already found"); } else if (TraineePropertiesValidation(trainee) == true) { error = m_xamlImp.AddTrainee(trainee); } return(error); }
/// <summary> /// Add Trainee /// </summary> /// <param name="newTrainee">The Trainee to add</param> public void AddTrainee(Trainee newTrainee) { if (AllTrainees.Any(trainee => trainee.Id == newTrainee.Id)) { throw new Exception("Trainee already exist"); } if (Tools.GetAge(newTrainee.BirthDate) < Configuration.MinTraineeAge) { throw new Exception("The trainee is too young"); } if (newTrainee.BirthDate == DateTime.MinValue) { throw new Exception("Invalid birth date"); } _dalImp.AddTrainee(newTrainee); }
//public void Kuku(DateTime time) // למצוא שם //{ // FindAvilableTesters(time); //} public void AddTrainee(Trainee trainee) { if (dal.FindTester(trainee.Id) != null || dal.FindTrainee(trainee.Id) != null) { throw new Exception("תעודת זהות זו כבר קיימת במערכת"); } if (!CheckIdValidity(trainee.Id)) { throw new Exception("תעודת זהות לא תקינה"); } // if age < 18 throw if (trainee.Age < Configuration.TraineeMinAge) { throw new MyExceptions("Trainee:" + trainee.FullName + " is under 18 YO!"); } else { dal.AddTrainee(trainee); } }
public bool AddTrainee(Trainee trainee) { //if trainee is to young if (DateTime.Now.Year - trainee.DateOfBirth.Year < Configuration.minTraineeAge) { throw new Exception("A trainee cannot be under " + Configuration.minTraineeAge + " years old \n"); } try { IDal _dal = FactorySingletonDal.GetDal(); if (_dal.AddTrainee(trainee)) { return(true); } return(false); } catch (Exception e) { throw e; } }