Beispiel #1
0
        private async Task ValidateAddressAsync(Address model)
        {
            try
            {
                var result = await _googleMapsApi.GeocodeAsync(new GoogleGeocodeQueryModel
                {
                    Key     = _configuration.GetValue <string>("GOOGLE_MAPS_KEY"),
                    Address = FormattedAddress(model.Street, model.District, model.City, model.State)
                });

                if (result.Status != GoogleGeocodeStatus.OK)
                {
                    throw new AppValidationException(HttpStatusCode.BadRequest,
                                                     _localizer["Address.AddressNotValid"].Value);
                }
            } catch (ApiException e)
            {
                throw new AppValidationException(HttpStatusCode.BadRequest,
                                                 _localizer["Address.AddressNotValid"].Value,
                                                 e.Content);
            }
        }