Beispiel #1
0
        private MenuOptionResult ViewRequests()
        {
            List <Transfer> userTransfers = apiService.GetUserTransfers();

            Console.WriteLine("Pending Requests");
            Console.WriteLine("-------------------------------------------");
            foreach (Transfer tran in userTransfers)
            {
                if (tran.AccountTo == UserService.GetUserId() && tran.TransferStatusId == 1)
                {
                    Console.WriteLine($"Transfer ID:{tran.TransferId}\tTo:{tran.UsernameFrom}\tAmount:{tran.Amount:C}");
                }
            }
            Console.WriteLine("-------------------------------------------");

            //Ask for user input of Transfer ID
            Console.Write("Please input the Transfer ID you would like to Approve/Reject: ");

            //Read user input for Transfer ID
            Int32.TryParse(Console.ReadLine(), out int transferId);
            Console.WriteLine("Approve/Reject Transfer");
            Console.WriteLine("-------------------------------------------");
            Console.WriteLine("1: Approve");
            Console.WriteLine("2: Reject");
            Console.WriteLine("0: Don't approve or reject");
            Console.WriteLine("-------------------------------------------");
            Console.Write("Please input an option: ");
            Int32.TryParse(Console.ReadLine(), out int userSelection);

            //If 1, Get transfer via GetUserTransfers, update transfer type ID to 1, update transfer status to 1
            if (userSelection == 1)
            {
                List <Transfer> transferList       = apiService.GetUserTransfers();
                List <Transfer> userInputTransfers = new List <Transfer>();
                foreach (Transfer tran in transferList.ToList())
                {
                    if (tran.TransferId == transferId)
                    {
                        userInputTransfers.Add(tran);
                    }
                }
                Transfer transferToUpdate = userInputTransfers[0];

                if (apiService.GetAccount().Balance >= transferToUpdate.Amount)
                {
                    transferToUpdate.TransferStatusId = 2;

                    //Update transfers log
                    apiService.UpdateTransfer(transferToUpdate.TransferId, transferToUpdate.AccountFrom, transferToUpdate.Amount, userSelection);

                    //Send approved funds
                    apiService.ApproveTransfer(transferToUpdate.AccountTo, transferToUpdate.Amount);
                    Console.WriteLine("Transfer Approval is complete! \n");
                }
                else
                {
                    Console.WriteLine("Transfer Approval Denied: Insufficient Funds \n");
                }
            }
            //If 2, update transfer status to 3
            else if (userSelection == 2)
            {
                List <Transfer> transferList       = apiService.GetUserTransfers();
                List <Transfer> userInputTransfers = new List <Transfer>();
                foreach (Transfer tran in transferList.ToList())
                {
                    if (tran.TransferId == transferId)
                    {
                        userInputTransfers.Add(tran);
                    }
                }
                Transfer transferToUpdate = userInputTransfers[0];

                transferToUpdate.TransferStatusId = 3;

                //Update transfers log
                apiService.UpdateTransfer(transferToUpdate.TransferId, transferToUpdate.AccountFrom, transferToUpdate.Amount, userSelection);

                Console.WriteLine("Transfer request has been rejected! Get that weak stuff outta here! \n");
            }

            //If 0, return to main menu
            else
            {
                Console.WriteLine("It's ok. We're indecisive too.\n");
            }

            Console.WriteLine("Press any key to return to main menu");

            return(MenuOptionResult.WaitAfterMenuSelection);
        }