31 lines
1.1 KiB
C#
31 lines
1.1 KiB
C#
namespace CMSMicroservice.Application.CommissionCQ.Queries.GetUserWeeklyBalances;
|
|
|
|
public class GetUserWeeklyBalancesQueryValidator : AbstractValidator<GetUserWeeklyBalancesQuery>
|
|
{
|
|
public GetUserWeeklyBalancesQueryValidator()
|
|
{
|
|
RuleFor(x => x.UserId)
|
|
.GreaterThan(0)
|
|
.WithMessage("شناسه کاربر معتبر نیست")
|
|
.When(x => x.UserId.HasValue);
|
|
|
|
RuleFor(x => x.WeekDefinitionId)
|
|
.GreaterThan(0)
|
|
.WithMessage("شماره هفته نمیتواند صفر باشد")
|
|
.When(x => x.WeekDefinitionId.HasValue);
|
|
}
|
|
|
|
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
|
{
|
|
var result = await ValidateAsync(
|
|
ValidationContext<GetUserWeeklyBalancesQuery>.CreateWithOptions(
|
|
(GetUserWeeklyBalancesQuery)model,
|
|
x => x.IncludeProperties(propertyName)));
|
|
|
|
if (result.IsValid)
|
|
return Array.Empty<string>();
|
|
|
|
return result.Errors.Select(e => e.ErrorMessage);
|
|
};
|
|
}
|