Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="inCity"></param>
        /// <param name="outCity"></param>
        /// <param name="weight">Вес (кг)</param>
        /// <param name="volume">объем m3(не обязательно)</param>
        /// <returns></returns>
        private async Task <string> CalculateCostAsync(string inCityName, string OutCityName, double weight)
        {
            if (weight <= 0)
            {
                return("Неправильно указан вес");
            }

            DpdCalculator.city inCity = CastGeoCityToCalcCity(FindCityByFullName(inCityName));
            if (inCity == null)
            {
                return("Неизвестный город получения");
            }
            DpdCalculator.city outCity = CastGeoCityToCalcCity(FindCityByFullName(OutCityName));
            if (outCity == null)
            {
                return("Неизвестный город отправления");
            }


            var client = new DPDCalculatorClient();

            var serviceRequest = new serviceCostRequest
            {
                auth = new DpdCalculator.auth
                {
                    clientKey    = clientKey,
                    clientNumber = clientNumber
                },
                pickup = new cityRequest
                {
                    cityId              = inCity.cityId,
                    cityIdSpecified     = inCity.cityIdSpecified,
                    cityName            = inCity.cityName,
                    countryCode         = inCity.countryCode,
                    regionCode          = inCity.regionCode,
                    regionCodeSpecified = inCity.regionCodeSpecified
                },
                delivery = new cityRequest
                {
                    cityId              = outCity.cityId,
                    cityIdSpecified     = outCity.cityIdSpecified,
                    cityName            = outCity.cityName,
                    countryCode         = outCity.countryCode,
                    regionCode          = outCity.regionCode,
                    regionCodeSpecified = outCity.regionCodeSpecified
                },
                selfDelivery = false,
                selfPickup   = false,
                weight       = weight,
                serviceCode  = "MAX"
            };

            var request = await client.getServiceCost2Async(serviceRequest);

            return([email protected]().cost.ToString());
        }
Beispiel #2
0
        public async Task <serviceCost[]> CalculateCost(string inCityName, string OutCityName, double weight, double volume = 1)
        {
            DPDCalculatorTest.city inCity  = CastGeoCityToCalcCity(FindCityByFullName(inCityName));
            DPDCalculatorTest.city outCity = CastGeoCityToCalcCity(FindCityByFullName(OutCityName));
            DPDCalculatorTest.auth auth    = new DPDCalculatorTest.auth
            {
                clientKey    = _authdata.clientKey,
                clientNumber = _authdata.clientNumber
            };
            var client = new DPDCalculatorClient();

            var serviceRequest = new serviceCostRequest
            {
                auth   = auth,
                pickup = new cityRequest
                {
                    cityId              = inCity.cityId,
                    cityIdSpecified     = inCity.cityIdSpecified,
                    cityName            = inCity.cityName,
                    countryCode         = inCity.countryCode,
                    regionCode          = inCity.regionCode,
                    regionCodeSpecified = inCity.regionCodeSpecified
                },// new CityRequestExtend(inCity),
                delivery = new cityRequest
                {
                    cityId              = outCity.cityId,
                    cityIdSpecified     = outCity.cityIdSpecified,
                    cityName            = outCity.cityName,
                    countryCode         = outCity.countryCode,
                    regionCode          = outCity.regionCode,
                    regionCodeSpecified = outCity.regionCodeSpecified
                },// new CityRequestExtend(outCity),
                selfDelivery = false,
                selfPickup   = false,
                weight       = weight,
                volume       = volume
            };

            var request = await client.getServiceCost2Async(serviceRequest);

            return(request.@return);
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="inCity"></param>
        /// <param name="outCity"></param>
        /// <param name="weight">Вес (кг)</param>
        /// <param name="volume">объем m3(не обязательно)</param>
        /// <returns></returns>
        private async Task <string> CalculateCostAsync(string inCityName, string OutCityName, double weight)
        {
            if (weight <= 0)
            {
                return("Неправильно указан вес");
            }

            var inCity = CastGeoCityToCalcCity(FindCityByFullName(inCityName));

            if (inCity == null)
            {
                return("Неизвестный город получения");
            }
            var outCity = CastGeoCityToCalcCity(FindCityByFullName(OutCityName));

            if (outCity == null)
            {
                return("Неизвестный город отправления");
            }


            var client = new DPDCalculatorClient();

            var serviceRequest = new serviceCostRequest
            {
                auth = new DpdCalculator.auth
                {
                    clientKey    = clientKey,
                    clientNumber = clientNumber
                },
                pickup = new cityRequest
                {
                    cityId              = inCity.cityId,
                    cityIdSpecified     = inCity.cityIdSpecified,
                    cityName            = inCity.cityName,
                    countryCode         = inCity.countryCode,
                    regionCode          = inCity.regionCode,
                    regionCodeSpecified = inCity.regionCodeSpecified
                },
                delivery = new cityRequest
                {
                    cityId              = outCity.cityId,
                    cityIdSpecified     = outCity.cityIdSpecified,
                    cityName            = outCity.cityName,
                    countryCode         = outCity.countryCode,
                    regionCode          = outCity.regionCode,
                    regionCodeSpecified = outCity.regionCodeSpecified
                },
                selfDelivery = false,  //самопривоз самовывоз с терминала
                selfPickup   = false,  //самопривоз на терминал
                weight       = weight, //*
                serviceCode  = "MAX"   //если сервис не задан возвращает список всех доступных услуг
            };

            try
            {
                var request = await client.getServiceCost2Async(serviceRequest);

                /*Если услуга была задана во входном сообщении, то при успешном выполнении запроса массив ответного сообщения будет состоять из одного элемента.*/
                return([email protected]().cost.ToString());
            }
            catch (FaultException)
            {
                return("Ошибка ответа");
            }
        }