public ItemSchemaController(IItemSchemaService schemaService, IMapper mapper, IValidator <ItemSchema> validator, IItemService itemService) : base(schemaService, mapper, validator) { _itemService = itemService; }
public ItemValidator(IItemSchemaService itemSchemaService) { RuleFor(x => x.Name).NotEmpty(); RuleFor(x => x.Quantity).GreaterThanOrEqualTo(0); RuleFor(x => x.SchemaId).Must(id => itemSchemaService.GetOne(id) != null) .WithMessage(item => $"{nameof(ItemSchema)} with Id {item.SchemaId} does not exist."); RuleFor(x => x.Properties).Must(list => list.Select(x => x.Key).Distinct().Count() == list.Count) .WithMessage(item => $"Item can not contain more than one of the same property"); }
public ItemSchemaValidator(IItemSchemaService itemSchemaService) { RuleFor(x => x.Name).NotEmpty() .Must((schema, name) => !itemSchemaService.Queryable() .Any(s => s.Id != schema.Id && s.Name == name)) .WithMessage(schema => $"Item schema name must be unique."); RuleFor(x => x.Properties).Must(list => list.Select(x => x.Name).Distinct().Count() == list.Count) .WithMessage(item => $"Item schema can not contain duplicate fields"); RuleForEach(x => x.Properties).ChildRules(properties => { properties.RuleFor(x => x.Type).IsInEnum(); properties.RuleFor(x => x.Name).NotEmpty(); }); }