Seem to be getting inconsistent returns in my model validation. The main issue that occurs is that whenever a date is invalid/malformed it will stop on all other validations besides date validations.
How is it possible that the first request does not return an error about the missing ParticipantUserId parameter, but the second request does? Is this intended behaviour?
Whilst debugging I've noticed that the missing parameter does not show up in the errors array, while logically it should be?
Examples:
Given the following model:
[Required]
[Range(1, int.MaxValue, ErrorMessage = "ParticipantUserId cannot be a negative number.")]
public int? ParticipantUserId { get; set; }
public DateTime? DateEnd { get; set; }
public DateTime? DateStart { get; set; }
[MaxLength(50)]
public string ExternalReferenceKey { get; set; }
[Required]
public int? ScheduleId{get;set;}
Request #1 (Missing the required ParticipantUserId AND having an invalid date):
{
"scheduleId": 1,
"correspondenceNote": "DND",
"dateStart": "2020-016T00:00:00",
"dateEnd": "2020-07-16T00:00:00",
"ExternalReferenceKey": null,
"internalNoTe": "Note",
"transferEnrollmentId": null
}
returns:
{
"fields": [
{
"propertyName": "dateStart",
"errorMessage": "Could not convert string to DateTime: 2020-016T00:00:00"
}
],
"errorMessage": "One or more validation errors occurred.",
"statusCode": 400
}
Whereas
Request #2 (Missing the required ParticipantUserId, but with valid Dates):
{
"scheduleId": 1,
"correspondenceNote": "DND",
"dateStart": "2020-07-16T00:00:00",
"dateEnd": "2020-07-16T00:00:00",
"ExternalReferenceKey": null,
"internalNoTe": "Note",
"transferEnrollmentId": null
}
returns:
{
"fields": [
{
"propertyName": "ParticipantUserId",
"errorMessage": "The field ParticipantUserId must be between 1 and 2147483647"
}
],
"errorMessage": "One or more validation errors occurred.",
"statusCode": 400
}