Exemplo n.º 1
0
        /// <summary>
        /// Validates all properties of properties of an AssetDto object.
        /// </summary>
        /// <param name="dto">The <see cref="AssetDto"/>.</param>
        protected override async Task ValidateAsync(AssetDto dto)
        {
            if (IsNull(dto))
            {
                return;
            }
            var url            = $"https://restcountries.eu/rest/v2/name/{dto.CountryOfDepartment}?fullText=true";
            var assetValidator = new AssetValidator(HttpDataAccess.SendRequestAsync(url));
            var results        = await assetValidator.ValidateAsync(new ValidationContext <Asset>(Adapt(dto)));

            foreach (var e in results.Errors)
            {
                ModelState.AddModelError(e.PropertyName, Localizer[e.ErrorCode ?? e.ErrorMessage]);
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> IsValidAssetCountry([FromQuery] string country)
        {
            if (string.IsNullOrEmpty(country))
            {
                return(Ok(new ValidationResultDto
                {
                    IsValid = false,
                    ErrorCode = "InvalidCountryName",
                    ErrorMessage = Localizer["InvalidCountryName"]
                }));
            }
            var url       = $"https://restcountries.eu/rest/v2/name/{country}?fullText=true";
            var validator = new AssetCountryValidator(HttpDataAccess.SendRequestAsync(url));
            var dto       = GetValidationResultDto(await validator.ValidateAsync(country));

            return(Ok(dto));
        }