public async Task<PublishedRate> CalculatePublishedRateAsync(QuotationRequest request, Product product, IEnumerable<ValueAddedService> valueAddedServices) { var url = new StringBuilder(); if (request.ReceiverCountry == "MY" || request.ReceiverCountry == "Malaysia") { request.ItemCategory = request.Weight < 2.01m ? "Document" : "Merchandise"; } url.Append("/calculator/CalculateRate2"); url.Append($"?ProductCode={product.Code}"); url.Append($"&SenderPostCode={request.SenderPostcode}&SenderCountryCode=MY&ReceiverPostCode={request.ReceiverPostcode}&ReceiverCountryCode={request.ReceiverCountry}"); url.Append($"&ItemCategoryName={request.ItemCategory}"); url.Append($"&ActualWeight={request.Weight}&Width={request.Width}&Height={request.Height}&Length={request.Length}"); url.Append($"&surcharge_S01=S01&surcharge_S03=S03&surcharge_S05=S05"); // 3 surcharge wajib foreach (var v in valueAddedServices) { url.Append($"&vas_{v.Code}={v.Code}"); foreach (var p in v.UserInputs) { url.Append($"&{v.Code}_{p.Name}={p.Value}"); } } var response = await m_snbWebAppClient.GetStringAsync(url.ToString()); var json = JObject.Parse(response); var rate = new PublishedRate(json); rate.ProductCode = product.Code; rate.ProductName = product.Name; rate.ItemCategory = request.ItemCategory; return rate; }
public async Task<decimal?> CalculateValueAddedServiceAsync(QuotationRequest request, Product product, ValueAddedService vas) { var userInputs = string.Join("\r\n", vas.UserInputs.Select(x => $"public const decimal {x.Name} = {x.Value}m;")); var options = ScriptOptions.Default .WithImports("System") .WithImports("System.Math"); var script = CSharpScript .Create<decimal>($@" using System; public class CalcHost {{ const string ITEM_CATEGORY_NAME = ""{request.ItemCategory}""; const bool IS_INTERNATIONAL = {(request.ReceiverCountry != "MY" ? "true" : "false")}; {userInputs} // TODO : like BASE_RATE and stuff public decimal Evaluate() {{ {vas.Formula} }} }} ").ContinueWith(@" var calc = new CalcHost(); ").ContinueWith(@" return calc.Evaluate(); ").WithOptions(options); var result = await script.RunAsync(); return (decimal?)result.ReturnValue; }
public async Task <decimal?> CalculateValueAddedServiceAsync(QuotationRequest request, Product product, ValueAddedService vas) { await Task.Delay(2000); if (string.IsNullOrWhiteSpace(vas.Formula)) { return(new Random(DateTime.Now.Second).Next(DateTime.Now.Millisecond)); } return(vas.Formula.Length); }
public Task <PublishedRate> CalculatePublishedRateAsync(QuotationRequest request, Product product, IEnumerable <ValueAddedService> valueAddedServices) { // throw new NotImplementedException(); }