コード例 #1
0
        public ActionResult Create([Bind(Include = "Id,Name,Message")] Comment comment, bool captchaValid)
        {
            comment.TimeStamp = DateTime.Now;
            if (ModelState.IsValid && !string.IsNullOrWhiteSpace(comment.Name) && !string.IsNullOrWhiteSpace(comment.Message))
            {
                db.Comments.Add(comment);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View("ErrorComment"));
        }
コード例 #2
0
        public IActionResult DeleteWalletById(int id)
        {
            var wallet = context.Wallets.Find(id);

            if (wallet == null)
            {
                return(NotFound());
            }

            context.Wallets.Remove(wallet);
            context.SaveChanges();

            // Default 404 if delete was successful
            return(NoContent());
        }
コード例 #3
0
        public IActionResult DeleteFounderById(int id)
        {
            var founder = context.Founders.Find(id);

            if (founder == null)
            {
                return(NotFound());
            }

            context.Founders.Remove(founder);
            context.SaveChanges();

            // Default 404 if delete was successful
            return(NoContent());
        }
コード例 #4
0
        //Updates the coin list, adding those who are not there yet
        public async Task GetAllCoins()
        {
            string baseImageAndLinkUrl = "https://www.cryptocompare.com";
            string jsonResponse        = await SendRequest(@"https://min-api.cryptocompare.com/data/top/mktcapfull?limit=100&tsym=USD" + _apiKey);

            CurrenciesToplist topList = JsonSerializer.Deserialize <CurrenciesToplist>(jsonResponse);

            foreach (Datum datum in topList.Data)
            {
                Currency currency = new Currency()
                {
                    Name     = datum.CoinInfo.FullName,
                    Symbol   = datum.CoinInfo.Name,
                    ValueUSD = 0,
                    WebPage  = baseImageAndLinkUrl + datum.CoinInfo.Url,
                    ImageURL = baseImageAndLinkUrl + datum.CoinInfo.ImageUrl
                };
                if (_context.Currencies.FirstOrDefault(c => c.Name == datum.CoinInfo.FullName) == null)
                {
                    _context.Currencies.Add(currency);
                }
            }

            try
            {
                _context.SaveChanges();
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
            }
        }
コード例 #5
0
        public IActionResult DeleteAssetById(int id)
        {
            var asset = context.Assets.Find(id);

            if (asset == null)
            {
                return(NotFound());
            }

            var forks = context.Assets.Where(c => c.Fork.ID == asset.ID).ToList();

            if (forks.Count > 0)
            {
                return(NotFound());
            }

            context.Assets.Remove(asset);
            context.SaveChanges();

            // Default 404 if delete was successful
            return(NoContent());
        }
コード例 #6
0
        public CryptoController(CryptoContext context)
        {
            _context = context;

            if (_context.CryptoItems.Count() == 0)
            {
                // Create new CryptoItems if collection is empty
                _context.CryptoItems.Add(new CryptoItem {
                    Name = "Bitcoin"
                });
                _context.CryptoItems.Add(new CryptoItem {
                    Name = "Ethereum"
                });
                _context.SaveChanges();
            }
        }
コード例 #7
0
        public async Task Import(Guid exchangeId, bool recalculate)
        {
            var exchange     = _context.Exchanges.Find(exchangeId);
            var importer     = GetImporter(exchange.ExchangeId);
            var transactions = await importer.GetTransactions(exchange);

            foreach (var transaction in transactions)
            {
                // Check if already in database and skip
                var row = _context.Transactions.SingleOrDefault(t =>
                                                                t.ExchangeId == exchangeId && t.TransactionKey == transaction.TransactionKey);
                if (row == null)
                {
                    _context.Transactions.Add(transaction);
                    _context.SaveChanges();
                }
            }

            if (recalculate)
            {
                BackgroundJob.Enqueue <Calculator>(c => c.RecalculateAll());
            }
        }
コード例 #8
0
        static void Main(string[] args)
        {
            IWebDriver chromeDriver = new ChromeDriver();

            //string pathToFile = @"C:\Users\jnprogrammer9\Documents\Projects\c#\webScrapper-Selenium\webScrapper-Selenium\webScrapper-Selenium\test.txt";
            string coinName, coinSymbol, coinPrice, coinMarketCap, coinSupply, coinVolume24hr;

            chromeDriver.Navigate().GoToUrl("https://coinmarketcap.com/all/views/all/");
            var table = chromeDriver.FindElement(By.XPath("//table[@id='currencies-all']"));

            try
            {
                // "//table[@id='currencies-all']//tr[@id='id-bitcoin']//td[@class='no-wrap currency-name']//a[@class='currency-name-container']"

                // coinName = chromeDriver.FindElement(By.XPath("//table[@id='currencies-all']//tr/td//a[@class='currency-name-container']")).Text; //$x("//table[@id='currencies-all']//tr[@id='id-bitcoin']")[0]



                // foreach (var row in table.FindElements(By.TagName("tbody")))

                coinName   = chromeDriver.FindElement(By.XPath("//table[@id='currencies-all']//tr/td//a[@class='currency-name-container']")).Text;
                coinSymbol = chromeDriver.FindElement(By.XPath("//table[@id='currencies-all']//tr/td[@class='text-left col-symbol']")).Text;
                coinPrice  = chromeDriver.FindElement(By.XPath("//table[@id='currencies-all']//tr/td//a[@class='price']")).Text;

                // < td class="text-left col-symbol">BTC</td>
                Console.WriteLine(coinName);
                Console.WriteLine(coinSymbol);
                Console.WriteLine(coinPrice);



                using (var db = new CryptoContext())
                {
                    var aCryptoTable = new CryptoTable {
                        CoinName = coinName, CoinSymbol = coinSymbol
                    };
                    db.CryptoTables.Add(aCryptoTable);
                    db.SaveChanges();

                    var query = from b in db.CryptoTables
                                orderby b.CoinName
                                select b;

                    foreach (var item in query)
                    {
                        Console.WriteLine(item.CoinSymbol);
                    }
                }

                /* coinSymbol = chromeDriver.FindElement(By.XPath("")).Text;
                 *                                                                                                                     coinPrice = chromeDriver.FindElement(By.XPath("")).Text;
                 *                                                                                                                                coinMarketCap = chromeDriver.FindElement(By.XPath("")).Text;
                 *                                                                                                                                coinSupply = chromeDriver.FindElement(By.XPath("")).Text;
                 *                                                                                                                                coinVolume24hr = chromeDriver.FindElement(By.XPath("")).Text;*/

                //Console.WriteLine("{0} {1} Price:{2} MarketCap:{3} Supply:{4} 24Hr Volume: {5}\n",coinName,coinSymbol,coinPrice,coinMarketCap,coinSupply,coinVolume24hr);  ////table[@id='currencies-all']//tr[@id='id-bitcoin']
            }
            catch (Exception e)
            {
                Console.WriteLine("Error:" + e);
            }
            chromeDriver.Close();
            Console.WriteLine("No errors thrown");
        }