Esempio n. 1
0
 public void BuyStock(Stock stock)
 {
     if (Portfolio.Any(x => x.Name == stock.Name))
     {
         return;
     }
     if (stock.MarketCapitalization <= 10000)
     {
         return;
     }
     if (stock.PricePerShare > MoneyToInvest)
     {
         return;
     }
     Portfolio.Add(stock);
     MoneyToInvest -= stock.PricePerShare;
 }
Esempio n. 2
0
 public string SellStock(string companyName, decimal sellPrice)
 {
     if (Portfolio.Any(x => x.Name == companyName))
     {
         Stock currentStock = Portfolio.Where(x => x.Name == companyName).FirstOrDefault();
         if (sellPrice < currentStock.PricePerShare)
         {
             return($"Cannot sell {companyName}.");
         }
         else
         {
             Portfolio.Remove(currentStock);
             MoneyToInvest += sellPrice;
             return($"{companyName} was sold.");
         }
     }
     else
     {
         return($"{companyName} does not exist.");
     }
 }