Ejemplo n.º 1
0
 public bool Validate(SearchInputDTO search)
 {
     if (search == null)
     {
         throw new ArgumentNullException(nameof(search));
     }
     if (search.StartStopId == -1)
     {
         throw new ArgumentException(SearchValidationResources.StartStopIsEmpty);
     }
     if (search.DestinationStopId == -1)
     {
         throw new ArgumentException(SearchValidationResources.EndStopIsEmpty);
     }
     if (!_stopRepository.DoesStopWithIdExist(search.StartStopId))
     {
         throw new ArgumentException($"{SearchValidationResources.StopWithIdDoesNotExist} {search.StartStopId}");
     }
     if (!_stopRepository.DoesStopWithIdExist(search.DestinationStopId))
     {
         throw new ArgumentException($"{SearchValidationResources.StopWithIdDoesNotExist} {search.DestinationStopId}");
     }
     if (search.StartDate.Equals(DateTime.MinValue))
     {
         throw new ArgumentException(SearchValidationResources.DateIsEmpty);
     }
     return(true);
 }
Ejemplo n.º 2
0
 public bool ValidateEdit(StopDTO stop)
 {
     Validate(stop);
     if (!_stopRepository.DoesStopWithIdExist(stop.Id))
     {
         throw new ArgumentException(ValidationResources.StopDoesntExist);
     }
     if (_stopRepository.Find(stop.Id).StopType != stop.StopType &&
         _stopRepository.IsStopConnectedToAnyLine(stop.Id))
     {
         throw new ArgumentException(ValidationResources.StopTypeCannotBeEditedWhenItsInPreviousTypeLine);
     }
     return(true);
 }