Пример #1
0
        static string responder(long chatId, string message)
        {
            string[] transactionParameters = message.Split(" ");

            if (transactionParameters.Length < 3)
            {
                return("Sorry, I do not undestand! Could you repat, please?");
            }

            string transaction = transactionParameters[0].ToUpper();
            string username    = transactionParameters[1];
            string token       = transactionParameters[2];

            if (transaction.Equals("CREATE"))
            {
                Console.WriteLine("Creating an Digital Wallet");
                bank.createDigitalWallet(chatId, transactionParameters[1], transactionParameters[2]);
                return("Digital Wallet was created");
            }

            else if (transaction.Equals("EXCHANGE"))
            {
                return("Sorry, this functionality was not implemented yet");
            }

            else
            {
                DigitalWallet clientWallet = bank.getWallet(username, token);
                if (clientWallet == null)
                {
                    return("Sorry, your wallet is not active");
                }

                if (transaction.Equals("BALANCE"))
                {
                    return("Your balance is: " + clientWallet.getWalletBalance().ToString("C2", CultureInfo.CurrentCulture));
                }

                int value = Convert.ToInt32(transactionParameters[3]);
                DigitalWalletTransaction walletTransaction = new DigitalWalletTransaction();
                if (transaction.Equals("ADD"))
                {
                    return(walletTransaction.addMoney(clientWallet, value));
                }

                if (transaction.Equals("PAY"))
                {
                    return(walletTransaction.payMoney(clientWallet, value));
                }

                if (transaction.Equals("TRANSFER"))
                {
                    DigitalWallet clientWalletReceive = bank.getWallet(transactionParameters[4]);
                    return(walletTransaction.transferMoney(clientWallet, value, clientWalletReceive));
                }
            }

            return("Sorry, I do not undestand! Could you repat, please?");
        }
Пример #2
0
        public string addMoney(DigitalWallet digitalWallet, int amount)
        {
            if (!this.commonValidation(digitalWallet, amount))
            {
                return("We can not do this transaction");
            }

            digitalWallet.setBalance(digitalWallet.getWalletBalance() + amount);

            return(returnBalance(digitalWallet));
        }
Пример #3
0
        public string transferMoney(DigitalWallet digitalWalletSend, int amount, DigitalWallet digitalWalletReceive)
        {
            if (!this.commonValidation(digitalWalletSend, amount))
            {
                return("We can not do this transaction");
            }

            payMoney(digitalWalletSend, amount);
            addMoney(digitalWalletReceive, amount);

            return(returnBalance(digitalWalletSend));
        }
Пример #4
0
        private bool commonValidation(DigitalWallet digitalWallet, int amount)
        {
            if (amount <= 0)
            {
                return(false);
            }

            if (digitalWallet.getUserAccessToken() == null)
            {
                return(false);
            }

            return(true);
        }
Пример #5
0
        public string payMoney(DigitalWallet digitalWallet, int amount)
        {
            if (!this.commonValidation(digitalWallet, amount))
            {
                return("We can not do this transaction");
            }

            // Final balance after possible transaction
            int finalBalance = 0;

            finalBalance = digitalWallet.getWalletBalance() - amount;

            if (finalBalance < 0)
            {
                return("Insufficient balance");
            }
            else
            {
                digitalWallet.setBalance(finalBalance);
            }

            return(returnBalance(digitalWallet));
        }
Пример #6
0
        public void createDigitalWallet(long walletId, string username, string userAccessToken)
        {
            DigitalWallet wallet = new DigitalWallet(walletId, username, userAccessToken);

            digitalWallets.Add(wallet.getUsername(), wallet);
        }
Пример #7
0
 private string returnBalance(DigitalWallet digitalWallet)
 {
     return("Your balance is: " + digitalWallet.getWalletBalance().ToString("C2", CultureInfo.CurrentCulture));
 }