Example #1
0
        public void BuyStocks()
        {
            StocksAndBonds temp = new StocksAndBonds();

            Console.WriteLine("Number of stocks: {0}", temp.Stock.Values.Count());
            foreach (KeyValuePair <string, StocksAndBonds.InfoStocks> v in temp.Stock)
            {
                Console.WriteLine("ID: {0} | Name: {1} | Current: {2}$ | Rise per day: {3} ", v.Value.Id, v.Value.Name, v.Value.Current, v.Value.RisePerDay);
            }
            Console.WriteLine("Write ID of Stocks, which would you buy");
            string reqOfBuyStr = Console.ReadLine();
            int    reqOfBuy    = Convert.ToInt32(reqOfBuyStr);

            if (reqOfBuyStr == "" || (reqOfBuy < 0 || reqOfBuy > 100))
            {
                Console.WriteLine("You entered incorrect data");
            }
            else
            {
                string reqOfBuyString = Convert.ToString(reqOfBuy);
                if (!temp.Stock.ContainsKey(reqOfBuyString))
                {
                    Console.WriteLine("THIS ID DIDN'T EXIST ({0})", reqOfBuy);
                }
                else
                {
                    Console.WriteLine("Write your personal ID of Bank account");
                    int id = Convert.ToInt32(Console.ReadLine());
                    if (people.Exists(x => x.IdBankAccount == id))
                    {
                        if (reqOfBuy == temp.Stock[reqOfBuyString].Id)
                        {
                            Person idUser = people.Find(x => x.IdBankAccount == id);
                            if (idUser.Money >= temp.Stock[reqOfBuyString].Current)
                            {
                                idUser.Money = idUser.Money - temp.Stock[reqOfBuyString].Current;
                                idUser.StonksInventory.Add(temp.Stock[reqOfBuyString]);
                                Console.WriteLine("You successfully bought stocks");
                            }
                            else
                            {
                                Console.WriteLine("you don't have such money in your account");
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("We didn't find your ID");
                    }
                }
            }
        }
Example #2
0
        public void SoldStocks()
        {
            Console.WriteLine("Write your personal ID of Bank account");
            string id    = Console.ReadLine();
            int    idInt = Convert.ToInt32(id);

            ShowPersonalStocks(id);
            Console.WriteLine("Write ID of stocks which would you sold");
            string         soldIdStr = Console.ReadLine();
            int            soldId    = Convert.ToInt32(soldIdStr);
            Person         idUser    = people.Find(x => x.IdBankAccount == idInt);
            StocksAndBonds temp      = new StocksAndBonds();

            idUser.Money = idUser.Money + temp.Stock[soldIdStr].Current;
            StocksAndBonds.InfoStocks soldIt = idUser.StonksInventory.Find(x => x.Id == soldId);
            idUser.StonksInventory.Remove(soldIt);
            ShowPersonalStocks(id);
            Console.WriteLine("You successfully sold stocks");
        }