public async Task <ActionResult> InsertInvestor([FromBody] InvestorViewModel viewModel)
        {
            try
            {
                var investor = new Investor(viewModel);
                var invCnt   = dbContext.Investors.Count();
                dbContext.Investors.Add(investor);
                var usd = dbContext.Assets.FirstOrDefault(a => a.Name == "USD");
                if (usd != null)
                {
                    usd.Quantity += investor.AmountInvested;
                    dbContext.Assets.Update(usd);

                    if (invCnt == 0)
                    {
                        var time = DateTime.Now;
                        var nav  = new NavHistory
                        {
                            Date  = time,
                            Value = usd.Quantity / investor.SharesReceived
                        };

                        var rate = await coinApi.GetCurrencyRateToUsd("BTC");

                        var btc = new BtcHistory
                        {
                            Date  = time,
                            Value = rate.Rate
                        };

                        dbContext.NavHistories.Add(nav);
                        dbContext.BtcHistories.Add(btc);

                        //if (!dbContext.Assets.ToList().Exists(a => a.ShortName == "BTC"))
                        //{
                        //    try
                        //    {
                        //        var rate = await coinApi.GetCurrencyRateToUsd("BTC");
                        //        var currency = dbContext.Currencies.FirstOrDefault(c => c.ShortName == "BTC");
                        //        if (currency != null)
                        //        {
                        //            currency.Rate = rate.Rate;
                        //            dbContext.Currencies.Update(currency);
                        //        }
                        //        dbContext.CurrencyRates.Add(rate);
                        //    }
                        //    catch (Exception e)
                        //    {
                        //        Console.WriteLine(e);
                        //    }
                        //}
                    }
                }

                dbContext.SaveChanges();
                return(this.Json(new MetaResponse <object> {
                    StatusCode = 200
                }));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(this.Json(new MetaResponse <object> {
                    StatusCode = 200
                }));
            }
        }
        private async Task UpdateDatabase()
        {
            using (var scope = _scopeFactory.CreateScope())
            {
                var coinApi   = new CoinApi(_configuration);
                var dbContext = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>();

                var navs = dbContext.NavHistories.ToList();

                if (navs.Count > 0)
                {
                    var latestNav = navs.Last();
                    var timeDiff  = latestNav.Date - DateTime.Now;
                    if (Math.Abs(timeDiff.Hours) < 3)
                    {
                        return;
                    }
                }

                var assets    = dbContext.Assets.ToList();
                var investors = await dbContext.Investors.ToListAsync();

                if (investors.Count == 0)
                {
                    return;
                }

                var sum         = assets.Sum(a => a.Price * a.Quantity);
                var totalShares = investors.Sum(investor => investor.SharesReceived);
                var time        = DateTime.Now;


                var nav = new NavHistory
                {
                    Date  = time,
                    Value = sum / totalShares
                };

                var rate = await coinApi.GetCurrencyRateToUsd("BTC");

                var btc = new BtcHistory
                {
                    Date  = time,
                    Value = rate.Rate
                };

                dbContext.NavHistories.Add(nav);
                dbContext.BtcHistories.Add(btc);
                dbContext.SaveChanges();

                //if (!assets.Exists(a => a.ShortName == "BTC"))
                //{
                //    try
                //    {


                //        var currency = dbContext.Currencies.FirstOrDefault(c => c.ShortName == "BTC");
                //        if (currency != null)
                //        {
                //            currency.Rate = rate.Rate;
                //            dbContext.Currencies.Update(currency);
                //        }
                //        dbContext.CurrencyRates.Add(rate);
                //    }
                //    catch (Exception e)
                //    {
                //        Console.WriteLine(e);
                //    }
                //}
            }
        }