示例#1
0
        public static void StartCommandLoop(string credential)
        {
            var me = acManager.GetBankAccountByCredentials(new AuthenticatedOperation()
            {
                Token = credential
            });

            Console.WriteLine($"Logged in! as :{me.HolderName}, cred:{credential}");
            var cmd = "";

            while (true)
            {
                try
                {
                    cmd = Console.ReadLine();
                    var tokens    = cmd.Split(" ");
                    var command   = tokens[0];
                    var arguments = tokens.ToList().GetRange(1, tokens.Length - 1);

                    if (command == "quit")
                    {
                        break;
                    }

                    if (command == "deposit")
                    {
                        var to = arguments[0];
                        var am = long.Parse(arguments[1]);

                        var depo = new CashOperation
                        {
                            ToIban = to,
                            Money  = new Currency()
                            {
                                Amount = am
                            },
                            OperationType = CashOperationType.Deposit,
                            Token         = credential
                        };

                        var tr = acManager.CashOperation(depo);
                        Console.WriteLine($"Deposited to: {to}, am:{am}");
                    }

                    if (command == "withdraw")
                    {
                        var to = me.Iban;
                        var am = long.Parse(arguments[0]);

                        var with = new CashOperation
                        {
                            ToIban = to,
                            Money  = new Currency()
                            {
                                Amount = am
                            },
                            OperationType = CashOperationType.Withdraw,
                            Token         = credential
                        };

                        var tr = acManager.CashOperation(with);
                        Console.WriteLine($"Withdrawn am:{am}");
                    }

                    if (command == "transfer")
                    {
                        var to  = arguments[0];
                        var am  = long.Parse(arguments[1]);
                        var msg = arguments[2];

                        var tx = new TransferOperation()
                        {
                            ToIban = to,
                            Money  = new Currency()
                            {
                                Amount = am
                            },
                            Message = msg,
                            Token   = credential
                        };

                        var tr = acManager.InterbankTransfer(tx);
                        Console.WriteLine($"Transfered to: {to}, am:{am} | {msg}");
                    }

                    if (command == "balance")
                    {
                        var bal = acManager.GetBalanceByCredentials(new AuthenticatedOperation()
                        {
                            Token = credential
                        });
                        Console.WriteLine($"Balance :{bal.Amount} HUF");
                    }

                    if (command == "history")
                    {
                        var filterDate = DateTime.MinValue;
                        var dir        = TransactionDirection.Any;
                        if (arguments.Count >= 1)
                        {
                            filterDate = DateTime.Parse(arguments[0]);
                            if (arguments.Count >= 2)
                            {
                                dir = arguments[1].ToLower() == "in"
                                    ? TransactionDirection.Incoming
                                    : TransactionDirection.Outgoing;
                            }
                        }

                        PrintHistory(credential, filterDate, dir);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"error: {ex.Message}");
                }
            }
        }