Код: Выделить всё
using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json;
public class ExternalNotificationRequest
{
///
/// Appointment details
///
[Required(AllowEmptyStrings = false, ErrorMessage = "Please provide a appointment object values.")]
[JsonProperty("appointment")]
public Appointment? Appointment { get; set; }
}
public class Appointment
{
///
/// Notification type such as Create/Update/Delete
///
[JsonProperty("type")]
[Required(AllowEmptyStrings = false, ErrorMessage = "Please provide a appointment type. Valid values are CREATE,UPDATE,DELETE.")]
public string? Type { get; set; }
///
/// appointment public id
///
[JsonProperty("publicId")]
[MaxLength(64)]
[MinLength(64)]
[Required(AllowEmptyStrings = false, ErrorMessage = "Please provide an appointment public id.")]
public string? PublicId { get; set; }
}
public static class ApiRequestValidation
{
public static bool IsValid(this object request, out ICollection validationResults)
{
validationResults = new List();
return Validator.TryValidateObject(request, new ValidationContext(request), validationResults, true);
}
}
Код: Выделить всё
ExternalNotificationRequest externalNotificationRequest = new ExternalNotificationRequest();
_logger.LogInformation("{FunctionName} Request Body: {requestBody}", functionName, requestBody);
externalNotificationRequest =
JsonConvert.DeserializeObject(requestBody)
?? new ExternalNotificationRequest();
// Validate Data Annotations.
if (!externalNotificationRequest.IsValid(validationResults: out var validationResults))
{
return messageExtensions.RenderApiMessage(_logger, StatusCodes.Status400BadRequest, validationResults.Select(s => s.ErrorMessage).FirstOrDefault(), functionName, validationResults.Select(s => s.MemberNames.FirstOrDefault()).FirstOrDefault().ToString());
}
Код: Выделить всё
{
"appointment": {
"type": "create",
"publicId": ""
}
}
Что мне не хватает?
Подробнее здесь: https://stackoverflow.com/questions/784 ... ed-attribu
Мобильная версия