public API_Transfer RequestTransfer(List <API_User> users)
        {
            int selection = -1;

            while (selection != 0)
            {
                Console.WriteLine("-------------------------------------");
                Console.WriteLine("Users");
                Console.WriteLine("ID\t \tName");
                Console.WriteLine("-------------------------------------");
                foreach (API_User user in users)
                {
                    Console.WriteLine($"{user.UserId}:\t \t{user.Username}");
                }
                API_Transfer transfer = new API_Transfer()
                {
                    UserFromID       = RequestedUserForTransfer(users),
                    UserToID         = UserService.GetUserId(),
                    TransferAmount   = AmountToTransfer(),
                    TransferStatusID = 1, //Request transfers default to pending untill approved
                    TransferTypeID   = 1
                };
                return(transfer);
            }
            return(null);
        }
        public API_Transfer StartTransfer(List <API_User> users)
        {
            int selection = -1;

            while (selection != 0)
            {
                Console.WriteLine("-------------------------------------");
                Console.WriteLine("Users");
                Console.WriteLine("ID         Name");
                Console.WriteLine("-------------------------------------");
                foreach (API_User user in users)
                {
                    Console.WriteLine($"{user.UserId}: {user.Username}");
                }
                Console.WriteLine("-------------------------------------");
                Console.WriteLine("");
                API_Transfer transfer = new API_Transfer()
                {
                    userFromID       = UserService.GetUserId(),
                    userToID         = UserToReceiveTransfer(users),
                    transferStatusID = 2,
                    transferTypeID   = 2,
                    transferAmount   = AmountToTransfer()
                };
                return(transfer);
            }
            return(null);
        }
        public API_Transfer StartTransfer(List <API_User> users)
        {
            int selection = -1;

            while (selection != 0)
            {
                Console.WriteLine("-------------------------------------");
                Console.WriteLine("Users");
                Console.WriteLine("ID\t \tName");
                Console.WriteLine("-------------------------------------");
                foreach (API_User user in users)
                {
                    Console.WriteLine($"{user.UserId}:\t \t{user.Username}");
                }
                Console.WriteLine("-------------------------------------");
                Console.WriteLine("");
                API_Transfer transfer = new API_Transfer()
                {
                    UserFromID       = UserService.GetUserId(),
                    UserToID         = UserToReceiveTransfer(users),
                    TransferStatusID = 2, //Sending transfers default to approved and sending.
                    TransferTypeID   = 2,
                    TransferAmount   = AmountToTransfer()
                };
                return(transfer);
            }
            return(null);
        }
Beispiel #4
0
        public TransferDetails PostTransfer(API_Transfer transfer)
        {
            string      token   = UserService.GetToken();
            RestRequest request = new RestRequest(API_BASE_URL + "transfer/send");

            client.Authenticator = new JwtAuthenticator(token);
            request.AddJsonBody(transfer);


            IRestResponse <TransferDetails> response = client.Post <TransferDetails>(request); // response to be informative if the transfer error was due to bad input from user.

            if (response.ResponseStatus != ResponseStatus.Completed)
            {
                Console.WriteLine("An error occurred communicating with the server.");
            }
            else if (!response.IsSuccessful)
            {
                Console.WriteLine("An error response was received from the server. The status code is " + (int)response.StatusCode);
            }
            else
            {
                return(response.Data);
            }

            return(null);
        }
Beispiel #5
0
        public bool SubmitTransferRequest(API_Transfer transfer)
        {
            RestRequest request = new RestRequest(API_BASE_URL + "transfer/request");

            request.AddJsonBody(transfer);
            IRestResponse <API_Transfer> response = client.Post <API_Transfer>(request);

            return(handleErrors(response, "making your transfer", "", ""));
        }
        public API_Transfer CreateTransfer(int accountTo, decimal amount, int accountFrom)
        {
            API_Transfer transfer = new API_Transfer()
            {
                AccountTo = accountTo, Amount = amount, AccountFrom = accountFrom
            };

            return(transfer);
        }
Beispiel #7
0
        private void DisplaySpecificTransfer(int transferIdInput, Dictionary <int, string> userDict)
        {
            Console.WriteLine("---------------------");
            Console.WriteLine(" Transfers Details   ");
            Console.WriteLine("---------------------");

            API_Transfer usersTransfer = transferService.GetSpecificTransfer(transferIdInput);

            //displays Transfer details
            Console.WriteLine();
            Console.WriteLine($"Id: {usersTransfer.TransferId}");
            Console.WriteLine($"From: {userDict[usersTransfer.AccountFrom]}");
            Console.WriteLine($"To: {userDict[usersTransfer.AccountTo]}");

            if (usersTransfer.TransferType == 1)
            {
                Console.WriteLine("Type: Request");
            }
            else
            {
                Console.WriteLine("Type: Send");
            }

            if (usersTransfer.TransferStatus == 1)
            {
                Console.WriteLine("Status: Pending");
                Console.WriteLine($"Amount: ${usersTransfer.Amount}");
                Console.WriteLine();
                Console.WriteLine("Do you want to approve this transfer?: Y/N (or press any other key to exit and return to the main menu)");
                string approvalAnswer = Console.ReadLine();
                if (approvalAnswer.ToLower() == "y")
                {
                    BalanceTransfer newbalanceTransfer = new BalanceTransfer(usersTransfer.AccountFrom, usersTransfer.AccountTo, usersTransfer.Amount, 1, 2, transferIdInput);
                    balanceTransferService.AcceptOrDeclineTransfer(newbalanceTransfer);
                }
                else if (approvalAnswer.ToLower() == "n")
                {
                    BalanceTransfer newbalanceTransfer = new BalanceTransfer(usersTransfer.AccountFrom, usersTransfer.AccountTo, usersTransfer.Amount, 1, 3, transferIdInput);
                    balanceTransferService.AcceptOrDeclineTransfer(newbalanceTransfer);
                }
            }
            else if (usersTransfer.TransferStatus == 2)
            {
                Console.WriteLine("Status: Approved");
                Console.WriteLine($"Amount: ${usersTransfer.Amount}");
            }
            else
            {
                Console.WriteLine("Status: Rejected");
                Console.WriteLine($"Amount: ${usersTransfer.Amount}");
            }

            Console.ReadLine();
            //ShowMainMenu();
        }
Beispiel #8
0
        public API_Transfer GetTransfer(int id)
        {
            API_Transfer transfer = new API_Transfer();
            RestRequest  request  = new RestRequest($"{API_BASE_URL}/transfer/{id}");

            client.Authenticator = new JwtAuthenticator(UserService.GetToken());
            IRestResponse <API_Transfer> response = client.Get <API_Transfer>(request);

            transfer = response.Data;
            return(transfer);
        }
        public string Transfer(API_Transfer transfer, string token)
        {
            RestRequest request = new RestRequest(TRANSFER_URL);

            request.AddJsonBody(transfer);
            client.Authenticator = new JwtAuthenticator(token);
            IRestResponse response = client.Post(request);
            string        message  = ProcessErrorResponse(response);

            return(message);
        }
 public void GetTransferDetails(API_Transfer transfer)
 {
     Console.WriteLine("-------------------------------------");
     Console.WriteLine("Transfer Details");
     Console.WriteLine("-------------------------------------");
     Console.WriteLine("");
     Console.WriteLine($"ID: {transfer.transferID}");
     Console.WriteLine($"From: {transfer.usernameFrom}");
     Console.WriteLine($"To: {transfer.usernameTo}");
     Console.WriteLine($"Type: {transfer.transferTypeDescription}");
     Console.WriteLine($"Status: {transfer.transferStatusDescription}");
     Console.WriteLine($"Amount: ${transfer.transferAmount}");
 }
Beispiel #11
0
        public API_Transfer UpdateTransfer(API_Transfer transfer, int approveOrReject)
        {
            int transferId = transfer.TransferID;

            transfer.TransferStatusId = approveOrReject;
            RestRequest request = new RestRequest($"{API_BASE_URL}/transfer/{transferId}");

            request.AddJsonBody(transfer);
            client.Authenticator = new JwtAuthenticator(UserService.GetToken());
            IRestResponse <API_Transfer> response = client.Put <API_Transfer>(request);

            transfer = response.Data;
            return(transfer);
        }
Beispiel #12
0
        public API_Transfer PromptForTransferInfo()
        {
            API_Transfer newTransfer = new API_Transfer()
            {
                FromUserID = UserService.GetUserId()
            };


            Console.WriteLine("Enter ID of user you are sending to (0 to cancel): ");
            string receiverID = Console.ReadLine();
            int    ID         = -1;
            bool   isValid    = validID.Contains(ID);

            while (!int.TryParse(receiverID, out ID) && !isValid)
            {
                if (ID == 0)
                {
                    break;
                }
                Console.WriteLine("Incorrect value submitted. Please enter a valid ID:");
                Console.WriteLine("Enter ID of user you are sending to (0 to cancel): ");
                receiverID = Console.ReadLine();
            }

            // create if statement to check for valid user ID

            newTransfer.ToUserID = ID;



            Console.WriteLine("Enter amount:");
            string  inputAmount = Console.ReadLine();
            decimal validAmount = 0;

            while (!decimal.TryParse(inputAmount, out validAmount) && validAmount > 0)
            {
                Console.WriteLine("Incorrect value submitted. Please enter a valid amount:");
                Console.WriteLine("Enter valid amount you want to send: ");
                receiverID = Console.ReadLine();
            }


            // create if statement to check for sufficient funds

            newTransfer.Amount = validAmount;

            return(newTransfer);
        }
Beispiel #13
0
        public API_Transfer PromptForUserToTransfer(int userId, decimal balance)
        {
            int                accountTo = 0;
            API_Transfer       transfer  = new API_Transfer();
            List <API_Account> accounts  = new List <API_Account>();

            accounts = accountService.GetAccounts();
            Console.WriteLine("--------------------------------------");
            Console.WriteLine("Users");
            Console.WriteLine("ID\tName");
            Console.WriteLine("--------------------------------------");
            foreach (API_Account account in accounts)
            {
                Console.WriteLine($"{account.UserId}\t{account.Username}");
            }
            Console.WriteLine("Enter ID of user you are sending to (0 to cancel): ");
            while (!int.TryParse(Console.ReadLine(), out accountTo))
            {
                Console.WriteLine("Please input a valid account number.");
            }
            transfer.AccountTo      = accountTo;
            transfer.AccountFrom    = userId;
            transfer.TransferStatus = "Approve";

            Console.WriteLine("Enter amount: ");
            decimal amountToSend = 0;

            while (!decimal.TryParse(Console.ReadLine(), out amountToSend))
            {
                Console.WriteLine("Please input a valid amount.");
            }

            if (amountToSend > balance || amountToSend < 0)
            {
                Console.WriteLine("Transfer failed try again later.");
                return(null);
            }

            transfer.Amount           = amountToSend;
            transfer.TransferStatusId = 2;
            transfer.TransferType     = "Send";
            transfer.TransferTypeId   = 2;



            return(transfer);
        }
Beispiel #14
0
        public API_Transfer PromptForUserToRequestTransfer(int userId)
        {
            int                accountFrom;
            API_Transfer       transfer = new API_Transfer();
            List <API_Account> accounts = new List <API_Account>();

            accounts = accountService.GetAccounts();
            Console.WriteLine("--------------------------------------");
            Console.WriteLine("Users");
            Console.WriteLine("ID\tName");
            Console.WriteLine("--------------------------------------");
            foreach (API_Account account in accounts)
            {
                Console.WriteLine($"{account.UserId}\t{account.Username}");
            }
            Console.WriteLine("Enter ID of user you are requesting from (0 to cancel): ");
            while (!int.TryParse(Console.ReadLine(), out accountFrom) && accountFrom != 0)
            {
                Console.WriteLine("Please input a valid account number.");
            }
            transfer.AccountFrom    = accountFrom;
            transfer.AccountTo      = userId;
            transfer.TransferStatus = "Pending";

            Console.WriteLine("Enter amount: ");
            decimal amountRequested = 0;

            while (!decimal.TryParse(Console.ReadLine(), out amountRequested))
            {
                Console.WriteLine("Please input a valid amount.");
            }

            if (amountRequested < 0)
            {
                Console.WriteLine("Transfer failed try again later.");
                return(null);
            }

            transfer.Amount           = amountRequested;
            transfer.TransferStatusId = 1;
            transfer.TransferType     = "Request";
            transfer.TransferTypeId   = 1;



            return(transfer);
        }
Beispiel #15
0
        public void PrintTransferDetails(API_Transfer transfer)
        {
            WriteDashes(COLUMN_WIDTH_TRANSFER_DETAILS);

            Console.WriteLine("Transfer Details");

            WriteDashes(COLUMN_WIDTH_TRANSFER_DETAILS);

            Console.WriteLine($"ID: {transfer.TransferID}");
            Console.WriteLine($"From: {transfer.FromUserName}");
            Console.WriteLine($"To: {transfer.ToUserName}");
            Console.WriteLine($"Type: {transfer.TransferType.ToString()}");
            Console.WriteLine($"Status: {transfer.TransferStatus.ToString()}");
            Console.WriteLine($"Amount: {transfer.TransferAmount.ToString("C2")}");

            WriteDashes(COLUMN_WIDTH_TRANSFER_DETAILS);
        }
Beispiel #16
0
        public API_Transfer UpdateBalance(API_Transfer transfer)
        {
            RestRequest restRequest = new RestRequest($"{API_URL}/transfer");

            restRequest.AddJsonBody(transfer);
            client.Authenticator = new JwtAuthenticator(UserService.GetToken());
            IRestResponse <API_Transfer> response = client.Put <API_Transfer>(restRequest);

            if (response.ResponseStatus != ResponseStatus.Completed || !response.IsSuccessful)
            {
                ProcessErrorResponse(response);
            }
            else
            {
                return(response.Data);
            }
            return(null);
        }
Beispiel #17
0
        private void TransferMoney(string username)
        {
            bool         isSufficient;
            int          receivingUser = SelectUserToReceiveTransfer();
            decimal      amtToTransfer = SelectAmtToTransfer();
            API_Account  account       = accountService.GetBalance(username);
            API_Transfer transfer      = new API_Transfer();

            transfer.SendingAccount   = account.AccountId;
            transfer.ReceivingAccount = receivingUser;
            transfer.AmountToTransfer = amtToTransfer;

            isSufficient = accountService.RequestToTransferToAnotherAccount(username, amtToTransfer, transfer);
            while (!isSufficient)
            {
                SelectAmtToTransfer();
                Console.WriteLine($"You do not have sufficient funds for the transfer, your current balance is  ${account.AccountBalance}.");
            }
        }
Beispiel #18
0
        private void GetListOfTransfers()
        {
            API_Account         Sender    = accountService.GetBalance(UserService.Username);
            List <API_Transfer> transfers = accountService.GetListOfTransfers(Sender.AccountId);

            foreach (API_Transfer transfer in transfers)
            {
                string transferDetailsString = $"{transfer.TransferId} ) Transfer To: {transfer.ReceivingAccountName} Transfer amount: ${transfer.AmountToTransfer}";
                Console.WriteLine(transferDetailsString);
            }
            Console.WriteLine("Please enter the transfer ID to view the details of the transfer");
            int          selectedTransfer  = int.Parse(Console.ReadLine());
            API_Transfer transferToDisplay = accountService.GetTransferDetails(selectedTransfer);

            string transferDetails = $" ID: {transferToDisplay.TransferId} \n FROM: {UserService.Username} " +
                                     $"\n TO:{transferToDisplay.ReceivingAccount} \n Type: {transferToDisplay.typeName} \n Status: {transferToDisplay.StatusName} " +
                                     $"\n Amount: ${transferToDisplay.AmountToTransfer}  ";

            Console.WriteLine(transferDetails);
        }
Beispiel #19
0
        public bool UpdateTransferStatus(API_Transfer transfer, int approvalOption)
        {
            if (approvalOption == 1)
            {
                transfer.TransferStatus = TransferStatus.Approved;
            }
            else if (approvalOption == 2)
            {
                transfer.TransferStatus = TransferStatus.Rejected;
            }
            else
            {
                return(false);
            }
            RestRequest request = new RestRequest(API_BASE_URL + "transfer");

            request.AddJsonBody(transfer);
            IRestResponse <API_Transfer> response = client.Put <API_Transfer>(request);

            return(handleErrors(response, "making your transfer", "", "You don't have enough money to approve this request."));
        }
Beispiel #20
0
        public API_Transfer PromptForTransferRequest(TransferType transferType)
        {
            bool succeedID           = false;
            bool succeedDollarAmount = false;
            var  transfer            = new API_Transfer();

            int     UserIDInput       = 0;
            decimal dollarAmountInput = 0;

            string[] userResponseArray;

            do
            {
                Console.WriteLine("Please enter user id and transfer amount respectively.");
                Console.WriteLine("For Example: 1 100");
                var userResponse = Console.ReadLine();
                userResponseArray = userResponse.Split(" ");

                if (userResponseArray.Length != 2)
                {
                    continue;
                }

                succeedID           = Int32.TryParse(userResponseArray[0], out UserIDInput);
                succeedDollarAmount = Decimal.TryParse(userResponseArray[1], out dollarAmountInput);
            }while (!succeedID || !succeedDollarAmount);

            if (transferType == TransferType.Send)
            {
                transfer.ToUserID = UserIDInput;
            }
            else
            {
                transfer.FromUserID = UserIDInput;
            }
            transfer.TransferAmount = dollarAmountInput;
            transfer.TransferType   = transferType;
            return(transfer);
        }
Beispiel #21
0
        public bool RequestFunds(int userId, decimal amount)
        {
            API_Transfer transfer = new API_Transfer();

            transfer.TransferTo = userId;
            transfer.Amount     = amount;
            RestRequest request = new RestRequest(API_BASE_URL + "transfer/requestfunds");

            request.AddJsonBody(transfer);
            IRestResponse <bool> response = client.Post <bool>(request);

            if (response.ResponseStatus != ResponseStatus.Completed)
            {
                throw new Exception("An error occurred communicating with the server.");
            }
            else if (!response.IsSuccessful)
            {
                throw new Exception("An error response was received from the server. The status code is " + (int)response.StatusCode);
            }
            else
            {
                return(response.Data);
            }
        }
Beispiel #22
0
        public void PromptForTransfer()
        {
            API_Transfer transfer = new API_Transfer();

            transfer.AccountFrom = UserService.UserId();
            List <API_User> allUsers = accountService.GetAllUserAccounts();
            List <int>      userIDs  = new List <int>();

            foreach (API_User user in allUsers)
            {
                userIDs.Add(user.UserId);
            }

            Console.WriteLine("---------");
            Console.WriteLine();
            Console.Write("Enter ID of user you are sending to (0 to cancel): ");
            int selection = -1;

            if (!int.TryParse(Console.ReadLine(), out selection))
            {
                Console.Clear();
                Console.WriteLine("Invalid input. Please enter only a number.");
                return;
            }
            if (selection == 0)
            {
                return;
            }
            transfer.AccountTo = selection;
            if (!userIDs.Contains(transfer.AccountTo))
            {
                Console.Clear();
                Console.WriteLine();
                Console.WriteLine("Please enter a valid user ID to transfer to!");
                return;
            }
            else if (transfer.AccountFrom == transfer.AccountTo)
            {
                Console.Clear();
                Console.WriteLine();
                Console.WriteLine("Cannot transfer funds to yourself!");
                return;
            }

            Console.Write("Enter amount: ");
            decimal transferAmount = -1;

            if (!decimal.TryParse(Console.ReadLine(), out transferAmount))
            {
                Console.Clear();
                Console.WriteLine("Invalid input. Please enter only valid dollar amount.");
                return;
            }
            transfer.Amount = transferAmount;

            decimal balance = accountService.GetBalance();

            if (this.accountService.TransferTEBucks(transfer) != null)
            {
                if (balance < transfer.Amount)
                {
                    Console.Clear();
                    Console.WriteLine();
                    Console.WriteLine("Insufficient funds for transfer");
                }

                else
                {
                    Console.Clear();
                    Console.WriteLine();
                    Console.WriteLine("Transfer Complete!");
                    Console.WriteLine("You have sent " + transfer.Amount.ToString("C") + " to User " + transfer.AccountTo);
                }
            }
        }
Beispiel #23
0
        public List <API_Transfer> GetAllUserTransfer(int userId)
        {
            RestRequest request = new RestRequest(API_BASE_URL + "transfer/account/transfers/" + userId);
            IRestResponse <List <API_Transfer> > response = client.Get <List <API_Transfer> >(request);

            if (response.ResponseStatus != ResponseStatus.Completed)
            {
                ProcessErrorResponse(response);
            }
            else
            {
                Console.WriteLine("-------------------------------------------");
                Console.WriteLine("Transfers");
                Console.WriteLine("ID\t\tFrom/To\t\tAmount");
                Console.WriteLine("-------------------------------------------");
                List <API_Transfer> transfers = new List <API_Transfer>(response.Data);
                foreach (API_Transfer transfer in transfers)
                {
                    string nameDisplayed = "";
                    if (transfer.accountFrom == UserService.GetUserId())
                    {
                        nameDisplayed = transfer.userTo;
                    }
                    else
                    {
                        nameDisplayed = transfer.userFrom;
                    }
                    Console.WriteLine($"{transfer.transferId}\t\t{GetFromOrTo(transfer.accountFrom)} {nameDisplayed}\t\t{transfer.amount:C2}");
                }
                Console.WriteLine("-------------------------------------------");

                List <int> validIds = new List <int>();
                foreach (API_Transfer transfer in transfers)
                {
                    validIds.Add(transfer.transferId);
                }
                int  selectedId = -1;
                bool isValidId  = false;
                while (isValidId == false)
                {
                    if (selectedId == 0)
                    {
                        return(new List <API_Transfer>());
                    }
                    else if (!validIds.Contains(selectedId))
                    {
                        Console.WriteLine("Please enter transfer ID to view details (0 to cancel):");
                        try
                        {
                            selectedId = Convert.ToInt32(Console.ReadLine());
                        }
                        catch (Exception)
                        {
                            Console.WriteLine("Must be an ID listed.");
                        }
                    }

                    else
                    {
                        isValidId = true;
                    }
                }
                RestRequest request2 = new RestRequest(API_BASE_URL + "transfer/" + selectedId);
                IRestResponse <API_Transfer> response2 = client.Get <API_Transfer>(request2);
                if (response2.ResponseStatus != ResponseStatus.Completed)
                {
                    ProcessErrorResponse(response2);
                }
                else
                {
                    API_Transfer transfer = new API_Transfer();
                    transfer = response2.Data;
                    Console.WriteLine("--------------------------------------------");
                    Console.WriteLine("Transfer Details");
                    Console.WriteLine("--------------------------------------------");
                    Console.WriteLine($"Id: {transfer.transferId}");
                    Console.WriteLine($"From: {transfer.userFrom}");
                    Console.WriteLine($"To: {transfer.userTo}");
                    Console.WriteLine($"Type: {transfer.transferType}");
                    Console.WriteLine($"Status: {transfer.transferStatus}");
                    Console.WriteLine($"Amount: {transfer.amount:C2}");
                    Console.WriteLine("--------------------------------------------");
                }
                return(response.Data);
            }
            return(null);
        }
Beispiel #24
0
        private static void MenuSelection()
        {
            int userID        = UserService.GetUserId();
            int menuSelection = -1;

            while (menuSelection != 0)
            {
                Console.WriteLine("");
                Console.WriteLine("Welcome to TEnmo! Please make a selection: ");
                Console.WriteLine("1: View your current balance");
                Console.WriteLine("2: View your past transfers");
                Console.WriteLine("3: View your pending requests");
                Console.WriteLine("4: Send TE bucks");
                Console.WriteLine("5: Request TE bucks");
                Console.WriteLine("6: Log in as different user");
                Console.WriteLine("0: Exit");
                Console.WriteLine("---------");
                Console.Write("Please choose an option: ");

                if (!int.TryParse(Console.ReadLine(), out menuSelection))
                {
                    Console.WriteLine("Invalid input. Please enter only a number.");
                }
                else if (menuSelection == 1)
                {
                    decimal balance = accountService.GetAccount(userID).Balance;
                    Console.WriteLine($"Your current account balance is: ${balance}");
                }
                else if (menuSelection == 2)
                {
                    int newSelection;
                    List <API_Transfer> transfers = transferService.ListTransfers(userID);
                    Console.WriteLine("--------------------------------------");
                    Console.WriteLine("Transfers");
                    Console.WriteLine("ID\tFrom/To\tAmount");
                    Console.WriteLine("--------------------------------------");
                    foreach (API_Transfer transfer in transfers)
                    {
                        if (transfer.AccountFrom == userID)
                        {
                            Console.WriteLine($"{transfer.TransferID}\tTo:\t{transfer.UserToName}\t$\t{transfer.Amount}");
                        }
                        else
                        {
                            Console.WriteLine($"{transfer.TransferID}\tFrom:\t{transfer.UserFromName}\t$\t{transfer.Amount}");
                        }
                    }
                    Console.WriteLine("--------------------------------------");
                    Console.WriteLine("Please enter transfer ID to view details (0 to cancel): ");
                    while (!int.TryParse(Console.ReadLine(), out newSelection))
                    {
                        Console.WriteLine("Invalid input please enter only a valid number.");
                    }
                    if (newSelection != 0)
                    {
                        API_Transfer transfer = transferService.GetTransfer(newSelection);
                        Console.WriteLine("--------------------------------------");
                        Console.WriteLine("Transfer Details");
                        Console.WriteLine("--------------------------------------");
                        Console.WriteLine($"Id: {transfer.TransferID}");
                        Console.WriteLine($"From:  {transfer.UserFromName}");
                        Console.WriteLine($"To:  {transfer.UserToName}");
                        Console.WriteLine($"Type: {transfer.TransferType}");
                        Console.WriteLine($"Status:  {transfer.TransferStatus}");
                        Console.WriteLine($"Amount:  ${transfer.Amount}");
                        Console.WriteLine("--------------------------------------");
                    }
                }
                else if (menuSelection == 3)
                {
                    int newSelection;
                    List <API_Transfer> transfers = transferService.ListPendingTransfers(userID);
                    Console.WriteLine("--------------------------------------");
                    Console.WriteLine("Pending Transfers");
                    Console.WriteLine("ID\tTo\tAmount");
                    Console.WriteLine("--------------------------------------");
                    foreach (API_Transfer transfer in transfers)
                    {
                        Console.WriteLine($"{transfer.TransferID}\t{transfer.UserToName}\t${transfer.Amount}");
                        Console.WriteLine("--------------------------------------");
                    }
                    Console.WriteLine("Please enter transfer ID to approve/reject (0 to cancel): ");
                    while (!int.TryParse(Console.ReadLine(), out newSelection))
                    {
                        Console.WriteLine("Invalid input please enter only a valid number.");
                    }
                    if (newSelection != 0)
                    {
                        int          approveOrReject;
                        API_Transfer transfer = transferService.GetTransfer(newSelection);
                        Console.WriteLine("1: Approve");
                        Console.WriteLine("2: Reject");
                        Console.WriteLine("0: Don't approve or reject");
                        Console.WriteLine("--------------------------------------");
                        Console.WriteLine("Please choose an option: ");
                        while (!int.TryParse(Console.ReadLine(), out approveOrReject))
                        {
                            Console.WriteLine("Invalid input please enter only a valid number.");
                        }
                        if (approveOrReject == 1)
                        {
                            API_Account accountFrom = accountService.GetAccount(transfer.AccountFrom);
                            if (transfer.Amount < accountFrom.Balance)
                            {
                                transfer             = transferService.UpdateTransfer(transfer, 2);
                                accountFrom.Balance -= transfer.Amount;
                                accountService.UpdateBalance(accountFrom);

                                API_Account accountTo = accountService.GetAccount(transfer.AccountTo);
                                accountTo.Balance += transfer.Amount;
                                accountService.UpdateBalance(accountTo);
                                Console.WriteLine("Transfer approved!");
                            }
                            else
                            {
                                Console.WriteLine("You do not have enough money to approve this transfer");
                            }
                        }
                        else if (approveOrReject == 2)
                        {
                            transfer = transferService.UpdateTransfer(transfer, 3);
                            Console.WriteLine("Transfer rejected!");
                        }
                    }
                }
                else if (menuSelection == 4)
                {
                    API_Account  accountFrom = accountService.GetAccount(userID);
                    API_Transfer transfer    = consoleService.PromptForUserToTransfer(userID, accountFrom.Balance);

                    if (transfer != null)
                    {
                        transferService.SendTransfer(transfer);

                        accountFrom.Balance -= transfer.Amount;
                        accountService.UpdateBalance(accountFrom);

                        API_Account accountTo = accountService.GetAccount(transfer.AccountTo);
                        accountTo.Balance += transfer.Amount;
                        accountService.UpdateBalance(accountTo);
                        Console.WriteLine("Transfer successful");
                    }
                }
                else if (menuSelection == 5)
                {
                    API_Account  accountTo = accountService.GetAccount(userID);
                    API_Transfer transfer  = consoleService.PromptForUserToRequestTransfer(userID);

                    if (transfer != null)
                    {
                        transferService.SendTransfer(transfer);
                        Console.WriteLine("Transfer pending");
                    }
                }
                else if (menuSelection == 6)
                {
                    Console.WriteLine("");
                    UserService.SetLogin(new API_User()); //wipe out previous login info
                    Run();                                //return to entry point
                }
                else
                {
                    Console.WriteLine("Goodbye!");
                    Environment.Exit(0);
                }
            }
        }
Beispiel #25
0
        private static void MenuSelection()
        {
            int menuSelection = -1;

            while (menuSelection != 0)
            {
                Console.WriteLine("");
                Console.WriteLine("Welcome to TEnmo! Please make a selection: ");
                Console.WriteLine("1: View your current balance");
                Console.WriteLine("2: View your past transfers");
                Console.WriteLine("3: View your pending requests");
                Console.WriteLine("4: Send TE bucks");
                Console.WriteLine("5: Request TE bucks");
                Console.WriteLine("6: Log in as different user");
                Console.WriteLine("0: Exit");
                Console.WriteLine("---------");
                Console.Write("Please choose an option: ");

                if (!int.TryParse(Console.ReadLine(), out menuSelection))
                {
                    Console.WriteLine("Invalid input. Please enter only a number.");
                }
                else if (menuSelection == 1)
                {
                    decimal?balance = apiService.GetAccountBalance();

                    if (balance != null)
                    {
                        decimal balanceAmount = (decimal)balance;
                        Console.WriteLine($"Here's your account balance: {balanceAmount.ToString("C2")}");
                    }
                }
                else if (menuSelection == 2)
                {
                    List <API_Transfer> transfers = apiService.GetTransfers();
                    if (transfers == null)
                    {
                        continue;
                    }

                    consoleService.PrintAllTransfers(transfers);

                    int chosenID = consoleService.PromptForTransferID("get details");

                    Func <API_Transfer, bool> search = t => t.TransferID == chosenID;

                    if (transfers.Any(search))
                    {
                        API_Transfer transfer = transfers.Single(search);

                        consoleService.PrintTransferDetails(transfer);
                    }
                    else if (chosenID != 0)
                    {
                        Console.WriteLine("The transfer ID you requested does not exist.");
                    }
                }
                else if (menuSelection == 3)
                {
                    List <API_Transfer> transfers = apiService.GetTransfers();
                    if (transfers == null)
                    {
                        continue;
                    }

                    consoleService.PrintPendingTransfers(transfers);
                    int chosenID = consoleService.PromptForTransferID("approve or reject request");
                    int approvalOption;

                    List <API_Transfer>       pendingTransfers = transfers.Where(t => t.TransferStatus == TransferStatus.Pending).ToList();
                    Func <API_Transfer, bool> search           = t => t.TransferID == chosenID;

                    if (pendingTransfers.Any(search))
                    {
                        API_Transfer pendingTransfer = pendingTransfers.Single(search);
                        approvalOption = consoleService.PromptForApproval();
                        apiService.UpdateTransferStatus(pendingTransfer, approvalOption);
                    }
                    else if (chosenID != 0)
                    {
                        Console.WriteLine("The transfer ID you requested does not exist.");
                    }
                }
                else if (menuSelection == 4)
                {
                    List <API_User> users = apiService.GetOtherUsers();
                    if (users == null)
                    {
                        continue;
                    }

                    consoleService.PrintUsers(users);
                    TransferType transferType = TransferType.Send;
                    API_Transfer transfer     = consoleService.PromptForTransferRequest(transferType);

                    if (!users.Any(u => u.UserId == transfer.ToUserID))
                    {
                        Console.WriteLine("The user ID you requested does not exist.");
                        continue;
                    }

                    transfer.ToUserName = users.First(u => u.UserId == transfer.ToUserID)?.Username;
                    apiService.SubmitTransferRequest(transfer);
                }
                else if (menuSelection == 5)
                {
                    List <API_User> users = apiService.GetOtherUsers();
                    if (users == null)
                    {
                        continue;
                    }

                    consoleService.PrintUsers(users);
                    TransferType transferType = TransferType.Request;
                    API_Transfer transfer     = consoleService.PromptForTransferRequest(transferType);

                    if (!users.Any(u => u.UserId == transfer.FromUserID))
                    {
                        Console.WriteLine("The user ID you requested does not exist.");
                        continue;
                    }

                    transfer.FromUserName = users.First(u => u.UserId == transfer.FromUserID).Username;
                    apiService.SubmitTransferRequest(transfer);
                }
                else if (menuSelection == 6)
                {
                    Console.WriteLine("");
                    UserService.SetLogin(new API_User()); //wipe out previous login info
                    Run();                                //return to entry point
                }
                else
                {
                    Console.WriteLine("Goodbye!");
                    Environment.Exit(0);
                }
            }
        }
Beispiel #26
0
        private static void MenuSelection()
        {
            int menuSelection = -1;

            while (menuSelection != 0)
            {
                Console.WriteLine("");
                Console.WriteLine("Welcome to TEnmo! Please make a selection: ");
                Console.WriteLine("1: View your current balance");
                Console.WriteLine("2: View your past transfers");
                Console.WriteLine("3: View your pending requests");
                Console.WriteLine("4: Send TE bucks");
                Console.WriteLine("5: Request TE bucks");
                Console.WriteLine("6: Log in as different user");
                Console.WriteLine("0: Exit");
                Console.WriteLine("---------");
                Console.Write("Please choose an option: ");

                if (!int.TryParse(Console.ReadLine(), out menuSelection))
                {
                    Console.WriteLine("Invalid input. Please enter only a number.");
                }
                else if (menuSelection == 1)
                {
                    Console.WriteLine($"Your current account balance is: ${apiService.GetBalance()}");
                }
                else if (menuSelection == 2)
                {
                    List <API_Transfer> transfers = apiService.ListTransfers();
                    if (transfers != null && transfers.Count > 0)
                    {
                        consoleService.WriteTransferList(transfers);
                        int          id       = consoleService.TransferToDetail(transfers);
                        API_Transfer transfer = apiService.GetTransfer(id);
                        consoleService.GetTransferDetails(transfer);
                    }
                }
                else if (menuSelection == 3)
                {
                    List <API_Transfer> transfers = apiService.ListTransfers();
                    if (transfers != null && transfers.Count > 0)
                    {
                        consoleService.WritePendingTransferList(transfers);
                    }
                }
                else if (menuSelection == 4)
                {
                    List <API_User> users       = apiService.ListUsers();
                    int             userID      = UserService.GetUserId();
                    API_Account     accountFrom = apiService.GetAccount(userID);
                    if (users != null && users.Count > 0)
                    {
                        API_Transfer transfer = consoleService.StartTransfer(users);
                        if (transfer.TransferAmount > accountFrom.Balance)
                        {
                            Console.WriteLine("Insufficient Funds");
                        }
                        else
                        {
                            API_Transfer updatedTransfer = apiService.DoTransfer(transfer);
                            apiService.UpdateBalance(updatedTransfer);
                            Console.WriteLine("Amount has been transferred");
                        }
                    }
                }
                else if (menuSelection == 5)
                {
                    List <API_User> users = apiService.ListUsers();
                    if (users != null && users.Count > 0)
                    {
                        API_Transfer transfer = consoleService.RequestTransfer(users);
                        apiService.DoTransfer(transfer);
                        Console.WriteLine("Request Sent.");
                    }
                }
                else if (menuSelection == 6)
                {
                    Console.WriteLine("");
                    UserService.SetLogin(new API_User()); //wipe out previous login info
                    Run();                                //return to entry point
                }
                else
                {
                    Console.WriteLine("Goodbye!");
                    Environment.Exit(0);
                }
            }
        }
Beispiel #27
0
        private static void MenuSelection()
        {
            int    menuSelection = -1;
            string token         = UserService.GetToken();

            while (menuSelection != 0)
            {
                Console.Clear();
                Console.WriteLine("");
                Console.WriteLine("Welcome to TEnmo! Please make a selection: ");
                Console.WriteLine("1: View your current balance");
                Console.WriteLine("2: View your past transfers");
                Console.WriteLine("3: View your pending requests");
                Console.WriteLine("4: Send TE bucks");
                Console.WriteLine("5: Request TE bucks");
                Console.WriteLine("6: Log in as different user");
                Console.WriteLine("0: Exit");
                Console.WriteLine("---------");
                Console.Write("Please choose an option: ");

                if (!int.TryParse(Console.ReadLine(), out menuSelection))
                {
                    Console.WriteLine("Invalid input. Please enter only a number.");
                }
                else if (menuSelection == 1)
                {
                    Console.Clear();
                    //prints the results of the get balance function
                    consoleService.printBalance(accountService.GetBalance(token));
                    Console.ReadLine();
                }
                else if (menuSelection == 2)
                {
                    Console.Clear();
                    //generates list of transfers for logged in user
                    List <Transfer> transferList = transferService.GetTransfersForUser(token);
                    //prints transfer list to console
                    consoleService.printTransfersFromList(transferList);
                    //prints to console, asks user for transfer to view details, deals w/ bad input
                    int transferId = consoleService.PromptForTransferDetails(transferList);
                    //if they choose zero, bounces out to main menu
                    if (transferId != 0)
                    {
                        Console.Clear();
                        //once they enter valid transfer number, prints details for transfer from the transfer list
                        consoleService.PrintTransferDetails(transferList, transferId);
                        Console.ReadLine();
                    }
                }
                else if (menuSelection == 3)
                {
                    Console.Clear();
                    //generates list of pending transfers for users
                    List <Transfer> transferList = transferService.GetPendingTransfersForUser(token);
                    //prints list of pending transfers
                    consoleService.printPendingRequestsFromList(transferList);
                    //prompts user for ID of request to approve/reject, deals with bad input
                    int transferId = consoleService.PromptForIdToApproveReject(transferList);
                    //storing the result from  promptforid in object to serialize for back end
                    TransferNumber transferNumber = new TransferNumber()
                    {
                        TransferId = transferId
                    };
                    if (transferId != 0)
                    {
                        int userInput = consoleService.PromptToApproveOrReject();
                        if (userInput != 0)
                        {
                            string message = transferService.ApproveOrReject(userInput, transferNumber, token);
                            consoleService.PromptPrintMessage(message);
                            Console.ReadLine();
                        }
                    }
                }
                else if (menuSelection == 4)
                {
                    Console.Clear();
                    List <User> userList = transferService.GetUsers(token);
                    consoleService.printUserList(userList);
                    int transferUserId = consoleService.PromptForTransferID("transfer", userList);
                    if (transferUserId != 0)
                    {
                        decimal transferAmount = consoleService.PromptForTransferAmount("transfer");
                        if (transferAmount != 0)
                        {
                            API_Transfer transfer        = transferService.CreateTransfer(transferUserId, transferAmount, UserService.GetUserId());
                            string       responseMessage = transferService.Transfer(transfer, token);
                            consoleService.PromptPrintMessage(responseMessage);
                            Console.ReadLine();
                        }
                    }
                    Console.ReadLine();
                }
                else if (menuSelection == 5)
                {
                    Console.Clear();
                    List <User> userList = transferService.GetUsers(token);
                    consoleService.printUserList(userList);
                    int transferUserId = consoleService.PromptForTransferID("request", userList);
                    if (transferUserId != 0)
                    {
                        decimal transferAmount = consoleService.PromptForTransferAmount("request");
                        if (transferAmount != 0)
                        {
                            API_Transfer transfer        = transferService.CreateTransfer(UserService.GetUserId(), transferAmount, transferUserId);
                            string       responseMessage = transferService.CreateRequest(transfer, token);
                            consoleService.PromptPrintMessage(responseMessage);
                        }
                    }
                    Console.ReadLine();
                }
                else if (menuSelection == 6)
                {
                    Console.WriteLine("");
                    UserService.SetLogin(new API_User()); //wipe out previous login info
                    Run();                                //return to entry point
                }
                else
                {
                    Console.WriteLine("Goodbye!");
                    Environment.Exit(0);
                }
            }
        }