38 lines
1.4 KiB
C#
38 lines
1.4 KiB
C#
using FluentValidation;
|
|
using SJZY.Track.Application.Dtos.Demo;
|
|
using SJZY.Track.Application.Dtos.TrackTemplates;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SJZY.Track.Application.Validations.TrackTemplates
|
|
{
|
|
/// <summary>
|
|
/// 轨迹模版编辑校验
|
|
/// </summary>
|
|
public class EditTrackTemplateInputValidation : AbstractValidator<EditTrackTemplateInput>, IValidationEnabled
|
|
{
|
|
public EditTrackTemplateInputValidation()
|
|
{
|
|
//条件分支
|
|
When(x => x.Options == OptionType.修改 || x.Options == OptionType.删除, () =>
|
|
{
|
|
RuleFor(x => x.Id).GreaterThan(0).WithMessage("修改或删除时Id必须大于0!");
|
|
});
|
|
|
|
When(x => x.Options == OptionType.新增, () =>
|
|
{
|
|
RuleFor(x => x.Id).Equal(0).WithMessage("新增时Id必须等于0!");
|
|
});
|
|
|
|
When(x => x.Options == OptionType.修改 || x.Options == OptionType.新增, () =>
|
|
{
|
|
RuleFor(x => x.Name).NotNull().WithMessage("模版名称必填!").NotEmpty().WithMessage("模版名称不能为空!");
|
|
RuleFor(x => x.Code).NotNull().WithMessage("模版代码必填!").NotEmpty().WithMessage("模版代码不能为空!");
|
|
});
|
|
}
|
|
}
|
|
}
|