예제 #1
0
        public AccountWithdrawResponse Withdraw(string accountNumber, decimal amount)
        {
            AccountWithdrawResponse response = new AccountWithdrawResponse();

            response.Account = _accountRepository.LoadAccount(accountNumber);

            if (response.Account == null)
            {
                response.Success = false;
                response.Message = "The account number is not valid";
                return(response);
            }

            //Iwithdraw local var
            IWithdraw withdrawRule = WithdrawRulesFactory.Create(response.Account.Type);//

            // where does the Account object conme from

            response = withdrawRule.Withdraw(response.Account, amount);

            if (response.Success)
            {
                _accountRepository.SaveAccount(response.Account);
            }

            return(response);
        }
예제 #2
0
        public AccountWithdrawResponse Withdraw(string accountNumber, decimal amount)
        {
            AccountWithdrawResponse response = new AccountWithdrawResponse();

            response.Account = _accountRepository.LoadAccount(accountNumber);

            if (response.Account == null)
            {
                response.Success = false;
                Console.WriteLine($"{accountNumber} is not valid");
                return(response);
            }
            else
            {
                response.Success = true;
            }

            IWithdraw withdrawRules = WithdrawRulesFactory.Create(response.Account.Type);

            response = withdrawRules.Withdraw(response.Account, amount);

            if (response.Success == true)
            {
                _accountRepository.SaveAccount(response.Account);
            }
            return(response);
        }
예제 #3
0
        public AccountWithdrawResponse Withdraw(string accountNumber, decimal amount)
        {
            AccountWithdrawResponse accountWithdrawResponse = new AccountWithdrawResponse
            {
                Account = _accountRepository.LoadAccount(accountNumber)
            };

            if (accountWithdrawResponse.Account == null)
            {
                accountWithdrawResponse.Success = false;
                accountWithdrawResponse.Message = "Error: Account number DNE";
                return(accountWithdrawResponse);
            }

            IWithdraw withdraw = WithdrawRulesFactory.Create(accountWithdrawResponse.Account.Type);

            accountWithdrawResponse = withdraw.Withdraw(accountWithdrawResponse.Account, amount);

            if (accountWithdrawResponse.Success)
            {
                _accountRepository.SaveAccount(accountWithdrawResponse.Account);
            }

            return(accountWithdrawResponse);
        }
예제 #4
0
        public AccountWithdrawResponse Withdraw(string accountNumber, decimal amount)
        {
            AccountWithdrawResponse response = new AccountWithdrawResponse();

            response.Account = _accountRepository.LoadAccount(accountNumber);

            if (response.Account == null)
            {
                response.Success = false;
                response.Message = $"{accountNumber}is an invalid account number";
            }
            else
            {
                response.Success = true;
            }


            if (response.Success)
            {
                IWithdraw WithdrawRule = WithdrawRulesFactory.Create(response.Account.Type);
                response = WithdrawRule.Withdraw(response.Account, amount);
                _accountRepository.SaveAccount(response.Account);
            }
            return(response);
        }
        public AccountWithdrawReponse Withdraw(string accountNumber, decimal amount)
        {
            AccountWithdrawReponse response = new AccountWithdrawReponse();

            response.Account = sgBankRepository.LoadAccount(accountNumber);

            if (response.Account == null)
            {
                response.Success = false;
                response.Message = $"{accountNumber} is not a valid account.";
                return(response);
            }
            else
            {
                response.Success = true;
            }

            IWithdraw withdrawRule = WithdrawRulesFactory.Create(response.Account.Type);

            response = withdrawRule.Withdraw(response.Account, amount);

            if (response.Success)
            {
                amount = response.Amount;
                sgBankRepository.SaveAccount(response.Account);
            }

            return(response);
        }
예제 #6
0
        public AccountWithdrawResponse Withdraw(string accountNumber, decimal amount)
        {
            AccountWithdrawResponse response = new AccountWithdrawResponse();

            response.Account = _accountRepository.LoadAccount(accountNumber);
            if (response.Account == null)
            {
                response.Success = false;
                response.Message = "That the account number is not valid.";
                return(response);
            }
            else
            {
                response.Success = true;
            }

            IWithdraw withdrawRule = WithdrawRulesFactory.Create(response.Account.Type);

            response = withdrawRule.Withdraw(response.Account, amount);

            if (response.Success)
            {
                _accountRepository.SaveAccount(response.Account);
            }

            return(response);
        }
예제 #7
0
        public AccountWithdrawResponse Withdraw(string accountNumber, decimal amount)
        {
            AccountWithdrawResponse response = new AccountWithdrawResponse();

            try
            {
                response.Account = _accountRepository.LoadAccount(accountNumber);
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }

            if (response.Account == null)
            {
                response.Success = false;
                response.Message = $"Error: {accountNumber} is not a valid account number. ";
                return(response);
            }


            IWithdraw withdraw = WithdrawRulesFactory.Create(response.Account.Type);

            response = withdraw.Withdraw(response.Account, amount);

            if (response.Success)
            {
                try
                {
                    _accountRepository.SaveAccount(response.Account);
                }
                catch (Exception ex)
                {
                    response.Success = false;
                    response.Message = ex.Message;
                }
            }
            return(response);
        }
예제 #8
0
        public AccountWithdrawResponse Withdraw(string accountNumber, decimal amount)
        {
            var account = _accountRepository.LoadAccount(accountNumber);

            if (account == null)
            {
                return(new AccountWithdrawResponse()
                {
                    Success = false,
                    Message = "Invalid Account Number"
                });
            }

            var action = WithdrawRulesFactory.Create(account.Type);
            var result = action.Withdraw(account, amount);

            if (result.Success)
            {
                _accountRepository.SaveAccount(account);
            }

            return(result);
        }
        public AccountWithdrawResponse Withdraw(string accountNumber, decimal amount)
        {
            AccountWithdrawResponse response = new AccountWithdrawResponse {
                Account = _accountRepository.LoadAccount(accountNumber)
            };

            if (response.Account.AccountNumber == null)
            {
                response.Success = false;
                response.Message = $"{accountNumber} is not a valid account.";
                return(response);
            }

            IWithdraw withdraw = WithdrawRulesFactory.Create(response.Account.Type);

            response = withdraw.Withdraw(response.Account, amount);

            if (response.Success)
            {
                _accountRepository.SaveAccount(response.Account);
            }

            return(response);
        }