Files
FrontOffice.BFF/src/FrontOffice.BFF.Application/ShopingCartCQ/Commands/AddNewUserCart/AddNewUserCartCommandValidator.cs
2025-11-20 00:26:12 +03:30

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