Exemplo n.º 1
0
 /// <summary>
 /// IValidatableObject接口验证整个实体
 /// </summary>
 public static ValidationResult TripDateValidator(Trip trip, ValidationContext validationContext)
 {
     if (trip.StartDate.Date >= trip.EndDate.Date)
     {
         return new ValidationResult("Start Date must be earlier than End Date", new[] { "StartDate", "EndDate" });
     }
     return ValidationResult.Success;
 }
Exemplo n.º 2
0
 /// <summary>
 /// IValidatableObject接口验证整个实体
 /// </summary>
 public static ValidationResult TripCostInDescriptionValidator(Trip trip, ValidationContext validationContext)
 {
     if (trip.CostUSD > 0)
     {
         if (trip.Description.Contains(Convert.ToInt32(trip.CostUSD).ToString()))
         {
             return new ValidationResult("Description cannot contain trip cost", new[] { "Description" });
         }
     }
     return ValidationResult.Success;
 }