23 lines
950 B
C#
23 lines
950 B
C#
using FluentValidation;
|
|
using Indotalent.Shared.Consts;
|
|
|
|
namespace Indotalent.Features.Pipeline.Lead.Cqrs;
|
|
|
|
public class UpdateLeadValidator : AbstractValidator<UpdateLeadRequest>
|
|
{
|
|
public UpdateLeadValidator()
|
|
{
|
|
RuleFor(x => x.Id).NotEmpty();
|
|
RuleFor(x => x.Title).NotEmpty().MaximumLength(GlobalConsts.StringLengthShort);
|
|
RuleFor(x => x.CompanyName).NotEmpty().MaximumLength(GlobalConsts.StringLengthShort);
|
|
RuleFor(x => x.CampaignId).NotEmpty();
|
|
RuleFor(x => x.SalesTeamId).NotEmpty();
|
|
}
|
|
|
|
public Func<object, string, Task<IEnumerable<string>>> ValidateValue() => async (model, propertyName) =>
|
|
{
|
|
var result = await ValidateAsync(ValidationContext<UpdateLeadRequest>.CreateWithOptions((UpdateLeadRequest)model, x => x.IncludeProperties(propertyName)));
|
|
if (result.IsValid) return Array.Empty<string>();
|
|
return result.Errors.Select(e => e.ErrorMessage);
|
|
};
|
|
} |