public Transaction withDraw(decimal requestedAmount, int accountNo) { Transaction transaction = null; Account account = getAccount(accountNo); try { if (account == null) { throw new Exception("\nAccount Did not Found"); } if (requestedAmount > account.Balance || requestedAmount < 0) { throw new Exception("\nWithdraw cannot be posssible because of the low ammount"); } else { account.Balance -= requestedAmount; transaction = new Transaction(account.ID, DateTime.Now, Transaction.TranscationType.WithDrawn, requestedAmount); transaction.Id = ATMDAL.getLastNumber("transactions.csv") + 1; updateAccount(account); CustomerDAL dal = new CustomerDAL(); dal.saveTransiction(transaction); } }catch (Exception ex) { Console.WriteLine(ex.Message); return(null); } return(transaction); }
public Transaction transferAmount(decimal requestedAmount, int customerFrom, int customerTo) { Transaction transaction = null; Account accountfrom = getAccount(customerFrom); Account accountTo = getAccount(customerTo); accountfrom.Balance -= requestedAmount; accountTo.Balance += requestedAmount; transaction = new Transaction(accountfrom.ID, DateTime.Now, Transaction.TranscationType.Transfer , requestedAmount); transaction.Id = ATMDAL.getLastNumber("transactions.csv") + 1; (new CustomerDAL()).saveTransiction(transaction); updateAccount(accountfrom); updateAccount(accountTo); return(transaction); }
public int createAccount(Person person, Credentials credentials, Account account) { AdminDAL dal = new AdminDAL(); int accountNo = ATMDAL.getLastNumber("account.csv") + 1; int personID = ATMDAL.getLastNumber("users.csv") + 1; person.id = personID; credentials.ID = personID; person.accountNo = accountNo; account.ID = person.accountNo; credentials.Password = Authentication.encryption(credentials.Password); dal.savePerson(person); dal.saveCredentials(credentials); dal.saveAccount(account); return(accountNo); }
public Transaction depositCash(decimal requestedAmount, int accountNo) { Account account = getAccount(accountNo); if (account == null) { return(null); } Transaction transaction = null; account.Balance += requestedAmount; transaction = new Transaction(account.ID, DateTime.Now, Transaction.TranscationType.WithDrawn, requestedAmount); transaction.Id = ATMDAL.getLastNumber("transactions.csv") + 1; updateAccount(account); CustomerDAL dal = new CustomerDAL(); dal.saveTransiction(transaction); return(transaction); }