public ActionResult Index(FormCollection forms) { var model = new ViewModel() { InputString = forms["query"], ListCurrencyUnit = SpaceTrading.Instance.GetAllCurrencyUnit(), ListItemTrading = SpaceTrading.Instance.GetAllItemsTrading(), Status = false, }; try { var exchangeResult = new ExchangeResult(); if (!string.IsNullOrEmpty(forms["query"])) { exchangeResult = SpaceTrading.Instance.ExchangeSpaceCredits(forms["query"]); } model.ListCurrencyUnit = SpaceTrading.Instance.GetAllCurrencyUnit(); model.ListItemTrading = SpaceTrading.Instance.GetAllItemsTrading(); model.Message = exchangeResult.Message; model.Result = exchangeResult.Result; model.Status = exchangeResult.Status; model.IsCredit = exchangeResult.IsCredit; } catch (Exception ex) { model.Message = ex.Message; } return(View("Index", model)); }
public static PageResult Restore(string json) { Email email = JsonConvert.DeserializeObject <Email>(json); ExchangeResult result = email.Restore(); return(new PageResult(200, result.message)); }
public ExchangeResult BuyCurrecy(decimal customerAmount, string currencyType) { MoneyExchangeData data = new MoneyExchangeData(); var getMoneyExchangeRate = data.GetMoneyExchange(currencyType.ToString()); ExchangeResult result = new ExchangeResult(); if (getMoneyExchangeRate != null) { if (customerAmount == 0) { result.Message = Constants.ExchangeZeroAmountMessage; return(result); } if (getMoneyExchangeRate.SellRate == 0) { result.Message = Constants.ExchangeSellAmountZeroMessage; return(result); } result.Message = Constants.ExchangeSuccessMessage; result.ExchangeRate = Math.Round(Convert.ToDecimal(customerAmount * (1 / getMoneyExchangeRate.SellRate)), 4); result.SuggestedExchangeRate = Math.Round(result.ExchangeRate, 0); result.CurrencyConvertedFrom = CurrencyType.SGD.ToString(); result.CurrencyConvertedTo = currencyType.ToString(); } else { result.Message = Constants.ExchangeDoNotBuyConvertMessage; } return(result); }
public EzExchangeResult( ExchangeResult result ) { if (result.item != null) { Item = new EzRateModel(result.item); } StampSheet = result.stampSheet; StampSheetEncryptionKeyId = result.stampSheetEncryptionKeyId; }
public string GetRateStats(List <DateTime> dates, string baseCurrency, string targetCurrency) { try { using (HttpClient client = new HttpClient()) { DateTime minDate = DateTime.MinValue; DateTime maxDate = DateTime.MinValue; double minRate = double.MaxValue; double maxRate = double.MinValue; double avgSum = 0; int avgCount = 0; client.BaseAddress = new Uri(BaseURL); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.Timeout = new TimeSpan(0, 30, 0); var task = client.GetAsync("history?start_at=" + dates.Min().ToString("yyyy-MM-dd") + "&end_at=" + dates.Max().ToString("yyyy-MM-dd") + "&symbols=" + targetCurrency + "&base=" + baseCurrency); task.Wait(); HttpResponseMessage response = task.Result; ExchangeResult result = JsonConvert.DeserializeObject <ExchangeResult>(response.Content.ReadAsStringAsync().Result); foreach (var i in result.Rates) { DateTime currDateTime = DateTime.Parse(i.Key); if (dates.Contains(currDateTime)) { double currRate = 0; if (double.TryParse(i.Value[targetCurrency].ToString(), out currRate)) { avgSum += currRate; avgCount++; if (minRate > currRate) { minRate = currRate; minDate = currDateTime; } if (maxRate < currRate) { maxRate = currRate; maxDate = currDateTime; } } } } StringBuilder sb = new StringBuilder(); sb.AppendFormat("A min rate of {0} on {1},\nA max rate of {2}, on {3},\nAn average rate of {4}", minRate, minDate.ToString("yyyy-MM-dd"), maxRate, maxDate.ToString("yyyy-MM-dd"), avgSum / avgCount); //NOTE: Return note if some date does not have currency. return(sb.ToString()); } } catch (Exception e) { //LOG EXCEPTION!!!! return("An error occured, please contact administrator."); } }
ExchangeResult CheckTrade() { int player = exchangeBottom.Grid.GetTradeValue(); int trader = exchangeTop.Grid.GetTradeValue(); ExchangeResult result = (player >= trader && exchangeBottom.Grid.Count > 0) ? ExchangeResult.Ok : ExchangeResult.Ng; if (exchangeTop.Grid.Count - exchangeBottom.Grid.Count > inventory.FreeSlots) { result = ExchangeResult.Ng; } if (exchangeBottom.Grid.Count - exchangeTop.Grid.Count > inventoryTrader.FreeSlots) { result = ExchangeResult.Ng; } return(result); }
static void Main(string[] args) { while (true) { Console.Write("Action (quit|delete|restore): "); string action = Console.ReadLine().ToLower(); if (action.StartsWith("q")) { break; } Console.Write("Recipient: "); string recipient = Console.ReadLine(); recipient = recipient.Replace("\\", "\\\\"); recipient = recipient.Replace("\"", "\\\""); Console.Write("MessageId: "); string message_id = Console.ReadLine(); message_id = message_id.Replace("\\", "\\\\"); message_id = message_id.Replace("\"", "\\\""); string json = "{\"recipient\":\"" + recipient + "\",\"message_id\":\"" + message_id + "\"}"; Email email = JsonConvert.DeserializeObject <Email>(json); ExchangeResult result = null; if (action.StartsWith("d")) { result = email.Delete(); } else if (action.StartsWith("r")) { result = email.Restore(); } else { Console.WriteLine("invalid action"); continue; } Console.WriteLine(result.message); } }
void WriteResult(HttpContext context, int errno, ExchangeData checkData) { ExchangeResult result = new ExchangeResult(); if (errno == 0) { result.errno = errno; result.errmsg = "充值成功"; result.data = checkData; } else if (errno == 1) { result.errno = errno; result.errmsg = "订单重复"; } else if (errno == -1) { result.errno = errno; result.errmsg = "参数不全"; } else if (errno == -2) { result.errno = errno; result.errmsg = "签名错误"; } else if (errno == -3) { result.errno = errno; result.errmsg = "用户不存在"; } else if (errno == -4) { result.errno = errno; result.errmsg = "请求超时"; } string str = JsonHelper.ConvertToStr(result); context.Response.Write(str); }
/// <summary> /// Executes a get request to the ExchangeRate API. /// </summary> /// <param name="currency">The request payload passed in by the client.</param> /// <returns>A double representing the conversion result.</returns> public object GetCurrency(Currency currency) { // Get result from exchangerate API (docs here https://www.exchangerate-api.com/docs/c-sharp-currency-api). try { // Prepare the URl. string URLString = $"https://v6.exchangerate-api.com/v6/{DotNetConstants.EXCHANGE_RATE_API_KEY}/latest/{currency.SourceCurrency}"; using var webClient = new WebClient(); // Get the json result from the API. var json = webClient.DownloadString(URLString); // Convert it into the ExchangeResult object using NewtonSoft. ExchangeResult result = JsonConvert.DeserializeObject <ExchangeResult>(json); // Compute the conversion and return the result. return(ExchangeUtility.Convert(currency, result)); } catch (Exception ex) { return(ex); } }
public void SendResultWithOutScript(ExchangeResult result) { WAFContext.Session.SendExchangeValue(ExchangeId, result, null, false); }
public void SendResult(ExchangeResult result, object value) { WAFContext.Session.SendExchangeValue(ExchangeId, result, value, false); CloseExchange(); }
public void SendResult(ExchangeResult result) { WAFContext.Session.SendExchangeValue(ExchangeId, result, null, false); CloseExchange(); }
protected async override Task <HandleResult> HandleCoreAsync(ExchangeRequest reqObj) { bool syncLocked = false; int totalWait = 0; do { if (totalWait > 10) { return(new HandleResult { State = HandleStates.TimeOut, Msg = "排队人数过多,请稍候再试。" }); } await Task.Delay(1000); syncLocked = _cacheManager.GetCache <ISyncRootCache>().AcquireSyncLock(SYNC_TYPE_EXCHANGE, reqObj.GiftId); totalWait++; } while (!syncLocked); ExchangeResult exchangeResult = await _giftRepo.DoExchangeAsync(reqObj.UserId, reqObj.GiftId, reqObj.ReqInfoId, reqObj.Amount); HandleResult result = null; switch (exchangeResult) { case ExchangeResult.Success: ReloadUserInfo(reqObj.UserId); result = new HandleResult { State = HandleStates.Success, Msg = "礼品兑换成功" }; break; case ExchangeResult.InsufficientBalance: result = new HandleResult { State = HandleStates.InvalidData, Msg = "可用金币不足" }; break; case ExchangeResult.ReachLimit: result = new HandleResult { State = HandleStates.InvalidData, Msg = "已经兑换过此礼品", }; break; case ExchangeResult.SoldOut: result = new HandleResult { State = HandleStates.NoDataFound, Msg = "礼品被兑换完了,下次早点来吧" }; break; case ExchangeResult.ConcurrencyError: result = new HandleResult { State = HandleStates.InvalidData, Msg = "出错了,请稍候重试" }; break; case ExchangeResult.RequireInfo: result = new HandleResult { State = HandleStates.InvalidData, Msg = "礼品接收信息有误,请重试" }; break; default: result = new HandleResult { State = HandleStates.UnkownError, Msg = "出了点问题,请稍后重试" }; break; } return(result); }
public async Task <IActionResult> Execute([FromBody] ExchangeModel request) { try { ExchangeResult exchangeResult = await _exchangeService.ExecuteAsync(Mapper.Map <ExchangeCommand>(request)); return(Ok(Mapper.Map <ExchangeResponse>(exchangeResult))); } catch (AssetNetworkNotDefinedException e) { _log.ErrorWithDetails(e, new { e.AssetId }); return(BadRequest(ErrorResponse.Create(e.Message))); } catch (ExchangeOperationNotSupportedException e) { _log.ErrorWithDetails(e, request); return(BadRequest(ErrorResponse.Create(e.Message))); } catch (InvalidOperationException e) { _log.ErrorWithDetails(e, request); return(BadRequest(ErrorResponse.Create(e.Message))); } catch (AssetPairUnknownException e) { _log.ErrorWithDetails(e, new { e.BaseAssetId, e.QuotingAssetId }); return(BadRequest(ErrorResponse.Create(e.Message))); } catch (InsufficientFundsException e) { _log.ErrorWithDetails(e, new { e.WalletAddress, e.AssetId }); return(BadRequest(ErrorResponse.Create(e.Message))); } catch (ExchangeOperationFailedException e) { _log.ErrorWithDetails(e, new { errors = e.TransferErrors }); return(BadRequest(ErrorResponse.Create(e.Message))); } catch (ExchangeRateChangedException e) { _log.ErrorWithDetails(e, new { e.CurrentRate, request.ExpectedRate }); return(BadRequest(ErrorResponse.Create(e.Message))); } catch (MultipleDefaultMerchantWalletsException e) { _log.ErrorWithDetails(e, new { e.AssetId, e.MerchantId, e.PaymentDirection }); return(BadRequest(ErrorResponse.Create(e.Message))); } catch (DefaultMerchantWalletNotFoundException e) { _log.ErrorWithDetails(e, new { e.AssetId, e.MerchantId, e.PaymentDirection }); return(BadRequest(ErrorResponse.Create(e.MerchantId))); } catch (MerchantWalletOwnershipException e) { _log.ErrorWithDetails(e, new { e.MerchantId, e.WalletAddress }); return(BadRequest(ErrorResponse.Create(e.Message))); } }
public async Task <IActionResult> PreExchange([FromBody] PreExchangeModel request) { try { ExchangeResult exchangeResult = await _exchangeService.PreExchangeAsync(Mapper.Map <PreExchangeCommand>(request)); return(Ok(Mapper.Map <ExchangeResponse>(exchangeResult))); } catch (InvalidOperationException e) { _log.ErrorWithDetails(e, request); return(BadRequest(ErrorResponse.Create(e.Message))); } catch (AssetPairUnknownException e) { _log.ErrorWithDetails(e, new { e.BaseAssetId, e.QuotingAssetId }); return(BadRequest(ErrorResponse.Create(e.Message))); } catch (ExchangeOperationNotSupportedException e) { _log.ErrorWithDetails(e, request); return(BadRequest(ErrorResponse.Create(e.Message))); } catch (MultipleDefaultMerchantWalletsException e) { _log.ErrorWithDetails(e, new { e.AssetId, e.MerchantId, e.PaymentDirection }); return(BadRequest(ErrorResponse.Create(e.Message))); } catch (DefaultMerchantWalletNotFoundException e) { _log.ErrorWithDetails(e, new { e.AssetId, e.MerchantId, e.PaymentDirection }); return(BadRequest(ErrorResponse.Create(e.MerchantId))); } catch (InsufficientFundsException e) { _log.ErrorWithDetails(e, new { e.WalletAddress, e.AssetId }); return(BadRequest(ErrorResponse.Create(e.Message))); } }
/// <summary> /// Converts the user selected currency and amount into /// the desired currency, based on the latest exchange /// rate snapshot. public static double Convert(Currency currency, ExchangeResult result) { switch (currency.TargetCurrency) { case "AED": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.AED)); case "ARS": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.ARS)); case "AUD": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.AUD)); case "BGN": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.BGN)); case "BRL": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.BRL)); case "BSD": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.BSD)); case "CAD": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.CAD)); case "CHF": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.CHF)); case "CLP": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.CLP)); case "CNY": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.CNY)); case "COP": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.COP)); case "CZK": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.CZK)); case "DKK": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.DKK)); case "DOP": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.DOP)); case "EGP": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.EGP)); case "EUR": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.EUR)); case "FJD": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.FJD)); case "GBP": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.GBP)); case "GTQ": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.GTQ)); case "HKD": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.HKD)); case "HRK": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.HRK)); case "HUF": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.HUF)); case "IDR": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.IDR)); case "ILS": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.ILS)); case "INR": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.INR)); case "ISK": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.ISK)); case "JPY": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.JPY)); case "KRW": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.KRW)); case "KZT": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.KZT)); case "MXN": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.MXN)); case "MYR": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.MYR)); case "NOK": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.NOK)); case "NZD": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.NZD)); case "PAB": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.PAB)); case "PEN": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.PEN)); case "PHP": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.PHP)); case "PKR": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.PKR)); case "PLN": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.PLN)); case "PYG": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.PYG)); case "RON": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.RON)); case "RUB": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.RUB)); case "SAR": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.SAR)); case "SEK": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.SEK)); case "SGD": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.SGD)); case "THB": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.THB)); case "TRY": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.TRY)); case "TWD": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.TWD)); case "UAH": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.UAH)); case "USD": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.USD)); case "UYU": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.UYU)); case "ZAR": return(GetExchangeResult(currency.SourceAmount, result.conversion_rates.ZAR)); default: return(0.0); } }