Esempio n. 1
0
        /// <summary>
        /// Epacket Check Delivery Rate
        /// </summary>
        /// <param name="carrierID">the carrier caller defined</param>
        /// <param name="myRequest">the epacket api request</param>
        /// <param name="debug">if debug, it will not call the api and return some test value</param>
        /// <returns>
        ///  A formated return data:
        ///  JsonNetPackResult.message:  the currency rate for this ship.
        ///  JsonApiReturnData.ApiRequest: the api calling request
        ///  JsonApiReturnData.ApiResponse: the api calling response
        ///  JsonApiReturnData.BizData: nothing here , not any WHL effect
        /// </returns>
        public JsonNetPackResult CheckPackageRate(int carrierID, GetRateRequest myRequest, Boolean debug)
        {
            GetRateResponse myResponse = new GetRateResponse();

            if (debug)
            { // if in debug mode , we generate a test request
                myRequest = GenTestGetRateRequest();
            }

            Carrier carrier = db.CarriersDB.Find(carrierID);

            if (carrier == null)
            {
                return(new JsonNetPackResult(ERROR, "Carrier not exist", new JsonApiReturnData(myRequest, myResponse, null)));
            }
            EpacketAuth epacketAuth = carrier.Auth;

            if (epacketAuth == null)
            {
                return(new JsonNetPackResult(ERROR, "Auth not exist", new JsonApiReturnData(myRequest, myResponse, null)));
            }

            CommonHelper.CopyObjectValue(epacketAuth, myRequest.Auth); // 把carrier里面的auth 复制赋值到apiRequest.auth

            double deliveryCharge = 0;

            if (debug) //debug
            {
                deliveryCharge = 18.8;
            }
            else    // not debug
            {
                myResponse = myCall.GetAPACShippingRate(myRequest);
                if (myResponse.Ack.ToUpper() != "SUCCESS")
                {
                    return(new JsonNetPackResult(ERROR, "Epacket API Calling Fail, Please see Data.ApiResponse to see the problem!", new JsonApiReturnData(myRequest, myResponse, null)));
                }
                deliveryCharge = myResponse.DeliveryCharge;
            }
            return(new JsonNetPackResult(SUCCESS, deliveryCharge.ToString(), new JsonApiReturnData(myRequest, myResponse, null)));
        }
Esempio n. 2
0
        /// <summary>
        /// 获得一个测试GetRateRequest用例
        /// </summary>
        /// <returns></returns>
        public GetRateRequest GenTestGetRateRequest()
        {
            GetRateRequest myRequest = new GetRateRequest();

            myRequest.Service = "EPACK";
            myRequest.ShipFromAddress.Add(new ShipFromAddressInfo()
            {
                City        = "430100",
                Company     = "",
                Contact     = "Koyomi",
                CountryCode = "CN",
                District    = "430102",
                Email       = "*****@*****.**",
                Mobile      = "13420737774",
                Phone       = "",
                Postcode    = "511400",
                Province    = "430000",
                Street      = "Test Street"
            });
            myRequest.ShipToAddress.Add(new ShipToAddressInfo()
            {
                //City = "Shunde",
                Company     = "",
                Contact     = "Shirobu",
                CountryCode = "RU",
                District    = "",
                Email       = "*****@*****.**",
                Mobile      = "",
                Phone       = "",
                //Postcode = "528300",
                //Province = "Guangdong",
                Street = "Test Street2"
            });
            myRequest.Weight = 1;
            return(myRequest);
        }
Esempio n. 3
0
        /// <summary>
        /// Debug Test: http://localhost:6659/zh_CN/Epacket/CheckPackageRateJson?carrierID=1&debug=true
        /// Epacket Check Delivery Rate
        /// </summary>
        /// <param name="carrierID">the carrier caller defined</param>
        /// <param name="myRequest">the epacket api request</param>
        /// <param name="debug">if debug, it will not call the api and return some test value</param>
        /// <returns>
        ///  A formated return data:
        ///  JsonNetPackResult.message:  the currency rate for this ship.
        ///  JsonApiReturnData.ApiRequest: the api calling request
        ///  JsonApiReturnData.ApiResponse: the api calling response
        ///  JsonApiReturnData.BizData: nothing here , not any WHL effect
        /// </returns>
        public JsonNetResult CheckPackageRateJson(int carrierID, GetRateRequest myRequest, Boolean debug)
        {
            JsonNetPackResult packResult = epacketService.CheckPackageRate(carrierID, myRequest, debug);

            return(new JsonNetResult(packResult));
        }
Esempio n. 4
0
        /// <summary>
        /// Fetch TCMB Today's Currency Rates with GetRateRequest Object.
        /// </summary>
        /// <param name="rateRequest">GetRateRequest</param>
        /// <returns>GetRateResponse</returns>
        public GetRateResponse ExportTodaysCurrencyRates(GetRateRequest rateRequest)
        {
            var getRateResponse = new GetRateResponse();

            const string tcmbTodayUrl = "https://www.tcmb.gov.tr/kurlar/today.xml";

            var tcmbXmlDoc = new XmlDocument();

            try
            {
                // Get Rates from TCMB and Load as XmlDocument.
                tcmbXmlDoc.Load(tcmbTodayUrl);

                using var stringReader = new StringReader(tcmbXmlDoc.InnerXml);

                var serializer = new XmlSerializer(typeof(Tarih_Date));

                // Deserialize Xml response to TCMB proxy class.
                var ratesDeserialized = (Tarih_Date)serializer.Deserialize(stringReader);

                // Generate IQueryable Rates From Deserialized Response.
                var rates = TCMBServiceHelpers.GenerateRatesFromDeserializedResponse(ratesDeserialized);

                // Aggregated list for filters & orders.
                var filteredAndOrderedRates = new List <Rate>();

                // Check filter options.
                if (rateRequest.FilterByOptions != null)
                {
                    foreach (FilterByOption filterByOption in rateRequest.FilterByOptions)
                    {
                        filteredAndOrderedRates.AddRange(TCMBServiceHelpers.ApplyFilterBy(rates, filterByOption.Field, filterByOption.Value).ToList());
                    }
                }

                // Check order options
                if (rateRequest.OrderByOptions != null)
                {
                    foreach (OrderByOption orderByOption in rateRequest.OrderByOptions)
                    {
                        filteredAndOrderedRates = orderByOption.OrderType switch
                        {
                            OrderType.Ascending => TCMBServiceHelpers.ApplyOrderByAscending(filteredAndOrderedRates.AsQueryable(), orderByOption.Field).ToList(),
                            OrderType.Descending => TCMBServiceHelpers.ApplyOrderByDescending(filteredAndOrderedRates.AsQueryable(), orderByOption.Field).ToList(),
                            _ => TCMBServiceHelpers.ApplyOrderByAscending(filteredAndOrderedRates.AsQueryable(), orderByOption.Field).ToList()
                        };
                    }
                }

                // For the sake of simlicity it exports to current application's running directory.
                // Can be converted to parameter like path which can be taken at RateRequest object.
                var exportPath = Directory.GetCurrentDirectory() + $"\\Rates_of_{DateTime.Today:dd_MM_yyyy}";

                // Check export type and create Exporter.
                IExportable exporter = ExporterFactory.CreatExporter(rateRequest.ExportType);

                // Do export.
                exporter.Export(filteredAndOrderedRates, exportPath + $".{rateRequest.ExportType.ToString().ToLowerInvariant()}");

                // Add exported path to GetRateResponse.
                getRateResponse.ExportedPath = exportPath;
            }
            catch (Exception e)
            {
                // Handle Exception
                getRateResponse.HasError     = true;
                getRateResponse.ErrorMessage = e.Message;
            }

            return(getRateResponse);
        }