Код: Выделить всё
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
sealed public class TelephoneAttribute : ValidationAttribute
{
private readonly IJobRepository _jobRepository;
public TelephoneAttribute(IJobRepository jobRepository)
{
_jobRepository = jobRepository;
}
public override bool IsValid(object value)
{
bool result = false;
// my logic to avoid duplication of telephone
var anyDuplicate = _jobRepository.AllJobs.GroupBy(x => x.CustomerContactNumber)
.Any(g => g.Count() > 1);
if (anyDuplicate) { result = true; }
return result;
}
}
Код: Выделить всё
[Required(ErrorMessage = "**Required**")]
[Display(Name = "Customer Contact Number")]
[DataType(DataType.PhoneNumber)]
[TelephoneAttribute(ErrorMessage = "Duplicate Entry")]
public string CustomerContactNumber { get; set; }
cs7036: нет никаких аргументов, которые соответствуют требуемому параметру «jobRepository» 'telephoneatTribute.telephoneatTribute (ijobrepository)' < /p>
< /blockquote>
гид. Спасибо
Подробнее здесь: https://stackoverflow.com/questions/794 ... p-net-core