public static bool IsValid(this AssetDto assetDto, ICountrySearch search, out IEnumerable <string> errors) { var validator = new AssetValidator(search); var validationResult = validator.Validate(assetDto); errors = AggregateErrors(validationResult); return(validationResult.IsValid); }
public AssetValidator(ICountrySearch countrySearch) { RuleFor(x => x.AssetName) .MinimumLength(5) .WithMessage("Asset name must be a minimum of 5 characters"); RuleFor(x => x.Department) // .IsInEnum() .Must(CheckEnum) .WithMessage("Department is not valid"); RuleFor(x => x.PurchaseDate) .GreaterThanOrEqualTo(DateTimeOffset.UtcNow.AddYears(-1)) .WithMessage("Purchase date must not be older then one year"); RuleFor(x => x.EMailAdressOfDepartment) .NotEmpty() .WithMessage("Email Address is required") .EmailAddress() .WithMessage("Email Address is not valid"); RuleFor(x => x.CountryOfDepartment) .MustAsync(async(country, cancellationToken) => { var result = await countrySearch.SearchByName(country); return(result); }).WithMessage("country is invalid"); }
public CitySearchFormatter(ICountrySearch countrySearch, IWeatherSearch weatherSearch) { _countrySearch = countrySearch; _weatherSearch = weatherSearch; }
public CityModelValidator(ICountrySearch countrySearch) { _countrySearch = countrySearch; }
public CountryController(ICountrySearch countrySearch, ILogger <CitiesController> logger) { _countrySearch = countrySearch; _logger = logger; }