示例#1
0
        public CreateRecipeCommandValidator()
        {
            RuleFor(x => x.Id)
            .NotNull()
            .WithMessage(ValidationMessages.NotNull(nameof(CreateRecipeCommand.Id)));

            RuleFor(x => x.Name)
            .NotNull()
            .WithMessage(ValidationMessages.NotNull(nameof(CreateRecipeCommand.Name)));

            RuleFor(x => x.Description)
            .NotNull()
            .WithMessage(ValidationMessages.NotNull(nameof(CreateRecipeCommand.Description)));

            RuleFor(x => x.RecipeInfo)
            .NotNull()
            .WithMessage(ValidationMessages.NotNull(nameof(CreateRecipeCommand.RecipeInfo)));

            RuleFor(x => x.RecipeIngredients)
            .NotEmpty()
            .WithMessage(ValidationMessages.NotEmpty(nameof(CreateRecipeCommand.RecipeIngredients)));

            RuleFor(x => x.RecipeInfo)
            .SetValidator(new RecipeDetailsValidator());

            RuleForEach(x => x.RecipeIngredients)
            .SetValidator(new RecipeIngredientValidator());
        }
示例#2
0
        public UpdateIngredientCommandValidator()
        {
            RuleFor(x => x.Id)
            .NotEmpty()
            .WithMessage(ValidationMessages.NotEmpty(nameof(UpdateIngredientCommand.Id)));

            RuleFor(x => x.Name)
            .NotEmpty()
            .WithMessage(ValidationMessages.NotEmpty(nameof(UpdateIngredientCommand.Name)));

            RuleFor(x => x.Shares)
            .NotEmpty()
            .WithMessage(ValidationMessages.NotEmpty(nameof(UpdateIngredientCommand.Shares)));

            RuleForEach(x => x.Shares).
            SetValidator(new MacroNutrientsSharesValidator());
        }