Files
FrontOffice.BFF/src/FrontOffice.BFF.Application/ShopingCartCQ/Commands/AddNewUserCart/AddNewUserCartCommandValidator.cs

19 lines
772 B
C#
Raw Normal View History

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);
};
}