Пример #1
0
        private static void GetPendingTransfers()
        {
            bool transferSelected = false;

            do
            {
                Console.Clear();
                List <ReturnTransfer> transfers = transferService.GetTransfers(UserService.GetUserId());
                if (transfers == null || transfers.Count == 0)
                {
                    Console.WriteLine("Sorry we couldn't find any transfers");
                    Console.WriteLine("Press enter to return");
                    Console.ReadLine();
                    return;
                }
                Console.WriteLine("-------------------------------------------");
                Console.WriteLine("Transfers");
                Console.Write("ID");
                Console.Write("To".PadLeft(17));
                Console.WriteLine("Amount".PadLeft(17));
                Console.WriteLine("-------------------------------------------");

                foreach (ReturnTransfer transfer in transfers)
                {
                    if (transfer.Transfer_status_id == 1 && transfer.Account_from == UserService.GetUserId())
                    {
                        Console.Write($"{transfer.Transfer_id}".PadRight(10));
                        Console.Write("To: ".PadRight(6));
                        Console.Write($"{transfer.ToName}");
                        Console.WriteLine($"{transfer.Amount:C2}".PadLeft(15));
                    }
                }
                Console.WriteLine("---------");
                Console.Write("Please enter transfer ID to approve/reject (0 to cancel): ");
                string approveRejectTransferChoice = Console.ReadLine().Trim();
                try
                {
                    if (Convert.ToInt32(approveRejectTransferChoice) == 0)
                    {
                        return;
                    }
                    ReturnTransfer approveRejectTransfer = transferService.GetTransfer(Convert.ToInt32(approveRejectTransferChoice));
                    if (approveRejectTransfer.Transfer_id != 0 && approveRejectTransfer.Transfer_status_id == 1 &&
                        approveRejectTransfer.Account_from == UserService.GetUserId() && approveRejectTransfer.Amount
                        <= accountService.GetBalance(UserService.GetUserId()))
                    {
                        Console.WriteLine("1: Approve");
                        Console.WriteLine("2: Reject");
                        Console.WriteLine("3: Don't approve or reject");
                        Console.WriteLine("---------");
                        Console.Write("Please choose an option: ");
                        string approveReject = Console.ReadLine();
                        switch (approveReject)
                        {
                        case "1":
                            ;
                            approveRejectTransfer.Transfer_status_id = 2;
                            transferService.UpdateTransferStatus(approveRejectTransfer);
                            transferSelected = true;
                            Console.WriteLine("Transfer Approved");
                            break;

                        case "2":
                            approveRejectTransfer.Transfer_status_id = 3;
                            transferService.UpdateTransferStatus(approveRejectTransfer);
                            transferSelected = true;
                            Console.WriteLine("Transfer Rejected");
                            break;

                        case "3":
                            transferSelected = true;
                            return;

                        default:
                            return;
                        }
                    }
                    else if (approveRejectTransfer.Amount > accountService.GetBalance(UserService.GetUserId()))
                    {
                        Console.WriteLine("You don't have enough funds to fulfill this request.");
                    }
                    else
                    {
                        Console.WriteLine("Please choose a valid transfer");
                    }
                }
                catch
                {
                    Console.WriteLine("Please enter a valid option");
                }
            } while (!transferSelected);
        }