public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { DateTime startDate; bool isValidStartDate = SystemTime.TryParse(StartYear.GetValueOrDefault(), StartMonth.GetValueOrDefault(), StartDay.GetValueOrDefault(), out startDate); if (!isValidStartDate) { yield return(new ValidationResult(IndexResources.FromValid, new[] { "StartDay" })); } DateTime endDate; bool isValidEndDate = SystemTime.TryParse(EndYear.GetValueOrDefault(), EndMonth.GetValueOrDefault(), EndDay.GetValueOrDefault(), out endDate); if (!isValidEndDate) { yield return(new ValidationResult(IndexResources.ToValid, new[] { "EndDay" })); } if (!(isValidStartDate && isValidEndDate)) { // Stop further validation if either date is not a valid date yield break; } if (startDate > endDate) { yield return(new ValidationResult(IndexResources.FromDateAfterToDate, new[] { "StartYear" })); } }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { if (!IsNumberOfShipmentsValid()) { yield return(new ValidationResult(ShipmentResources.NumberOfShipmentsValid, new[] { "NumberOfShipments" })); } if (!IsQuantityValid() && Units.HasValue) { yield return(new ValidationResult(string.Format(ShipmentResources.DecimalPlacesValid, ShipmentQuantityUnitsMetadata.Precision[Units.Value]), new[] { "Quantity" })); } DateTime startDate; bool isValidStartDate = SystemTime.TryParse(StartYear.GetValueOrDefault(), StartMonth.GetValueOrDefault(), StartDay.GetValueOrDefault(), out startDate); if (!isValidStartDate) { yield return(new ValidationResult(ShipmentResources.FirstDepartureValid, new[] { "StartDay" })); } DateTime endDate; bool isValidEndDate = SystemTime.TryParse(EndYear.GetValueOrDefault(), EndMonth.GetValueOrDefault(), EndDay.GetValueOrDefault(), out endDate); if (!isValidEndDate) { yield return(new ValidationResult(ShipmentResources.LastDepartureValid, new[] { "EndDay" })); } if (!(isValidStartDate && isValidEndDate)) { // Stop further validation if either date is not a valid date yield break; } if (startDate < SystemTime.Now.Date && Status == NotificationStatus.NotSubmitted) { yield return(new ValidationResult(ShipmentResources.FirstDeparturePastDate, new[] { "StartDay" })); } if (startDate > endDate) { yield return(new ValidationResult(ShipmentResources.FirstDepartureBeforeLastDate, new[] { "StartYear" })); } var monthPeriodLength = IsPreconsentedRecoveryFacility ? 36 : 12; if (endDate >= startDate.AddMonths(monthPeriodLength)) { yield return(new ValidationResult(string.Format(ShipmentResources.DepartureDateRange, monthPeriodLength), new[] { "EndYear" })); } }
public SetIntendedShipmentInfoForNotification ToRequest(Guid notificationId) { DateTime startDate; SystemTime.TryParse(StartYear.GetValueOrDefault(), StartMonth.GetValueOrDefault(), StartDay.GetValueOrDefault(), out startDate); DateTime endDate; SystemTime.TryParse(EndYear.GetValueOrDefault(), EndMonth.GetValueOrDefault(), EndDay.GetValueOrDefault(), out endDate); return(new SetIntendedShipmentInfoForNotification( notificationId, int.Parse(NumberOfShipments, NumberStyles.AllowThousands), Convert.ToDecimal(Quantity), Units.GetValueOrDefault(), startDate, endDate)); }