Exemplo n.º 1
0
        public override void Run(bool clearScreen = true)
        {
            if (clearScreen)
            {
                Console.Clear();
            }
            Console.WriteLine($"Deposit for {User.Username}\n");
            Console.Write("Enter amount to deposit: ");
            var amount = UserInputHelper.GetDecimal();

            Console.Write($"Depost {amount:C}. Are you sure? (y/n) : ");
            var confirm = Console.ReadLine();

            if (confirm == "y" || confirm == "Y")
            {
                var res = UserTransactionService.Deposit(User.Id, amount);
                if (res.Success)
                {
                    Console.WriteLine("Deposit Success!");
                }
                else
                {
                    Console.WriteLine($"Deposit Failed. {res.Errors}");
                }
            }
            else
            {
                Console.WriteLine("Deposit Cancelled!");
            }
            ShowDoneOptions();
        }
Exemplo n.º 2
0
        public void Withdraw_WithValidAmount_AfterDeposit_UpdatesLastTransactionBalance()
        {
            //Arrange
            var user = new User
            {
                Username  = "******",
                FirstName = "Demo",
                LastName  = "User",
                Password  = "******"
            };

            new AuthService().Register(user);

            decimal depositAmount  = 500;
            decimal withdrawAmount = 150;
            decimal expected       = depositAmount - withdrawAmount;
            UserTransactionService transactionService = new UserTransactionService();

            //act
            transactionService.Deposit(user.Id, depositAmount);
            transactionService.Withdraw(user.Id, withdrawAmount);

            //Assert
            var balance = transactionService.GetCurrentBalanceForUser(user.Id);

            Assert.AreEqual(expected, balance, "Wrong balance value");
        }
Exemplo n.º 3
0
        public override void Run(bool clearScreen = true)
        {
            if (clearScreen)
            {
                Console.Clear();
            }
            Console.WriteLine($"Withdrawal for {User.Username}");
            Console.WriteLine($"Availabe for withdrawal: {UserTransactionService.GetCurrentBalanceForUser(User.Id):C}\n");

            Console.Write("Enter amount to withdraw: ");
            var amount = UserInputHelper.GetDecimal();

            Console.Write($"Withdraw {amount:C}. Are you sure? (y/n) : ");
            var confirm = Console.ReadLine();

            if (confirm == "y" || confirm == "Y")
            {
                var res = UserTransactionService.Withdraw(User.Id, amount);
                if (res.Success)
                {
                    Console.WriteLine("Withdrawal Success!");
                }
                else
                {
                    Console.WriteLine($"Withdrawal Failed. {res.Errors}");
                }
            }
            else
            {
                Console.WriteLine("Withdrawal Cancelled!");
            }
            ShowDoneOptions();
        }
Exemplo n.º 4
0
        public BaseAccountScreen(long userId, Guid authKey)
        {
            UserTransactionService = new UserTransactionService();
            this.User = UserTransactionService.GetUser(userId);

            this.AuthKey = authKey;
            AuthService  = new AuthService();
        }
Exemplo n.º 5
0
        private void lastFiveItems_Click(object sender, EventArgs e)
        {
            int uId = new UserService(Server).GetUserByLogin(transactionUser.Text);
            List <UserTransactionDTO> filteredList = new UserTransactionService(Server).GetLastUserTransactions(uId, 5);

            UserTransactions = filteredList;
            userTransactionList.DataSource = UserTransactions;
        }
Exemplo n.º 6
0
        private void sortTransactionsByMaxSum_Click(object sender, EventArgs e)
        {
            int uId = new UserService(Server).GetUserByLogin(transactionUser.Text);
            List <UserTransactionDTO> filteredList = new UserTransactionService(Server).GetUserTransactionsDescByMaxSum(uId);

            UserTransactions = filteredList;
            userTransactionList.DataSource = UserTransactions;
        }
        protected void ShowTransactions(int page = 1)
        {
            Console.Clear();
            Console.WriteLine($"Transactions: {User.Username}\n");
            var transactions = UserTransactionService.GetTransactionsForUser(User.Id, page);
            var table        = new ConsoleTable("Date", "Type", "Amount", "Balance");

            foreach (var trans in transactions)
            {
                table.AddRow($"{trans.Date:MM/dd/yyyy hh:mm:ss tt}", $"{trans.GetTransactionType().ToString()}", $"{trans.Amount:C}", $"{trans.CurrentBalance:C}");
            }
            table.Write();
            Console.WriteLine($" Current Page: {page}");
            Console.WriteLine("1. Next Page\t2. Prev Page\t3. Account Screen");

            if (Int32.TryParse(Console.ReadLine(), out int input))
            {
                switch (input)
                {
                case 1:
                {
                    ShowTransactions(++page);
                    break;
                }

                case 2:
                {
                    if (page > 1)
                    {
                        ShowTransactions(--page);
                    }
                    else
                    {
                        ShowTransactions(1);
                    }
                    break;
                }

                case 3:
                {
                    new AccountScreen(User.Id, AuthKey).Run();
                    break;
                }

                default:
                {
                    ShowInvalidOptionError();
                    break;
                }
                }
            }
            else
            {
                ShowInvalidOptionError();
            }
        }
Exemplo n.º 8
0
        public void Deposit_WithValidAmount_AddedToTransactionList()
        {
            //Arrange
            var user = new User
            {
                Username  = "******",
                FirstName = "Demo",
                LastName  = "User",
                Password  = "******"
            };

            new AuthService().Register(user);
            UserTransactionService transactionService = new UserTransactionService();

            //act
            transactionService.Deposit(user.Id, 5);

            //Assert
            var allTransactions = transactionService.GetTransactionsForUser(user.Id);

            Assert.IsTrue(allTransactions.Count() > 0, "Wrong transaction list count");
        }
Exemplo n.º 9
0
        public void Transaction_LastTransactionNotNull()
        {
            //Arrange
            var user = new User
            {
                Username  = "******",
                FirstName = "Demo",
                LastName  = "User",
                Password  = "******"
            };

            new AuthService().Register(user);
            UserTransactionService transactionService = new UserTransactionService();

            //act
            transactionService.Deposit(user.Id, 5);

            //Assert
            var lastTransaction = transactionService.GetLastTransactionForUser(user.Id);

            Assert.IsNotNull(lastTransaction, "Wrong last transaction is null");
        }
Exemplo n.º 10
0
        public void GetUser_AfterRegister()
        {
            //Arrange
            var user1 = new User
            {
                Username  = "******",
                FirstName = "test1",
                LastName  = "test1",
                Password  = "******"
            };

            AuthService auth = new AuthService();

            auth.Register(user1);
            UserTransactionService transactionService = new UserTransactionService();

            //act
            var user = transactionService.GetUser(user1.Id);

            //Assert
            // var transaction = transactionService.GetLastTransactionForUser(user.Id);
            Assert.IsNotNull(user, "user is null after register");
        }
Exemplo n.º 11
0
        public override void Run(bool clearScreen = true)
        {
            if (User == null || !AuthService.IsAuthenticated(AuthKey))
            {
                Console.WriteLine("Could not validate user.");
                return;
            }

            Console.Clear();
            Console.WriteLine($"Welcome {User.Username}!\n");
            Console.WriteLine("1. Check Balance");
            Console.WriteLine("2. Deposit");
            Console.WriteLine("3. Withdrawl");
            Console.WriteLine("4. Transaction History");
            Console.WriteLine("5. Logout");

            Console.Write("\nPlease enter your choice: ");
            if (Int32.TryParse(Console.ReadLine(), out int input))
            {
                switch (input)
                {
                case 1:
                {
                    var currBal = UserTransactionService.GetCurrentBalanceForUser(User.Id);
                    Console.WriteLine($"Your Current Balance is {currBal:C}");
                    Console.WriteLine("Press any key to continue...");
                    Console.ReadLine();
                    Run();
                    break;
                }

                case 2:
                {
                    new DepositScreen(User.Id, AuthKey).Run();
                    break;
                }

                case 3:
                {
                    new WithdrawalScreen(User.Id, AuthKey).Run();
                    break;
                }

                case 4:
                {
                    new TransactionHistoryScreen(User.Id, AuthKey).Run();
                    break;
                }

                case 5:
                {
                    AuthService.Logout(User.Id);
                    new HomeScreen().Run();
                    break;
                }

                default:
                {
                    ShowInvalidOptionError();
                    break;
                }
                }
            }
            else
            {
                ShowInvalidOptionError();
            }
        }
Exemplo n.º 12
0
 public TransactionController(UserTransactionService userTransactionService)
 {
     _userTransactionService = userTransactionService;
 }
Exemplo n.º 13
0
 public AccountController()
 {
     this.UserTransactionService = new UserTransactionService();
 }