private async Task <Response <Address> > CreateAddressAsync(GasStationDto dto)
        {
            var response = Response <Address> .Create();

            var addressResponse = Address.Create(dto.Address.Cep, dto.Address.StreetAddress, dto.Address.City, dto.Address.UF, dto.Address.Complement);

            if (addressResponse.HasError)
            {
                return(addressResponse);
            }

            var address = $"{addressResponse.Data.Value.StreetAddress}"
                          + $"+{(!string.IsNullOrEmpty(addressResponse.Data.Value.Complement) ? $"{addressResponse.Data.Value.Complement}," : string.Empty)}"
                          + $"+{addressResponse.Data.Value.City}"
                          + $"+{addressResponse.Data.Value.UF}"
                          + $"CEP: {addressResponse.Data.Value.Cep}";

            var geocodingResponse = await GeolocationExternalService.GetGeolocationAsync(address);

            if (geocodingResponse.HasError)
            {
                return(response.WithMessages(geocodingResponse.Messages));
            }

            var setCordinatesResponse = addressResponse.Data.Value.SetLocation(geocodingResponse.Data.Value.Longitude, geocodingResponse.Data.Value.Latitude);

            if (setCordinatesResponse.HasError)
            {
                return(response.WithMessages(setCordinatesResponse.Messages));
            }

            return(response.SetValue(addressResponse));
        }
示例#2
0
        async Task <Response <GetLocationDto> > GetGeocodingAsync(string address)
        {
            var response = Response <GetLocationDto> .Create();

            var geocodingResponse = await GeolocationExternalService.GetGeolocationAsync(address);

            if (geocodingResponse.HasError)
            {
                return(response.WithMessages(geocodingResponse.Messages));
            }

            return(response.SetValue(geocodingResponse.Data.Value.ToGetLocationDto()));
        }
示例#3
0
        private async Task <Response> UpdateAddressAsync(Address newAddress)
        {
            var response = Response.Create();

            var address = $"{newAddress.StreetAddress}"
                          + $"+{(!string.IsNullOrEmpty(newAddress.Complement) ? $"{newAddress.Complement}," : string.Empty)}"
                          + $"+{newAddress.City}"
                          + $"+{newAddress.UF}"
                          + $"CEP: {newAddress.Cep}";

            var geocodingResponse = await GeolocationExternalService.GetGeolocationAsync(address);

            if (geocodingResponse.HasError)
            {
                return(response.WithMessages(geocodingResponse.Messages));
            }

            return(newAddress.SetLocation(geocodingResponse.Data.Value.Longitude, geocodingResponse.Data.Value.Latitude));
        }