Example #1
0
        [Test] // 1
        public void AddBankAccount_AddsANewAccountAnd_ReturnsNewAccountId_WhenCalled()
        {
            //Arrange
            BankAccount bankAccount = new BankAccount {
                CustomerId = 1, BankAccountTypeId = 1, Interestrate = 0
            };
            BankAccountRepository bankAccountRepository = new BankAccountRepository(context);
            var             expected1        = bankAccount;
            BankAccountType bankAccountType1 = new BankAccountType
            {
                BankAccountTypeId = 1, BankAccountTypeName = "Saving Account"
            };
            BankAccountType bankAccountType2 = new BankAccountType
            {
                BankAccountTypeId = 2, BankAccountTypeName = "Check Account"
            };

            context.BankAccountTypes.Add(bankAccountType1);
            context.BankAccountTypes.Add(bankAccountType2);
            context.SaveChanges();
            int expected2 = 1;

            //Act
            int actual2 = bankAccountRepository.AddBankAccount(bankAccount);
            var actual1 = context.BankAccounts.ToList().ElementAt(0);

            //Assert
            Assert.AreEqual(expected1, actual1);
            Assert.AreEqual(expected2, actual2);
        }
Example #2
0
 public long AddBankAccount(BankAccountObject bankAccount)
 {
     try
     {
         return(_bankAccountRepository.AddBankAccount(bankAccount));
     }
     catch (Exception ex)
     {
         ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
         return(0);
     }
 }
        static void Main(string[] args)
        {
            // 1 CreateCustomer
            CustomerRepository customerRepository = new CustomerRepository();
            Customer           customer           = new Customer();

            customer.TaxIDNumber = 3;
            customer.Address     = "address3";
            customer.Name        = "customer3";
            //customer.CustomerId = 3;
            customerRepository.CreateCustomer(customer);
            Console.WriteLine("New Customer with ID {0} added", customer.CustomerId);
            Console.WriteLine();

            ////////////////////////////////////////////////////////////////////
            BankAccountRepository bankRepository = new BankAccountRepository();
            BankAccount           newBankAccount = new BankAccount();

            //1 AddBankAccount
            newBankAccount.Interestrate      = 0;
            newBankAccount.CustomerId        = 1;
            newBankAccount.BankAccountTypeId = 1;
            var type1 = newBankAccount.GetType();
            int newsavingaccountid = bankRepository.AddBankAccount(newBankAccount);

            Console.WriteLine("new {1} with Id {0} added", newBankAccount.BankAccountId, type1);
            Console.WriteLine();

            ////2 DeleteBankAccount
            //BankAccount bankAccount = new BankAccount();
            //bankAccount.BankAccountId = 7;
            //bankRepository.DeleteBankAccount(bankAccount);
            //Console.WriteLine("new SavingAccount with Id {0} Deleted", bankAccount.BankAccountId);
            //Console.WriteLine();

            ////3 Display BankAccounts // Not Implemented Yet
            //List<BankAccount> bankAccountList = bankRepository.GetAllBankAccounts();
            //for (int i = 0; i < bankAccountList.Count; i++)
            //{
            //    Console.WriteLine("SavingAccount number {0} in DataBase has ID {1} and tpye {2}",
            //                        (i + 1), bankAccountList[i].BankAccountId, bankAccountList[i].GetType().Name);
            //    //*bankRepository.DeleteBankAccount(bankAccountList[i]);
            //}
            //Console.WriteLine();

            ////////////////////////////////////////////////////////////
            //BankAccount bankAccount = new BankAccount();
            //BankAccountRepository bankAccountRepository = new BankAccountRepository();

            //Depositing depositing = new Depositing();
            //bankAccount.BankAccountId = 13;
            //depositing.Deposit(100, bankAccount);
            ////*var newBalance = bankAccount.Balance;
            ////*var newInterestRate = bankAccount.Interestrate;

            //BankAccount bankAccountInDBAfterDepositing =
            //    bankAccountRepository.GetBankAccuntById(13);

            ////Console.WriteLine("BankAccount {0} balance is {1} interestrate: {2}",
            ////    bankAccount.BankAccountId, newBalance, newInterestRate);

            //Console.WriteLine("BankAccount {0} balance is {1} interestrate: {2}",
            //   bankAccountInDBAfterDepositing.BankAccountId, bankAccountInDBAfterDepositing.Balance,
            //   bankAccountInDBAfterDepositing.Interestrate);

            //Console.WriteLine(2 + 3);
            //Console.WriteLine();

            //Withdrawing withdraw = new Withdrawing();
            //bankAccount.BankAccountId = 13;
            //withdraw.Withdraw(100, bankAccount);
            //BankAccount bankAccountInDBAfterWithdraw =
            //    bankAccountRepository.GetBankAccuntById(13);

            //Console.WriteLine("BankAccount {0} balance is {1} interestrate: {2}",
            //    bankAccountInDBAfterWithdraw.BankAccountId, bankAccountInDBAfterWithdraw.Balance,
            //    bankAccountInDBAfterWithdraw.Interestrate);
            //Console.WriteLine(2 + 3);
            //Console.WriteLine();

            //Correcting correcting = new Correcting();
            //bankAccount.BankAccountId = 15;
            //correcting.Correct(329, bankAccount);

            //BankAccount bankAccountInDBAfterCorrection =
            //    bankAccountRepository.GetBankAccuntById(15);

            //Console.WriteLine("BankAccount {0} balance is {1} interestrate: {2}",
            //    bankAccountInDBAfterCorrection.BankAccountId, bankAccountInDBAfterCorrection.Balance,
            //    bankAccountInDBAfterCorrection.Interestrate);
            //Console.WriteLine();


            Console.Read();
        }
Example #4
0
 //1 Add a new Bank Account
 public int AddBankAccount(BankAccount bankAccount)
 {
     return(bankAccountRepository.AddBankAccount(bankAccount));
 }
Example #5
0
        private void InitCommands()
        {
            LoginCommand = new RelayCommand((x) =>
            {
                if (!userRepo.DoesUserExist(LoginTextBox))
                {
                    MessageBox.Show("There is no user with this login", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }

                var user = userRepo.GetUserByName(LoginTextBox);

                if (user.Password != PasswordTextBox)
                {
                    MessageBox.Show("Wrong password", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }

                if (user.IsLogged)
                {
                    MessageBox.Show("User is online", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
                user.IsLogged = true;
                userRepo.UpdateUser(user);
                var bankAccount       = bankRepo.GetBankAccountByOwnerId(user.Id);
                var window            = serviceProvider.GetRequiredService <AccountWindow>();
                var vm                = window.DataContext as AccountWindowViewModel;
                vm.CurrentUser        = user;
                vm.CurrentBankAccount = bankAccount;
                vm.Balance            = vm.CurrentBankAccount.Deposit;
                vm.PopulateInvestments();
                vm.PopulateLoans();
                vm.broker.UpdateLoggedUsers();
                window.Show();
            });
            RegisterCommand = new RelayCommand((x) =>
            {
                RegisterWindowVisibility = Visibility.Visible;
                LoginWindowVisibility    = Visibility.Collapsed;
            });
            RegisterButtonCommand = new RelayCommand((x) =>
            {
                if (userRepo.DoesUserExist(RegisterLoginTextBox))
                {
                    MessageBox.Show("User already registered", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
                var user = new User()
                {
                    Login    = RegisterLoginTextBox,
                    Password = RegisterPasswordBox,
                    IsAdmin  = RegisterIsAdmin,
                    Name     = RegisterUserName
                };

                userRepo.AddUser(user);
                var userId = userRepo.GetUserByName(user.Login).Id;

                var bankAccount = new BankAccount()
                {
                    Deposit     = 1000,
                    OwnerUserId = userId
                };
                bankRepo.AddBankAccount(bankAccount);
                CleanRegisterePage();
                RegisterWindowVisibility = Visibility.Collapsed;
                LoginWindowVisibility    = Visibility.Visible;
            });
            CancelButtonCommand = new RelayCommand((x) =>
            {
                RegisterWindowVisibility = Visibility.Collapsed;
                LoginWindowVisibility    = Visibility.Visible;
                CleanRegisterePage();
            });
        }