Пример #1
0
        public AzureMapResults Get_Bc_ShipToAddressCoordinates(BC_ShipToAddress customer)
        {
            try
            {
                var address = string.Format("{0}, {1}, {2}, {3}, ({4})"
                                            , customer.Address
                                            , customer.PostCode
                                            , customer.City
                                            , customer.County
                                            , customer.Country);
                var url = string.Format(AzureMapEndpoint, AzureMapKey, address);

                using (var client = new WebClient())
                {
                    var uri = new Uri(url);

                    var response = client.DownloadString(uri).ToString();
                    var result   = JsonConvert.DeserializeObject <AzureMapResults>(response.ToString());
                    return(result);
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }
Пример #2
0
        public async Task <BC_ShipToAddresses> UpdateShipToAddress(BC_ShipToAddress customer, AzureMapResults azureMapResults, string filter)
        {
            try
            {
                using (var client = new HttpClient())
                {
                    var coords = new BC_ShipToAddressCoordinates();
                    coords.Latitude  = azureMapResults.Results.ElementAt(0).Position.Lat;
                    coords.Longitude = azureMapResults.Results.ElementAt(0).Position.Lon;
                    coords.Code      = customer.Code;

                    var apiUpdateEndpoint = apiEndpoint4C + filter;
                    var request           = new HttpRequestMessage(HttpMethod.Patch, new Uri(apiUpdateEndpoint));
                    var json = JsonConvert.SerializeObject(coords);
                    request.Content = new StringContent(json, Encoding.UTF8, "application/json");
                    request.Headers.TryAddWithoutValidation("If-Match", customer.OdataEtag);
                    request.Headers.Authorization = new AuthenticationHeaderValue("Basic", this.authHeaderValue);

                    var response = await client.SendAsync(request);

                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        var responseJson = await response.Content.ReadAsStringAsync();

                        var customerCoord = JsonConvert.DeserializeObject <BC_ShipToAddresses>(responseJson);
                        return(customerCoord);
                    }
                    else
                    {
                        Debugger.Break();
                    }

                    return(null);
                }
            }
            catch (Exception ex)
            {
                log.LogError(ex.Message.ToString());
                return(null);
            }
        }