Пример #1
0
        public static async Task <PriceInquiryResult> PriceInquiry(LocationDTO originLocation, LocationDTO destinationLocation, bool cashed, bool hasReturn)
        {
            try
            {
                var result = new PriceInquiryResult
                {
                    DeliveryProviderId = 2,
                    DeliveryType       = "Post",
                    DeliveryType_Fa    = "پست",

                    Price             = 12000,
                    Final_Price       = 12000,
                    Distance          = "0",
                    Discount          = 0,
                    Duration          = "0",
                    Delay             = 0,
                    Cashed            = cashed,
                    Has_Return        = hasReturn,
                    Price_With_Return = 15000,
                    Addresses         = null
                };

                return(result);
            }
            catch (Exception e)
            {
                FileLoger.Error(e);

                return(null);
            }
        }
Пример #2
0
        public static async Task <PriceInquiryResult> PriceInquiry(LocationDTO origin, LocationDTO destination, bool cashed, bool hasReturn)
        {
            var result = new PriceInquiryResult();

            try
            {
                #region Create Request Bode
                var model = new
                {
                    transport_type = AloPeikTransportType.motor_taxi.ToString(),
                    addresses      = new List <dynamic> {
                        new { type = AloPeikAddressType.origin.ToString(), lat = origin.Lat, lng = origin.Lng },
                        new { type = AloPeikAddressType.destination.ToString(), lat = destination.Lat, lng = destination.Lng }
                    },
                    has_return = hasReturn,
                    cashed     = cashed
                };
                #endregion

                using (var httpClient = new HttpClient())
                {
                    var body = new StringContent(model.SerializeToJson(), Encoding.UTF8, "application/json");
                    httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", GlobalVariables.DeliveryProviders.AloPeik.Token);
                    var response = await httpClient.PostAsync($"{GlobalVariables.DeliveryProviders.AloPeik.Url}/orders/price/calc", body);

                    var responseBody = await response.Content.ReadAsStringAsync();

                    var responseResult = responseBody.DeSerializeJson <AloPeikResult <PriceInquiryResult> >();
                    if (responseResult.Status == "success")
                    {
                        result = new PriceInquiryResult
                        {
                            DeliveryProviderId = 1,
                            DeliveryType       = "Peyk",
                            DeliveryType_Fa    = "پیک",

                            Price             = responseResult.Object.Price,
                            Final_Price       = responseResult.Object.Final_Price,
                            Distance          = responseResult.Object.Distance,
                            Discount          = responseResult.Object.Discount,
                            Duration          = responseResult.Object.Duration,
                            Delay             = responseResult.Object.Delay,
                            Cashed            = responseResult.Object.Cashed,
                            Has_Return        = responseResult.Object.Has_Return,
                            Price_With_Return = responseResult.Object.Price_With_Return,
                            Addresses         = new List <AloPeikAddress> {
                                new AloPeikAddress {
                                    Type = responseResult.Object.Addresses[0].Type, Address = responseResult.Object.Addresses[0].Address, City_Fa = responseResult.Object.Addresses[0].City_Fa
                                },
                                new AloPeikAddress {
                                    Type = responseResult.Object.Addresses[1].Type, Address = responseResult.Object.Addresses[1].Address, City_Fa = responseResult.Object.Addresses[1].City_Fa
                                },
                            }
                        };
                    }
                    else
                    {
                        result = null;
                    }
                }

                return(result);
            }
            catch (Exception e)
            {
                FileLoger.Error(e);

                return(null);
            }
        }