Ejemplo n.º 1
0
        /// <summary>
        /// Sells the specified symbol.
        /// </summary>
        /// <param name="symbol">The symbol.</param>
        public void Sell(string symbol)
        {
            List <CompanyShares> companySharesList = CommercialUtility.ReadFromFile();

            foreach (CompanyShares companyShares in companySharesList)
            {
                if (companyShares.Symbol.Equals(symbol))
                {
                    companySharesList.Remove(companyShares);
                    Console.WriteLine("Share with Symbol " + symbol + "removed");
                    CommercialUtility.WriteToFile(companySharesList);
                    return;
                }
            }

            Console.WriteLine("stock with Symbol " + symbol + "does not exist");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Buys the specified number of shares.
        /// </summary>
        /// <param name="numberOfShares">The number of shares.</param>
        /// <param name="price">The price.</param>
        /// <param name="symbol">The symbol.</param>
        public void Buy(long numberOfShares, double price, string symbol)
        {
            List <CompanyShares> companySharesList = CommercialUtility.ReadFromFile();

            foreach (CompanyShares shares in companySharesList)
            {
                if (shares.Symbol.Equals(symbol))
                {
                    Console.WriteLine("You have already bought this share with symbol " + symbol);
                    return;
                }
            }

            string        dateTime      = DateTime.Now.ToString();
            CompanyShares companyShares = new CompanyShares(numberOfShares, price, symbol, dateTime);

            companySharesList.Add(companyShares);

            CommercialUtility.WriteToFile(companySharesList);
        }