namespace Yw.Application
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public class UpdateHealthQuotaEvaluationModelInput : IValidatableObject
|
{
|
/// <summary>
|
/// id
|
/// </summary>
|
[Required, Range(1, long.MaxValue, ErrorMessage = "ID 必须大于0")]
|
public long ID { get; set; }
|
|
/// <summary>
|
/// 名称
|
/// </summary>
|
[Required]
|
public string Name { get; set; }
|
|
/// <summary>
|
/// 评价方式
|
/// </summary>
|
[Required, Range(0, 1, ErrorMessage = "Way 值范围 [0,1] ")]
|
public eEvaluateWay Way { get; set; }
|
|
/// <summary>
|
/// 评价标准
|
/// </summary>
|
[Required]
|
public string Evaluation { get; set; }
|
|
/// <summary>
|
/// 缺省值
|
/// </summary>
|
[Required]
|
public double DefaultValue { get; set; }
|
|
/// <summary>
|
/// 说明
|
/// </summary>
|
public string Description { get; set; }
|
|
/// <summary>
|
/// 验证
|
/// </summary>
|
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
{
|
if (this.Way == eEvaluateWay.Auto)
|
{
|
var json = AutoEvaluation.ToModel(this.Evaluation);
|
if (json == null)
|
{
|
yield return new ValidationResult(
|
"Evaluation 参数错误"
|
, new[] { nameof(Evaluation) }
|
);
|
}
|
|
else if (json.Items == null || json.Items.Count < 1)
|
{
|
yield return new ValidationResult(
|
"Evaluation 参数错误"
|
, new[] { nameof(Evaluation) }
|
);
|
}
|
|
else
|
{
|
foreach (var item in json.Items)
|
{
|
if (string.IsNullOrEmpty(item.Expression))
|
{
|
yield return new ValidationResult(
|
"Expression 不能为空"
|
, new[] { nameof(item.Expression) }
|
);
|
}
|
|
else if (!DynamicExpresso.Validator.VerifyMax(item.Expression, 1))
|
{
|
yield return new ValidationResult(
|
$"Expression [{item.Expression}] 配置错误"
|
, new[] { nameof(item.Expression) }
|
);
|
}
|
}
|
}
|
|
}
|
else
|
{
|
var json = HandEvaluation.ToModel(this.Evaluation);
|
if (json == null)
|
{
|
yield return new ValidationResult(
|
"Evaluation 参数错误"
|
, new[] { nameof(Evaluation) }
|
);
|
}
|
|
else if (json.Items == null || json.Items.Count < 1)
|
{
|
yield return new ValidationResult(
|
"Evaluation 参数错误"
|
, new[] { nameof(Evaluation) }
|
);
|
}
|
|
else if (json.Items.Exists(x => string.IsNullOrEmpty(x)))
|
{
|
var index = json.Items.IndexOf(null);
|
if (index < 0)
|
index = json.Items.IndexOf(string.Empty);
|
yield return new ValidationResult(
|
$"Evaluation [{index}] 参数错误"
|
, new[] { nameof(Evaluation) }
|
);
|
}
|
}
|
}
|
|
|
}
|
}
|