public user homescreen(user User)
        {
            // Initiatize variables
            List <string> acctTypes = new List <string> {
                "Checking", "Savings"
            };
            int acctSelection = 1;

            Console.WriteLine();

            bool accountSelected = false;

            while (!accountSelected && User.loggedIn)
            {
                Console.Clear();
                Console.WriteLine();
                Console.WriteLine("Which account would you like to work with?");
                Console.WriteLine();
                Console.WriteLine("X Logout");
                Console.WriteLine("0 Add a new account");
                foreach (account acct in User.accounts)
                {
                    Console.WriteLine(acct.acctID + " " + acct.name + " " + acctTypes[acct.acctType - 1]);
                }
                try
                {
                    Console.WriteLine();
                    string acctSelectionString = Console.ReadLine();
                    if (acctSelectionString == "X" || acctSelectionString == "x")
                    {
                        User.loggedIn = false;
                    }
                    else
                    {
                        acctSelection = Convert.ToInt16(acctSelectionString);
                        Console.WriteLine();
                        if (acctSelection == 0)
                        {
                            createAccount acctCreator = new createAccount();
                            // method will update user with a newly created account in the user object.
                            User          = acctCreator.newAccount(User);
                            acctSelection = User.accounts.Count;
                        }
                        else if (acctSelection > 0 && acctSelection <= User.accounts.Count)
                        {
                            accountSelected = true;
                        }
                        else
                        {
                            Console.WriteLine();
                            Console.WriteLine("Sorry, try again.");
                            Console.WriteLine();
                        }
                    }
                }
                catch
                {
                    Console.WriteLine();
                    Console.WriteLine("Sorry, try again.");
                    Console.WriteLine();
                }
            }


            // Account is selected. Loop until user done with this account.
            bool moreWithThisAcct = true;

            while (moreWithThisAcct && User.loggedIn)
            {
                Console.Clear();
                Console.WriteLine();
                Console.WriteLine("What shall we do with {0} {1}?", User.accounts[acctSelection - 1].name, acctTypes[User.accounts[acctSelection - 1].acctType - 1]);
                Console.WriteLine();
                Console.WriteLine("1 -- Record deposit");
                Console.WriteLine("2 -- Record withdrawal");
                Console.WriteLine("3 -- Check balance");
                Console.WriteLine("4 -- See transaction history");
                Console.WriteLine("5 -- Done with this account");
                Console.WriteLine();
                string userSelection = Console.ReadLine();
                Console.WriteLine();

                if (userSelection == "1")
                {
                    Console.WriteLine("How much did you deposit?");
                    float transAmount = 0;
                    try
                    {
                        transAmount = Convert.ToSingle(Console.ReadLine());
                        Console.WriteLine();
                        Console.WriteLine("Enter a note for this transaction. (optional)");
                        string transactNote   = Console.ReadLine();
                        int    nextTransactID = User.accounts[acctSelection - 1].transactions.Count + 1;
                        User.accounts[acctSelection - 1].transactions.Add(new transaction
                        {
                            transactID = nextTransactID,
                            date       = DateTime.Now,
                            amount     = transAmount,
                            notes      = transactNote
                        });
                        Console.WriteLine();
                    }
                    catch
                    {
                        Console.WriteLine("Sorry, your input was of the wrong format.");
                        Console.ReadLine();
                    }
                    Console.WriteLine("Press Enter to continue.");
                    Console.ReadLine();
                }
                if (userSelection == "2")
                {
                    Console.WriteLine("How much did you withdraw?");
                    float transAmount = Convert.ToSingle(Console.ReadLine());
                    Console.WriteLine();
                    Console.WriteLine("Enter a note for this transaction. (optional)");
                    string transactNote   = Console.ReadLine();
                    int    nextTransactID = User.accounts[acctSelection - 1].transactions.Count + 1;
                    User.accounts[acctSelection - 1].transactions.Add(new transaction
                    {
                        transactID = nextTransactID,
                        date       = DateTime.Now,
                        amount     = -transAmount,
                        notes      = transactNote
                    });
                    Console.WriteLine();
                    Console.WriteLine("Press Enter to continue.");
                    Console.ReadLine();
                }
                if (userSelection == "3")
                {
                    float balance = 0;
                    for (int i = 0; i < User.accounts[acctSelection - 1].transactions.Count; i++)
                    {
                        balance += User.accounts[acctSelection - 1].transactions[i].amount;
                    }
                    Console.Clear();
                    Console.WriteLine();
                    Console.WriteLine("Balance for account #" + acctSelection + " " + User.accounts[acctSelection - 1].name + " " + acctTypes[User.accounts[acctSelection - 1].acctType - 1] + ": " + balance);
                    Console.WriteLine();
                    Console.WriteLine("Press Enter to continue.");
                    Console.ReadLine();
                }
                if (userSelection == "4")
                {
                    float balance = 0;
                    Console.Clear();
                    Console.WriteLine();
                    Console.WriteLine("Transaction history for " + User.accounts[acctSelection - 1].name + " " + acctTypes[User.accounts[acctSelection - 1].acctType - 1] + ";");
                    Console.WriteLine();
                    Console.WriteLine("Date      Deposit      Withdrawal        Balance ");
                    Console.WriteLine();
                    for (int i = 0; i < User.accounts[acctSelection - 1].transactions.Count; i++)
                    {
                        balance += User.accounts[acctSelection - 1].transactions[i].amount;
                        string d;
                        if (User.accounts[acctSelection - 1].transactions[i].amount < 0)
                        {
                            d = Convert.ToDateTime(User.accounts[acctSelection - 1].transactions[i].date).Date.ToString("d");
                            Console.WriteLine(d + "                   (" + -User.accounts[acctSelection - 1].transactions[i].amount + ")           " + balance + "  " + User.accounts[acctSelection - 1].transactions[i].notes);
                        }
                        else
                        {
                            d = Convert.ToDateTime(User.accounts[acctSelection - 1].transactions[i].date).Date.ToString("d");
                            Console.WriteLine(d + "    " + User.accounts[acctSelection - 1].transactions[i].amount + "                    " + "        " + balance + "  " + User.accounts[acctSelection - 1].transactions[i].notes);
                        }
                        Console.WriteLine();
                    }
                    Console.WriteLine();
                    Console.WriteLine("Press Enter to continue.");
                    Console.ReadLine();
                }
                if (userSelection == "5")
                {
                    moreWithThisAcct = false;
                }
            }                          // end of loop to work with account
            return(User);
        }
Example #2
0
        static void Main(string[] args)
        {
            // Instantiate users
            var BobSmithCheckingTransaction1 = new transaction
            {
                transactID = 1,
                date       = new DateTime(2018, 7, 15),
                amount     = 3000,
                notes      = "Initial cash deposit"
            };
            var BobSmithCheckingTransaction2 = new transaction
            {
                transactID = 1,
                date       = new DateTime(2018, 7, 16),
                amount     = -2711,
                notes      = "Bought candy at candy store"
            };
            var BobSmithChecking = new account
            {
                acctID       = 1,
                name         = "Main",
                acctType     = 1,
                transactions = new List <transaction> {
                    BobSmithCheckingTransaction1, BobSmithCheckingTransaction2
                },
            };
            var BobSmithSavingsTransaction1 = new transaction
            {
                transactID = 1,
                date       = new DateTime(2018, 7, 14),
                amount     = 1,
                notes      = "Initial cash deposit"
            };
            var BobSmithSavings = new account
            {
                acctID       = 2,
                name         = "Main",
                acctType     = 2,
                transactions = new List <transaction> {
                    BobSmithSavingsTransaction1
                },
            };
            user bobS = new user()
            {
                userName  = "******",
                userId    = 0,
                email     = "*****@*****.**",
                firstName = "Bob",
                lastName  = "Smith",
                password  = "******",
                accounts  = new List <account> {
                    BobSmithChecking, BobSmithSavings
                },
            };
            var SamTomCheckingTransaction1 = new transaction
            {
                transactID = 1,
                date       = new DateTime(2018, 7, 14),
                amount     = 4000,
                notes      = "Initial cash deposit"
            };
            var SamTomChecking = new account
            {
                acctID       = 1,
                name         = "Normal",
                acctType     = 1,
                transactions = new List <transaction> {
                    SamTomCheckingTransaction1
                },
            };
            user samT = new user()
            {
                userName  = "******",
                userId    = 1,
                email     = "*****@*****.**",
                firstName = "Sam",
                lastName  = "Tom",
                password  = "******",
                accounts  = new List <account> {
                    SamTomChecking
                },
            };
            var userList = new List <user> {
                bobS, samT
            };


            // Instantiate login object
            logIn establishUser = new logIn();


            // Startup screen

            string logInOrRegister;

            Console.WriteLine();

            bool programRunning = true;

            while (programRunning)
            {
                // Start of login procedure
                user currentUser  = null;
                bool loginSuccess = false;
                while (!loginSuccess)
                {
                    Console.Clear();
                    Console.WriteLine();
                    Console.WriteLine("Welcome to the World's Greatest Banking Ledger!");
                    Console.WriteLine();
                    Console.WriteLine("Please choose one of the following:");
                    Console.WriteLine("1  --  Login");
                    Console.WriteLine("2  --  Register (new user)");
                    Console.WriteLine("3  --  Exit");
                    Console.WriteLine();
                    logInOrRegister = Console.ReadLine();
                    Console.WriteLine();
                    try
                    {
                        if (logInOrRegister == "1")
                        {
                            while (currentUser == null)
                            {
                                currentUser = establishUser.login(userList);
                            }
                            if (currentUser.userName != "failedLogin")
                            {
                                Console.WriteLine("Welcome back, {0}", currentUser.firstName);
                                loginSuccess = true;
                            }
                        }
                        else if (logInOrRegister == "2")
                        {
                            int userCount = userList.Count;
                            userList = establishUser.register(userList);
                            if (userCount + 1 == userList.Count)
                            {
                                int newestUser = userList.Count - 1;
                                currentUser  = userList[newestUser];
                                loginSuccess = true;
                            }
                        }
                        else if (logInOrRegister == "3")
                        {
                            Console.WriteLine("Okay. Goodbye!");
                            Console.ReadKey();
                            return;
                        }
                    }
                    catch
                    {
                    }
                }



                // User logged in, going to home screen
                currentUser.loggedIn = true;
                while (currentUser.loggedIn)
                {
                    homeScreen currentCycle = new homeScreen();

                    // for new users with no accounts
                    if (currentUser.accounts.Count == 0)
                    {
                        createAccount acctCreator = new createAccount();
                        // method will update user with a newly created account in the user object.
                        currentUser = acctCreator.newAccount(currentUser);
                    }

                    currentUser = currentCycle.homescreen(currentUser);
                    //updates list item
                    userList[currentUser.userId] = currentUser;
                    Console.Clear();
                    Console.WriteLine();
                    //Console.WriteLine("Could I do something else for you? (\"n\" to logout)");
                    //Console.WriteLine();
                    //string moreAnswer = Console.ReadLine();
                    //Console.WriteLine();
                    //if (moreAnswer == "n" || moreAnswer == "no" || moreAnswer == "N" || moreAnswer == "NO" || moreAnswer == "No")
                    //{
                    //    Console.WriteLine("Okay! Thanks for using the World's Greatest Banking Ledger!");
                    //    Console.WriteLine();
                    //    Console.ReadLine();
                    //    Console.Clear();
                    //    moreTransactions = false;
                }
            }



            Console.WriteLine("That's all folks!");
            Console.ReadLine();
        }