コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("id,TradeDate,CurrencyPairID,Rate,DateTimeModified,DateTimeAdded")] Dfr dfr)
        {
            if (id != dfr.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    dfr.DateTimeModified = Utility.GetLocalDateTime();
                    _context.Update(dfr);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DfrExists(dfr.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewBag.CurrencyPair = new SelectList(_context.CurrencyPair.OrderBy(x => x.CurrencyPairName).ToList(), "id", "CurrencyPairName");
            return(View(dfr));
        }
コード例 #2
0
        // GET: Dfr/Create
        public IActionResult Create()
        {
            ViewBag.CurrencyPair = new SelectList(_context.CurrencyPair.OrderBy(x => x.CurrencyPairName).ToList(), "id", "CurrencyPairName");
            //ViewData["DefaultDate"] = Utility.GetLocalDateTime().Date.ToString("yyyy-MM-dd");

            Dfr dfr = new Dfr();

            dfr.TradeDate = Utility.GetLocalDateTime().Date;

            return(View("Create", dfr));
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("id,TradeDate,CurrencyPairID,Rate,DateTimeModified,DateTimeAdded")] Dfr dfr)
        {
            if (ModelState.IsValid)
            {
                dfr.DateTimeModified = Utility.GetLocalDateTime();
                dfr.DateTimeAdded    = Utility.GetLocalDateTime();
                _context.Add(dfr);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewBag.CurrencyPair = new SelectList(_context.CurrencyPair.OrderBy(x => x.CurrencyPairName).ToList(), "id", "CurrencyPairName");
            return(View(dfr));
        }
コード例 #4
0
        public ActionResult UpdateDfr2()
        {
            //ChromeOptions options = new ChromeOptions();
            //options.AddArgument("headless");

            //Close the Chrome Driver console
            //ChromeDriverService driverService = ChromeDriverService.CreateDefaultService();
            //driverService.HideCommandPromptWindow = true;

            //ChromeDriver driver = new ChromeDriver(driverService, options);
            //driver.Navigate().GoToUrl("https://www.xe.com/currencyconverter/convert/?Amount=1&From=USD&To=VND");
            //string html = driver.PageSource;

            //WebBrowser wb;
            //HtmlWeb w = new HtmlWeb();
            //HtmlAgilityPack.HtmlDocument doc = w.Load("https://www.xe.com/currencyconverter/convert/?Amount=1&From=USD&To=VND");
            string             url;//"https://www.x-rates.com/calculator/?from=USD&to=hkd"
            HtmlNodeCollection colNode;
            decimal            rate;
            var currencyPair = _context.CurrencyPairView;

            DateTime today   = Utility.GetLocalDateTime().Date;
            var      dfrList = _context.Dfr.Where(m => m.TradeDate == today);

            _context.RemoveRange(dfrList);

            foreach (var cp in currencyPair)
            {
                url     = "https://www.x-rates.com/calculator/?from=" + cp.CurrencyName1 + "&to=" + cp.CurrencyName2;
                colNode = getNodes(url, "//span[@class='ccOutputRslt']");

                string[] s           = colNode[0].InnerText.Split(" ");
                bool     parseResult = decimal.TryParse(s[0], out rate);

                if (parseResult)
                {
                    Dfr dfr = new Dfr();
                    dfr.TradeDate        = Utility.GetLocalDateTime().Date;
                    dfr.CurrencyPairID   = cp.id;
                    dfr.Rate             = rate;
                    dfr.DateTimeAdded    = Utility.GetLocalDateTime();
                    dfr.DateTimeModified = Utility.GetLocalDateTime();
                    _context.Add(dfr);
                }
            }
            _context.SaveChanges();
            //var txn = _context.TxnCompleteView.Where(x => x.id == txnID).FirstOrDefault();
            return(Json(null));
        }
コード例 #5
0
        public ActionResult UpdateDfr()
        {
            string             url;
            HtmlNodeCollection colNode;
            string             resp;
            bool    parseResult;
            decimal rate;
            var     currencyPair = _context.CurrencyPairView;

            DateTime today = Utility.GetLocalDateTime().Date;

            var dfrList = _context.Dfr.Where(m => m.TradeDate == today);

            _context.RemoveRange(dfrList);

            foreach (var cp in currencyPair)
            {
                if (cp.CurrencyName1 == "ETH" || cp.CurrencyName1 == "UST" || cp.CurrencyName2 == "ETH" || cp.CurrencyName2 == "UST")
                {
                    string currFrom = cp.CurrencyName1 == "UST" ? "USDT" : cp.CurrencyName1;
                    string currTo   = cp.CurrencyName2 == "UST" ? "USDT" : cp.CurrencyName2;

                    url  = "https://min-api.cryptocompare.com/data/price?fsym=" + currFrom + "&tsyms=" + currTo;
                    resp = getWebResponse(url);
                    var result = Regex.Match(resp, @"\d+(\.\d+)?").Value;

                    parseResult = decimal.TryParse(result, out rate);

                    if (parseResult)
                    {
                        Dfr dfr = new Dfr();
                        dfr.TradeDate        = Utility.GetLocalDateTime().Date;
                        dfr.CurrencyPairID   = cp.id;
                        dfr.Rate             = rate;
                        dfr.DateTimeAdded    = Utility.GetLocalDateTime();
                        dfr.DateTimeModified = Utility.GetLocalDateTime();
                        _context.Add(dfr);
                    }
                }
                else
                {
                    url = "https://xecdapi.xe.com/v1/convert_from.xml/?from=" + cp.CurrencyName1 + "&to=" + cp.CurrencyName2;

                    colNode = getNodes(url, "//to/rate/mid");
                    if (colNode != null)
                    {
                        string s = colNode[0].InnerText;
                        parseResult = decimal.TryParse(s, NumberStyles.Float, CultureInfo.CreateSpecificCulture("en-US"), out rate);

                        if (parseResult)
                        {
                            Dfr dfr = new Dfr();
                            dfr.TradeDate        = Utility.GetLocalDateTime().Date;
                            dfr.CurrencyPairID   = cp.id;
                            dfr.Rate             = rate;
                            dfr.DateTimeAdded    = Utility.GetLocalDateTime();
                            dfr.DateTimeModified = Utility.GetLocalDateTime();
                            _context.Add(dfr);
                        }
                    }
                }
            }
            _context.SaveChanges();
            //var txn = _context.TxnCompleteView.Where(x => x.id == txnID).FirstOrDefault();
            return(Json(null));
        }