Example #1
0
        public int GetCost(string cityIdFrom, string cityIdTo, string weight, string assessedCost)
        {
            int cost     = -1;
            var settings = _settingService.LoadSetting <NewPostSettings>();
            var request  = new NewPostApiRequest <NewPostInternetDocumentGetDocumentPrice>()
            {
                apiKey           = settings.ApiKey,
                modelName        = "Address",
                calledMethod     = "searchSettlements",
                methodProperties = new NewPostInternetDocumentGetDocumentPrice()
                {
                    CargoType     = "Cargo",
                    ServiceType   = "DoorsDoors",
                    CitySender    = cityIdFrom,
                    CityRecipient = cityIdTo,
                    Weight        = weight,
                    Cost          = assessedCost
                }
            };

            try
            {
                var client = new HttpClient();
                client.BaseAddress = new Uri(settings.Url);
                var response = client.PostAsync("en/getDocumentPrice/json/", new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json")).Result;

                if (response.IsSuccessStatusCode)
                {
                    string result   = response.Content.ReadAsStringAsync().Result;
                    var    responce = JsonConvert.DeserializeObject <NewPostApiResponse <List <NewPostCost> > >(result);
                    if (responce.success && responce.data.Count > 0)
                    {
                        cost = responce.data[0].Cost;
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("New post has been throw exception when does the GetCost", ex);
            }

            return(cost);
        }
Example #2
0
        public string GetCityId(string cityName)
        {
            var cityId   = string.Empty;
            var settings = _settingService.LoadSetting <NewPostSettings>();
            var request  = new NewPostApiRequest <NewPostAddressSearchSettlements>()
            {
                apiKey           = settings.ApiKey,
                modelName        = "Address",
                calledMethod     = "searchSettlements",
                methodProperties = new NewPostAddressSearchSettlements()
                {
                    CityName = cityName.Trim().ToLower(),
                    Limit    = 1
                }
            };

            try
            {
                var client = new HttpClient();
                client.BaseAddress = new Uri(settings.Url);
                var response = client.PostAsync("json/Address/searchSettlements", new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json")).Result;

                if (response.IsSuccessStatusCode)
                {
                    string result   = response.Content.ReadAsStringAsync().Result;
                    var    responce = JsonConvert.DeserializeObject <NewPostApiResponse <List <NewPostAddressList> > >(result);
                    if (responce.success && responce.data.Count > 0 && responce.data[0].Addresses.Count > 0)
                    {
                        cityId = responce.data[0].Addresses[0].DeliveryCity;
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("New post has been throw exception when does the GetCityId", ex);
            }

            return(cityId);
        }