コード例 #1
0
        private MenuOptionResult SendTEBucks()
        {
            //Creates new transfer object (defaults status to approved and type to sent)
            Transfer newTransfer = new Transfer();

            newTransfer.TransferStatusID = 2;
            newTransfer.TransferTypeID   = 2;

            UserApiDao u = new UserApiDao(API_BASE_URL, User);

            List <API_User>            names = u.GetUsers();
            Dictionary <int, API_User> users = consoleServices.NamesToDiction(names);

            //User selects recipient
            UserSelectionMenu selectMenu = new UserSelectionMenu(users, User.Username, this, newTransfer.TransferTypeID);

            selectMenu.Show();

            if (selectionId == 0)
            {
                return(MenuOptionResult.DoNotWaitAfterMenuSelection);
            }

            newTransfer.AccountTo.AccountId = selectionId;

            //User selects which balance to send from
            AccountApiDao  acc  = new AccountApiDao(API_BASE_URL, User);
            List <Account> list = acc.GetAccounts();

            AccountSelectionMenu acctSelect = new AccountSelectionMenu(list, this, newTransfer.TransferTypeID);

            acctSelect.Show();

            if (acctSelection == null)
            {
                return(MenuOptionResult.DoNotWaitAfterMenuSelection);
            }

            newTransfer.AccountFrom = acctSelection;

            //User input amount of TE Bucks to send
            consoleServices.PrintBalance(acctSelection);
            decimal amount = GetDecimal("\nEnter amount to transfer: ", 0);

            while (amount > acctSelection.Balance || amount <= 0)
            {
                if (amount < 0)
                {
                    consoleServices.ErrorMessage();
                }
                else if (amount == 0)
                {
                    Console.WriteLine("Transfer Cancelled");
                    return(MenuOptionResult.WaitAfterMenuSelection);
                }
                else if (amount > acctSelection.Balance)
                {
                    Console.WriteLine("Error: Attempt to overdraft");
                }

                amount = GetDecimal("\nEnter amount to transfer: ");
            }

            newTransfer.Amount = amount;

            TransferApiDao trans  = new TransferApiDao(API_BASE_URL, User);
            decimal        newBal = trans.TransferMoney(newTransfer);

            consoleServices.TransferComplete(newBal);

            return(MenuOptionResult.WaitAfterMenuSelection);
        }
コード例 #2
0
        private MenuOptionResult RequestTEBucks()
        {
            Transfer newTransfer = new Transfer();

            newTransfer.TransferStatusID = 1;
            newTransfer.TransferTypeID   = 1;

            UserApiDao u = new UserApiDao(API_BASE_URL, User);

            List <API_User>            names = u.GetUsers();
            Dictionary <int, API_User> users = consoleServices.NamesToDiction(names);

            //User selects recipient
            UserSelectionMenu selectMenu = new UserSelectionMenu(users, User.Username, this, newTransfer.TransferTypeID);

            selectMenu.Show();

            if (selectionId == 0)
            {
                return(MenuOptionResult.DoNotWaitAfterMenuSelection);
            }

            newTransfer.AccountFrom.AccountId = selectionId;

            //User selects which account to send to
            AccountApiDao  acc  = new AccountApiDao(API_BASE_URL, User);
            List <Account> list = acc.GetAccounts();

            AccountSelectionMenu acctSelect = new AccountSelectionMenu(list, this, newTransfer.TransferTypeID);

            acctSelect.Show();

            if (acctSelection == null)
            {
                return(MenuOptionResult.DoNotWaitAfterMenuSelection);
            }

            newTransfer.AccountTo = acctSelection;

            //User input amount of TE Bucks to send
            Decimal amount = GetDecimal("\nEnter amount to request: ", 0);

            while (amount <= 0)
            {
                if (amount < 0)
                {
                    consoleServices.ErrorMessage();
                }
                else if (amount == 0)
                {
                    Console.WriteLine("Transfer Cancelled");
                    return(MenuOptionResult.WaitAfterMenuSelection);
                }
                amount = GetDecimal("\nEnter amount to transfer: ");
            }

            newTransfer.Amount = amount;

            TransferApiDao trans = new TransferApiDao(API_BASE_URL, User);
            int            newId = (int)trans.TransferMoney(newTransfer);

            consoleServices.TransferRequest(newId);

            return(MenuOptionResult.WaitAfterMenuSelection);
        }