public CreateProductJsonValidation(
     IJsonProductContext productContext,
     IJsonSupplierContext supplierContext,
     IJsonManufacturerContext manufacturerContext,
     IJsonCategoryContext categoryContext)
 {
     RuleFor(x => x.Name)
     .NotEmpty()
     .Must(name => !productContext.Read().Any(x => x.Name == name))
     .WithMessage("Name must be unique.");
     RuleFor(x => x.Category)
     .Must(category => categoryContext.Read().Any(x => x.Name == category))
     .WithMessage("Category must exist");
     RuleFor(x => x.Manufacturer)
     .Must(manufacturer => manufacturerContext.Read().Any(x => x.Name == manufacturer))
     .WithMessage("Manufacturer must exist");
     RuleFor(x => x.Supplier)
     .Must(supplier => supplierContext.Read().Any(x => x.Name == supplier))
     .WithMessage("Supplier must exist");
 }
Ejemplo n.º 2
0
 public GetCategoriesJsonQuery(IJsonCategoryContext categoryContext)
 {
     _categoryContext = categoryContext;
 }