in Blueprints/BlueprintDefinitions/vs2019/LexBookTripSample/template/src/BlueprintBaseName.1/BookCarIntentProcessor.cs [223:295]
private ValidationResult Validate(Reservation reservation)
{
if (!string.IsNullOrEmpty(reservation.PickUpCity) && !TypeValidators.IsValidCity(reservation.PickUpCity))
{
return new ValidationResult(false, PICK_UP_CITY_SLOT,
$"We currently do not support {reservation.PickUpCity} as a valid destination. Can you try a different city?");
}
DateTime pickupDate = DateTime.MinValue;
if (!string.IsNullOrEmpty(reservation.PickUpDate))
{
if (!DateTime.TryParse(reservation.PickUpDate, out pickupDate))
{
return new ValidationResult(false, PICK_UP_DATE_SLOT,
"I did not understand your departure date. When would you like to pick up your car rental?");
}
if (pickupDate < DateTime.Today)
{
return new ValidationResult(false, PICK_UP_DATE_SLOT,
"Your pick up date is in the past! Can you try a different date?");
}
}
DateTime returnDate = DateTime.MinValue;
if (!string.IsNullOrEmpty(reservation.ReturnDate))
{
if (!DateTime.TryParse(reservation.ReturnDate, out returnDate))
{
return new ValidationResult(false, RETURN_DATE_SLOT,
"I did not understand your return date. When would you like to return your car rental?");
}
}
if (pickupDate != DateTime.MinValue && returnDate != DateTime.MinValue)
{
if (returnDate <= pickupDate)
{
return new ValidationResult(false, RETURN_DATE_SLOT,
"Your return date must be after your pick up date. Can you try a different return date?");
}
var ts = returnDate.Date - pickupDate.Date;
if (ts.Days > 30)
{
return new ValidationResult(false, RETURN_DATE_SLOT,
"You can reserve a car for up to thirty days. Can you try a different return date?");
}
}
int age = 0;
if (!string.IsNullOrEmpty(reservation.DriverAge))
{
if (!int.TryParse(reservation.DriverAge, out age))
{
return new ValidationResult(false, DRIVER_AGE_SLOT,
"I did not understand the driver's age. Can you enter the driver's age again?");
}
if (age < 18)
{
return new ValidationResult(false, DRIVER_AGE_SLOT,
"Your driver must be at least eighteen to rent a car. Can you provide the age of a different driver?");
}
}
if (!string.IsNullOrEmpty(reservation.CarType) && !TypeValidators.IsValidCarType(reservation.CarType))
{
return new ValidationResult(false, CAR_TYPE_SLOT,
"I did not recognize that model. What type of car would you like to rent? " +
"Popular cars are economy, midsize, or luxury");
}
return ValidationResult.VALID_RESULT;
}