コード例 #1
0
        public AzureMapResults Get_Bc_CustomerCoordinates(BC_Customer 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_CustomerCoordinates> UpdateCustomer(BC_Customer customer, AzureMapResults azureMapResults, string filter)
        {
            try
            {
                using (var client = new HttpClient())
                {
                    var coords = new BC_CustomerCoordinates();
                    coords.NblLatitude = azureMapResults.Results.ElementAt(0).Position.Lat;
                    coords.NblLogitude = azureMapResults.Results.ElementAt(0).Position.Lon;
                    coords.No          = customer.No;

                    var apiUpdateEndpoint = apiEndpoint + 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_CustomerCoordinates>(responseJson);
                        return(customerCoord);
                    }
                    else
                    {
                        Debugger.Break();
                    }
                    return(null);
                }
            }
            catch (Exception ex)
            {
                log.LogError(ex.Message.ToString());
                return(null);
            }
        }