Example #1
0
 public bool Validate(LineDTO line)
 {
     if (line == null)
     {
         throw new ArgumentException(ValidationResources.LineIsEmpty);
     }
     if (string.IsNullOrEmpty(line.Name))
     {
         throw new ArgumentException(ValidationResources.LineNameIsEmpty);
     }
     foreach (var stopType in line.Stops.Select(p => p.StopType))
     {
         if (!_stopLineTypesMatchChecker.AreStopAndLineTypesMatching
                 (stopType, line.LineType))
         {
             throw new ArgumentException(ValidationResources.StopLineTypesDoNotMatch);
         }
     }
     if (line.IsCircular)
     {
         if (line.Stops == null || line.Stops.Count() < 3)
         {
             throw new ArgumentException(ValidationResources.CircularLineStopsLessThanThree);
         }
         if (line.Stops.First().Id != line.Stops.Last().Id)
         {
             throw new ArgumentException(ValidationResources.CircularLineMustStartAndEndInTheSameStop);
         }
         if (_lineRepository.GetCountByLineName(line.Name) >= 1)
         {
             throw new ArgumentException(ValidationResources.OnlyOneCircularLineCanExist);
         }
     }
     else
     {
         if (line.Stops == null || line.Stops.Count() < 2)
         {
             throw new ArgumentException(ValidationResources.LineStopsLessThanTwo);
         }
         if (_lineRepository.GetCountByLineName(line.Name) >= 2)
         {
             throw new ArgumentException(ValidationResources.OnlyTwoOneWaysLinesCanExist);
         }
     }
     return(true);
 }