Ejemplo n.º 1
0
        private void RefreshTable()
        {
            _listViewStocks.Items.Clear();

            double total = 0;
            double gain  = 0;

            foreach (Stock stock in _stockModel.EnumerateStocks())
            {
                var price = new StockPriceLoader().Load(stock.Ticker);

                var stockTotalPrice = stock.GetTotalPrice(price);
                var stockGain       = stock.GetGain(price);
                var listViewItem    = CreateListViewItem(stock.Ticker, price, stock.Shares, stockTotalPrice,
                                                         stockGain);
                _listViewStocks.Items.Add(listViewItem);

                total += stockTotalPrice;
                gain  += stockGain;
            }


            var listViewItemLine = CreateListViewItem("------", "-", "-", "-");

            _listViewStocks.Items.Add(listViewItemLine);

            var listViewItemTotal = CreateListViewItem("Total", "-", "-", total, gain);

            _listViewStocks.Items.Add(listViewItemTotal);
        }
        private static IEnumerable <M_StockWithPrice> AddPriceToStock(StockCollection stockCollection)
        {
            StockPriceLoader stockPriceLoader = new StockPriceLoader();

            return(stockCollection.EnumerateStocks()
                   .Select(stock => new M_StockWithPrice()
            {
                Stock = stock, Price = stockPriceLoader.Load(stock.Ticker)
            }));
        }
Ejemplo n.º 3
0
 public GainModel(StockPriceLoader stockPriceLoader)
 {
     _stockPriceLoader = stockPriceLoader;
 }