public PlayerViewModel(Investment investment, Quote latestQuote, Player player) { Name = player.Name; Description = player.Description; Symbol = investment.Symbol; CompanyName = latestQuote.Name; CurrentPrice = latestQuote.LastTradePrice.Value / 100; PurchasePrice = investment.PurchasePrice / 100; PurchasedOn = investment.PurchaseDate; ShareQuantity = investment.Quantity; PercentageChange = (double) ((CurrentPrice - PurchasePrice) / PurchasePrice); }
/// <summary> /// /// </summary> /// <param name="player"></param> /// <param name="quote"></param> /// <param name="walletSize">The size of your wallet, in £</param> public void InitializePlayer(Player player, Quote quote, decimal walletSize) { walletSize *= 100; int quantity = (int)(walletSize / quote.LastTradePrice.Value); Investment investment = new Investment() { Id = Guid.NewGuid(), PlayerName = player.GetType().Name, PurchaseDate = DateTime.Now, PurchasePrice = quote.LastTradePrice.Value, Quantity = quantity, Symbol = quote.Symbol }; using (DbConnection connection = Db.CreateConnection()) { connection.Open(); connection.Insert<Investment>(investment); Log.Information("Initialized {0} with symbol {1}", investment.PlayerName, investment.Symbol); } }