I got a requirement that a new product name should be unique.
So I created this rule (very new to FV btw)
RuleFor(product => product.Name) .NotEmpty() .Must(_productsService.ProductNameIsUnique);
Which use this method in my repository:
public bool ProductNameIsUnique(string name){ Product product = _productsRepository.GetByName(name); return product == null;}
All is well, but the thing is when I UPDATE an existing product, this will fail (unless you changed the product name)
So I need to do something in the line of "where productname == name && productid !=id", if that make any sense?