Beispiel #1
0
        public void BuyStock(Stock s)
        {
            decimal? amount = s.DayValue * s.Quantity;
            if (amount == null)
                throw new ArgumentException("Stock must have a valid quantity and value : " + s, "s");
            if (amount > mRemain)
                throw new ArgumentException("Balance Remaining must be greater than the cost of the Stock " + s.Name, "s");

            Remaining -= amount.Value;
            mStocks.Add(s);
            Worth += amount.Value;
        }
Beispiel #2
0
        public void SellStock(Stock s, decimal qty)
        {
            var walletStock = mStocks.FirstOrDefault(stock => stock.ID == s.ID);
            if (walletStock == null)
                throw new ArgumentException("Cannot sell Stock " + s.Name + ": It is not in the wallet!", "s");
            if (qty > walletStock.Quantity)
                throw new ArgumentException("Cannot sell " + qty + " of Stock " + s.Name + " as there is only " + walletStock.Quantity + " in the wallet.", "qty");

            var amount = qty * s.DayValue;
            walletStock.Quantity -= qty;
            Worth -= amount;
            Remaining += amount;

            if (walletStock.Quantity == 0)
                mStocks.Remove(s);
        }