public void AddStockInList()
        {
            try
            {
                Stock newstock = new Stock();
                newstock.Price       = Convert.ToDouble(NewStockPrice);
                newstock.Quantity    = Convert.ToInt64(NewStockQuantity);
                newstock.StockType   = IsEquitySelected ? StockEnum.Equity : StockEnum.Bond;
                newstock.StockName   = GenerateStockName(newstock.StockType);
                newstock.StockWeight = CalculateStockWeight(newstock.MarketValue);
                AllStocks.Add(newstock);

                /* After stock is added , Panel to add new stock is hidden,
                 * Price and Quantity Textboxes are reset
                 * Equity and Bond type checkboxes are also reset */
                NewStockVisibility = Visibility.Hidden;
                IsEquitySelected   = false;
                IsBondSelected     = false;
                NewStockPrice      = null;
                NewStockQuantity   = null;
                NotifyPropertyChanged("NewStockVisibility");
                NotifyPropertyChanged("StocksValue");
                NotifyPropertyChanged("NewStockPrice");
                NotifyPropertyChanged("NewStockQuantity");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public double CalculateStockWeight(double marketValue)
        {
            /* stock weight as Market Value percentage of the Total Market Value of the Fund
             * (assuming Total Market Value of the Fund is the total market value of ALL funds of User)*/
            double totalMarketValue = AllStocks.Sum(c => c.MarketValue);

            return((marketValue / 100) * totalMarketValue);
        }
        public string GenerateStockName(StockEnum stocktype)
        {
            // Stock Name gets generated from the number of occurrences of that Stock Type

            int count = AllStocks.Where(c => c.StockType == stocktype).Count();

            return((stocktype == StockEnum.Equity ? "Equity" : "Bond") + (count + 1).ToString());
        }
Exemplo n.º 4
0
 private void GetAllStocksCallback(IEnumerable <Stock> allStocks)
 {
     AllStocks.Clear();
     foreach (Stock stock in allStocks)
     {
         AllStocks.Add(stock);
     }
 }
Exemplo n.º 5
0
        protected override async Task InitialDictionaryLoad()
        {
            try
            {
                using (SqlConnection _conn = new SqlConnection(_connectionString))
                {
                    string ogCommand = _commandText;

                    using (SqlCommand _cmd = new SqlCommand($"EXEC [dbo].[ExecuteOpenGateQuery] @conString = N'{_ogConnectionString}', @sql = N'{ogCommand}', @parameters = NULL",
                                                            _conn))
                    {
                        await _conn.OpenAsync();

                        _cmd.CommandTimeout = 100000;
                        using (var reader = await _cmd.ExecuteReaderAsync())
                        {
                            while (await reader.ReadAsync())
                            {
                                var stock = Stock.BuildModel(reader);
                                AllStocks.TryAdd(stock.StockID, stock);
                            }
                        }
                    }
                }
                var tracked = await dBContext.TrackedStocks.ToListAsync();

                foreach (var trackedStock in tracked)
                {
                    if (AllStocks.TryGetValue(trackedStock.StockID, out var stock))
                    {
                        TrackedStocks.TryAdd(stock.StockID, stock);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogCritical($"{nameof(ex)}: {ex.Message}");
            }
        }