Ejemplo n.º 1
0
        // Feature: Transfer Funds between accounts
        // Requirements:
        //      Must be owner of both source and destination accounts
        //      Can only transfer between checking and savings
        //      Can only transfer quantity >= 100
        public bool TransferFunds(BankAppUser invokingUser, BankAccount source, BankAccount destination, decimal amount)
        {
            if (source.Owner.EntityId != invokingUser.EntityId || destination.Owner.EntityId != invokingUser.EntityId)
            {
                return(false);
            }

            if (source.AccountType != BankAccountType.Checking || source.AccountType != BankAccountType.Savings)
            {
                return(false);
            }

            if (destination.AccountType != BankAccountType.Checking || destination.AccountType != BankAccountType.Savings)
            {
                return(false);
            }

            if (amount < 100)
            {
                return(false);
            }


            return(_bankAccountService.TransferFund(source, destination, amount));
        }
Ejemplo n.º 2
0
        public IActionResult CreateBankUser(BankAppUser bankAppUser)
        {
            return(Gatekeeper(() =>
            {
                if (_manager.CreateUser(bankAppUser))
                {
                    return Ok();
                }

                return BadRequest();
            }));
        }
Ejemplo n.º 3
0
        // Feature: Retrieve all bank accounts
        // Requirements:
        //      Only your bank accounts is returned
        public ISet <BankAccount> GetUserBankAccounts(string bankAppUserId)
        {
            // Lecture:
            // One major problem of having different models or using the
            // DTO pattern is the need to box values just to be able to
            // pass along the abstraction layers
            var bankAppUser = new BankAppUser()
            {
                EntityId = bankAppUserId
            };


            return(_bankAccountService.GetBankAccounts(bankAppUser));
        }
Ejemplo n.º 4
0
        public ISet <BankAccount> GetBankAccounts(BankAppUser bankAppUser)
        {
            var accountEntities = _bankDAO.GetBankAccountsBy(bankAppUser.EntityId);

            var bankAccounts = accountEntities.Select(x => new BankAccount()
            {
                Balance     = x.Balance,
                Owner       = bankAppUser,
                AccountType = (BankAccountType)x.BankAccountTypeValue,
                EntityId    = x.EntityId
            }).ToHashSet();


            return(bankAccounts);
        }
Ejemplo n.º 5
0
        static void CreateUser()
        {
            BankAppUserManager manager = new BankAppUserManager();

            Console.Write("Enter Username: ");

            var username = Console.ReadLine();

            var bankAppUser = new BankAppUser()
            {
                Username = username
            };

            manager.CreateUser(bankAppUser);
        }
Ejemplo n.º 6
0
        // Feature: Create new user
        // Requirements:
        //      User does not already exist
        public bool CreateUser(BankAppUser newUser)
        {
            if (_bankDAO.GetBankUsers().Any(u => u.Username == newUser.Username))
            {
                return(false);
            }


            var userEntity = new BankAppUserEntity()
            {
                //DOB = DateTime.Parse(newUser.DOB),
                Username     = newUser.Username,
                PasswordHash = newUser.PasswordHash,
                Salt         = newUser.Salt
            };

            return(_bankDAO.AddBankUser(userEntity));
        }