public Response Deposit(Account account, decimal Amount) { var response = new Response(); if (Amount > 0) { account.Balance += Amount; var repo = new AccountRepository(); repo.UpdateAccount(account); response.Success = true; response.Message = "You have successfully made a deposit."; response.DepositInfo = new DepositSlip(); response.DepositInfo.AccountNumber = account.AccountNumber; response.DepositInfo.DepositAmount = Amount; response.DepositInfo.NewBalance = account.Balance; } else { response.Success = false; response.Message = "WTF You have to give a positive amount to deposit!"; } return response; }
public Response<Account> DeleteAccount(DeleteAccountRequest request) { var response = new Response<Account>(); var accountToDelete = request.Account; try { if (accountToDelete == null) { response.Success = false; response.Message = "Account Not Found!"; } else { var repo = new AccountRepository(); repo.DeleteAccount(accountToDelete); response.Success = true; } } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return response; }
public Response<Account> MakeDeposit(DepositRequest request) { var response = new Response<Account>(); var accountToUpdate = request.Account; try { if (request.DepositAmount <= 0) { response.Success = false; response.Message = "Must deposit a positive amount."; } else { accountToUpdate.Balance += request.DepositAmount; var repo = new AccountRepository(); repo.UpdateAccount(accountToUpdate); response.Success = true; response.Data = accountToUpdate; } } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return response; }
public Response<DeleteReceipt> Delete(int accountNumber) { var repo = new AccountRepository(); var response = new Response<DeleteReceipt>(); try { var account = repo.GetAllAccounts(); if (account == null) { response.Success = false; response.Message = "Account was not found!"; } else { response.Success = true; repo.OverwriteFile(account, accountNumber); } } catch (Exception ex) { // log the exception response.Success = false; response.Message = "There was an error. Please try again later."; } return response; }
public Response CreateAccount() { AccountRepository repo = new AccountRepository(); Account newAccount = new Account(); Response response = new Response(); newAccount.AccountNumber = 1; Console.Write("Account holder First name :"); newAccount.FirstName = Console.ReadLine(); Console.Write("Account holder Last name :"); newAccount.LastName = Console.ReadLine(); newAccount.Balance = 0.00M; int returnedAccountNumber = repo.WriteNewLine(newAccount); if (returnedAccountNumber == repo.GetAllAccounts().Count) { response.Success = true; response.CreateAccountInfo = new CreateAccountSlip(); response.CreateAccountInfo.AccountNumber = returnedAccountNumber; response.CreateAccountInfo.FirstName = newAccount.FirstName; response.CreateAccountInfo.LastName = newAccount.LastName; response.CreateAccountInfo.NewBalance = newAccount.Balance; } else { response.Success = false; response.Message = "The account was not created, please try again."; } return response; }
public Response<Account> GetAccount(string accountNumber) { var repo = new AccountRepository(); var response = new Response<Account>(); try { var account = repo.GetAccount(accountNumber); if (account == null) { response.Success = false; response.Message = "Account Not Found!"; } else { response.Success = true; response.Data = account; } } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return response; }
public void AccountWithdrawFails() { var repo = new AccountRepository(); var accountToWithdraw = repo.LoadAccount(2); var accountManager = new AccountManager(); var response = accountManager.Withdraw(accountToWithdraw, 200M); Assert.AreEqual(false, response.Success); }
public void AccountDepositFailsZero() { var repo = new AccountRepository(); var accountToDeposit = repo.LoadAccount(2); var accountManager = new AccountManager(); var response = accountManager.Deposit(accountToDeposit, 0); Assert.IsFalse(response.Success); }
public void CanLoadAccount() { var repo = new AccountRepository(); var account = repo.GetAccount(1); Assert.AreEqual(1, account.AccountNumber); Assert.AreEqual("Mary", account.FirstName); }
public void AccountWithdrawSucceeds() { var repo = new AccountRepository(); var accountToWithdraw = repo.LoadAccount(3); var accountManager = new AccountManager(); var response = accountManager.Withdraw(accountToWithdraw, 100M); Assert.AreEqual(455M, response.Data.NewBalance); Assert.AreEqual(100M, response.Data.WithdrawAmount); Assert.AreEqual(true, response.Success); }
public void AccountDepositSucceeds() { var repo = new AccountRepository(); var accountToDeposit = repo.LoadAccount(1); var accountManager = new AccountManager(); var response = accountManager.Deposit(accountToDeposit, 150M); Assert.AreEqual(497M, response.Data.NewBalance); Assert.AreEqual(150M, response.Data.DepositAmount); Assert.AreEqual(true, response.Success); }
public Response<Account> CreateAccount(CreateAccountRequest request) { var response = new Response<Account>(); var newAccount = request.Account; var repo = new AccountRepository(); repo.CreateAccount(newAccount); response.Success = true; response.Data = newAccount; return response; }
public void WriteNewAccount() { Account account = new Account(); account.FirstName = "Victor"; account.LastName = "Smith"; account.Balance = 1000000000000.00M; var repo = new AccountRepository(); var accounts = repo.GetAllAccounts(); var numAccounts = accounts.Count; repo.WriteNewLine(account); var accountsAfterAdd = repo.GetAllAccounts(); var numAccountsAfterAdd = accountsAfterAdd.Count; Assert.AreEqual(numAccounts +1, numAccountsAfterAdd); }
public Response<CreateReceipt> Create(string[] newAccount) { AccountRepository repo = new AccountRepository(); var response = new Response<CreateReceipt>(); var allAccounts = repo.GetAllAccounts(); List<int> accountNums = new List<int>(); foreach (var accout in allAccounts) { accountNums.Add(accout.AccountNumber); } int freshAccountNumber = accountNums.Max() + 1; try { if (Decimal.Parse(newAccount[2]) <= 0) { response.Success = false; response.Message = "Must initially deposit a positive value."; } else { response.Data = new CreateReceipt(); response.Data.AccountNumber = freshAccountNumber; response.Data.FirstName = newAccount[0]; response.Data.LastName = newAccount[1]; response.Data.InitalAmount = Decimal.Parse(newAccount[2]); response.Success = true; response.Message = "Account successfully created. Press any key to continue..."; repo.CreateAccount(response); } } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return response; }
public Response GetAccount(int AccountNumber) { var repo = new AccountRepository(); var response = new Response(); var account = repo.GetAccount(AccountNumber); if (account == null) { response.Success = false; response.Message = "This is not the Account you are looking for..."; } else { response.Success = true; response.AccountInfo = account; } return response; }
public void CheckAddAccount() { var repo = new AccountRepository(); var newAccount = new Account() { FirstName = "Homer", LastName = "Simpson", Balance = 500 }; repo.AddAccount(newAccount); repo.GetAllAccounts(); var result = repo.LoadAccount(repo.HighestAccountNumber()); Assert.AreEqual(result.Balance, newAccount.Balance); Assert.AreEqual(result.LastName, newAccount.LastName); Assert.AreEqual(result.FirstName, newAccount.FirstName); Assert.AreEqual(result.AccountNumber, 5); }
public Response Transfer(Account Account1, Account Account2, decimal Amount) { var response = new Response(); if (Amount <= Account1.Balance && Amount > 0) { Account1.Balance -= Amount; Account2.Balance += Amount; var repo = new AccountRepository(); repo.UpdateAccount(Account1, Account2); response.Success = true; response.Message = "You have successfully made a transfer."; response.TransferInfo = new TransferSlip(); response.TransferInfo.CurrentAccountNumber = Account1.AccountNumber; response.TransferInfo.CurrentAccountName = Account1.FirstName + " " + Account1.LastName; response.TransferInfo.TargetAccountNumber = Account2.AccountNumber; response.TransferInfo.TargetAccountName = Account2.FirstName + " " + Account2.LastName; response.TransferInfo.TransferAmount = Amount; response.TransferInfo.NewBalanceCurrentAccount = Account1.Balance; response.TransferInfo.NewBalanceTargetAccount = Account2.Balance; } else { response.Success = false; if (Amount > Account1.Balance) { response.Message = "You cannot transfer more money than you have in your balance!!"; } else { response.Message = "That is not a proper transfer amount."; } } return response; }
public Response<Account> MakeWithDrawal(WithDrawalRequest request) { var response = new Response<Account>(); var accountToUpdate = request.Account; try { if (request.Account.Balance < request.WithdrawalAmount) { response.Success = false; response.Message = "You do not have adequate funds in your account."; } else { accountToUpdate.Balance -= request.WithdrawalAmount; var repo = new AccountRepository(); repo.UpdateAccount(accountToUpdate); response.Success = true; response.Data = accountToUpdate; } } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return response; }
public decimal WithdrawFunds(Account account, decimal withdrawAmt) { var repo = new AccountRepository(); decimal newBalance = repo.WithdrawFunds(account, withdrawAmt); return newBalance; }
public void UpdateAccountSucceeds() { var repo = new AccountRepository(); var accountToUpdate = repo.LoadAccount(1); accountToUpdate.Balance = 500.00M; repo.UpdateAccount(accountToUpdate); var result = repo.LoadAccount(1); Assert.AreEqual(500.00M, result.Balance); }
public Response<DepositReciept> Deposit(Account account, decimal amount) { var response = new Response<DepositReciept>(); try { if (amount <= 0) { response.Success = false; response.Message = "Must deposit a positive value."; } else { account.Balance += amount; var repo = new AccountRepository(); repo.UpdateAccount(account); response.Success = true; response.Data = new DepositReciept(); response.Data.AccountNumber = account.AccountNumber; response.Data.DepositAmount = amount; response.Data.NewBalance = account.Balance; } } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return response; }
public Response Withdraw(Account account, decimal Amount) { var response = new Response(); if (Amount <= account.Balance && Amount > 0) { account.Balance -= Amount; var repo = new AccountRepository(); repo.UpdateAccount(account); response.Success = true; response.Message = "You have successfully made a withdrawal."; response.WithdrawalInfo = new WithdrawalSlip(); response.WithdrawalInfo.AccountNumber = account.AccountNumber; response.WithdrawalInfo.WithdrawalAmount = Amount; response.WithdrawalInfo.NewBalance = account.Balance; } else { response.Success = false; if (Amount > account.Balance) { response.Message = "You cannot withdraw more money than you have in your balance!!"; } else { response.Message = "That is not a proper withdrawal amount."; } } return response; }
public Response<WithdrawReciept> Withdraw(Account account, decimal amount) { var response = new Response<WithdrawReciept>(); try { if (amount <= 0 ) { response.Success = false; response.Message = "Must withdraw a positive value."; } else if (amount > account.Balance) { response.Success = false; response.Message = "Insufficient Funds"; } else { account.Balance -= amount; var repo = new AccountRepository(); repo.UpdateAccount(account); response.Success = true; response.Data = new WithdrawReciept(); response.Data.AccountNumber = account.AccountNumber; response.Data.WithdrawAmount = amount; response.Data.NewBalance = account.Balance; } } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return response; }
public Response<TransferReceipt> Transfer(Account accountFrom, Account accountTo, decimal amount) { var response = new Response<TransferReceipt>(); try { if (amount <= 0) { response.Success = false; response.Message = "Must transfer a positive value."; } else { accountFrom.Balance -= amount; accountTo.Balance += amount; var repoFrom = new AccountRepository(); repoFrom.UpdateAccount(accountFrom); repoFrom.UpdateAccount(accountTo); response.Success = true; response.Data = new TransferReceipt(); response.Data.AccountNumberFrom = accountFrom.AccountNumber; response.Data.TransferAmount = amount; response.Data.NewBalance = accountFrom.Balance; response.Data = new TransferReceipt(); response.Data.AccountNumberTo = accountTo.AccountNumber; response.Data.TransferAmount = amount; response.Data.NewBalance = accountTo.Balance; } } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return response; }
public void DeleteSuccess() { var repo = new AccountRepository(); repo.RemoveAccount(3); var account = repo.LoadAccount(3); Assert.IsNull(account); }
public Response Withdraw(Account account, decimal Amount) { var response = new Response(); if (Amount > account.Balance) { response.Success = false; response.Message = " Insufficent funds"; } else { account.Balance -= Amount; var repo = new AccountRepository(); repo.UpdateAccount(account); response.Success = true; response.WithdrawInfo = new WithdrawSlip(); response.WithdrawInfo.AccountNumber = account.AccountNumber; response.WithdrawInfo.WithdrawalAmount = Amount; response.WithdrawInfo.NewBalance = account.Balance; } return response; }
public Response<Account> GetAccount(int accountNumber) { var repo = new AccountRepository(); var response = new Response<Account>(); try { var account = repo.LoadAccount(accountNumber); if (account == null) { response.Success = false; response.Message = "Account was not found!"; } else { response.Success = true; response.Data = account; } } catch (Exception ex) { // log the exception response.Success = false; response.Message = "There was an error. Please try again later."; } return response; }
public void CheckHighestAccountNumber() { var repo = new AccountRepository(); int result = repo.HighestAccountNumber(); Assert.AreEqual(4, result); }