15 lines
547 B
C#
15 lines
547 B
C#
using FluentValidation;
|
|
using Commerce.Contracts.DTOs;
|
|
|
|
namespace Commerce.Contracts.Validators;
|
|
|
|
public class ProductVMValidator : AbstractValidator<ProductVM>
|
|
{
|
|
public ProductVMValidator()
|
|
{
|
|
RuleFor(x => x.Translations).NotEmpty().WithMessage("At least one translation is required");
|
|
RuleFor(x => x.Price).GreaterThan(0).When(x => x.Price.HasValue).WithMessage("Price must be greater than 0");
|
|
RuleFor(x => x.CategoryId).NotEmpty().When(x => !x.IsBundle).WithMessage("Category is required for products");
|
|
}
|
|
}
|