19 lines
772 B
C#
19 lines
772 B
C#
|
|
namespace FrontOffice.BFF.Application.ShopingCartCQ.Commands.AddNewUserCart;
|
||
|
|
public class AddNewUserCartCommandValidator : AbstractValidator<AddNewUserCartCommand>
|
||
|
|
{
|
||
|
|
public AddNewUserCartCommandValidator()
|
||
|
|
{
|
||
|
|
RuleFor(model => model.ProductId)
|
||
|
|
.NotNull();
|
||
|
|
RuleFor(model => model.Count)
|
||
|
|
.NotNull();
|
||
|
|
}
|
||
|
|
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||
|
|
{
|
||
|
|
var result = await ValidateAsync(ValidationContext<AddNewUserCartCommand>.CreateWithOptions((AddNewUserCartCommand)model, x => x.IncludeProperties(propertyName)));
|
||
|
|
if (result.IsValid)
|
||
|
|
return Array.Empty<string>();
|
||
|
|
return result.Errors.Select(e => e.ErrorMessage);
|
||
|
|
};
|
||
|
|
}
|