public async Task <IActionResult> OnPostDeleteCryptoAsync(int?id) { _logger.LogWarning($"OnPost: InvestorId {id}, DROP crypto {CryptoIdToDelete}"); if (id == null) { return(NotFound()); } Investor = await _context.Investor.Include(i => i.InvestorCryptos).ThenInclude(ic => ic.Crypto).FirstOrDefaultAsync(m => m.InvestorId == id); if (Investor == null) { return(NotFound()); } InvestorCrypto cryptoToDrop = _context.InvestorCrypto.Find(CryptoIdToDelete, id.Value); if (cryptoToDrop != null) { _context.Remove(cryptoToDrop); _context.SaveChanges(); } else { _logger.LogWarning("Investor Does Not have this crypto"); } return(RedirectToPage(new { id = id })); //reloads details page of that specific investor }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new PortfolioDbContext(serviceProvider.GetRequiredService <DbContextOptions <PortfolioDbContext> >())) { //look for any investors if (context.Investor.Any()) { return; //DB has been seeded } context.Investor.AddRange( new Investor { FirstName = "Aaron", LastName = "Phillips" }, new Investor { FirstName = "Walter", LastName = "White" }, new Investor { FirstName = "Mark", LastName = "Cuban" } ); context.SaveChanges(); if (context.Crypto.Any()) { return; } context.Crypto.AddRange( new Crypto { Name = "BitCoin", Ticker = "BTC", Price = 54792.00M, Volatility = "Low" }, new Crypto { Name = "Ethereum", Ticker = "ETH", Price = 2009.00M, Volatility = "Low" }, new Crypto { Name = "DogeCoin", Ticker = "Doge", Price = 0.37967M, Volatility = "High" }, new Crypto { Name = "LiteCoin", Ticker = "LTC", Price = 250.50M, Volatility = "Medium" }, new Crypto { Name = "BinanceCoin", Ticker = "BNB", Price = 488.38M, Volatility = "Medium" }, new Crypto { Name = "Ripple", Ticker = "XRP", Price = 1.24M, Volatility = "High" }, new Crypto { Name = "Tether", Ticker = "USDT", Price = 1.00M, Volatility = "High" }, new Crypto { Name = "Cardano", Ticker = "ADA", Price = 1.15M, Volatility = "Medium" }, new Crypto { Name = "Polkadot", Ticker = "DOT", Price = 34.05M, Volatility = "Medium" }, new Crypto { Name = "Vechain", Ticker = "VET", Price = 0.2418M, Volatility = "High" }, new Crypto { Name = "UniSwap", Ticker = "UNI", Price = 30.08M, Volatility = "High" }, new Crypto { Name = "Chainlink", Ticker = "LINK", Price = 36.67M, Volatility = "Medium" }, new Crypto { Name = "Stellar", Ticker = "XLM", Price = 0.4973M, Volatility = "Medium" }, new Crypto { Name = "Theta Network", Ticker = "THETA", Price = 10.69M, Volatility = "High" }, new Crypto { Name = "Solana", Ticker = "SOL", Price = 39.78M, Volatility = "High" }, new Crypto { Name = "Filecoin", Ticker = "FIL", Price = 146.86M, Volatility = "High" }, new Crypto { Name = "Tron", Ticker = "TRX", Price = 0.111M, Volatility = "Medium" }, new Crypto { Name = "IOTA", Ticker = "MIOTA", Price = 1.84M, Volatility = "High" }, new Crypto { Name = "Aave", Ticker = "AAVE", Price = 363.24M, Volatility = "Low" }, new Crypto { Name = "Cosmos", Ticker = "ATOM", Price = 18.99M, Volatility = "High" }, new Crypto { Name = "Ethereum Classic", Ticker = "ETC", Price = 34.46M, Volatility = "Low" }, new Crypto { Name = "Tezos", Ticker = "XTZ", Price = 5.00M, Volatility = "Medium" }, new Crypto { Name = "Siacoin", Ticker = "SC", Price = 0.036M, Volatility = "Medium" }, new Crypto { Name = "Decentraland", Ticker = "MANA", Price = 1.23M, Volatility = "High" }, new Crypto { Name = "Enjin Coin", Ticker = "ENJ", Price = 2.23M, Volatility = "High" } ); // 25 cryptos ready for a possible crytpo page to support paging. context.SaveChanges(); } }