public Result Deposit(float amount, AbstractAccount account) { Result result = new Result() { Success = false, Information = "Deposit was not successful" }; try { if (account.CanDeposit(amount)) { AccountEntry entry = new AccountEntry() { Id = account.NextId, Date = DateTime.Now.Date, Descirption = "Counter withdrawal", Credit = amount }; account.Add(entry.Id, entry); result.Information = "Deposit was successful."; result.Success = account.ContainsValue(entry); } else { result.Information = "Cannot process deposit."; result.Success = false; } } catch (ApplicationException exception) { result.Success = false; result.Information = exception.Message; result.Exception = exception; } return result; }
public Result Close(AbstractAccount account) { Result result = new Result() { Success = false, Information = "Attemt to close the account was unsuccessful." }; try { if (account.CanClose()) { account.IsClosed = true; result.Success = true; result.Information = "Account is closed."; } else { result.Information = "Account has a balance."; } } catch (ApplicationException exception) { result.Success = false; result.Information = exception.Message; result.Exception = exception; } return result; }
public Result Withdraw(float amount, AbstractAccount account) { Result result = new Result() { Success = false, Information = "Withrdraw was not successful" }; try { if (account.CanWithdraw(amount)) { AccountEntry entry = new AccountEntry() { Id = account.NextId, Date = DateTime.Now.Date, Descirption = "Counter withdrawal", Debit = amount }; account.Add(entry.Id, entry); result.Information = "Withdwaw was successful."; result.Success = account.ContainsValue(entry); } else { result.Information = "Insufficient funds."; result.Success = false; } } catch (ApplicationException exception) { result.Success = false; result.Information = exception.Message; result.Exception = exception; } return result; }
public void execute(AbstractAccount acc, int amount) { if (amount <= 0) { throw new System.ArgumentException("Invalid amount."); } acc.Deposit(amount); }
internal static void CreateNewAccount(AbstractAccount data) { if (!data.ExistCreditLine) { data.Balance = 5000; } AccountRepository.CreateNewAccount(data); }
internal static void CreateNewAccount(AbstractAccount data) { //AbstractAccountList accountItems = dblayer.ME.GetItems<AbstractAccountList>("accounts"); //if(accountItems == null) //{ // accountItems = new AbstractAccountList(); // accountItems.Items = new List<AbstractAccount>(); //} //accountItems.Items.Add(data); dblayer.ME.InsertNewItem(data, data.AccountNumber); }
private static AbstractAccountList GetAllAccounts() { string dbdatafolder = ConfigurationManager.AppSettings["dbdatafolder"]; DirectoryInfo directoryInfo = new DirectoryInfo(dbdatafolder); AbstractAccountList resultt = new AbstractAccountList(); resultt.Items = new List <AbstractAccount>(); foreach (var filename in directoryInfo.GetFiles()) { AbstractAccount accountItem = dblayer.ME.GetItems <AbstractAccount>(filename.Name); resultt.Items.Add(accountItem); } return(resultt); }
internal static bool IsValidDataForCreation(AbstractAccount data, JsonFEResult jsonResult) { bool result = true; if (!IsValidAccountNumber(data.AccountNumber, jsonResult) || !NotExistAccountNumber(data.AccountNumber, jsonResult)) { result = false; } if (string.IsNullOrEmpty(data.OwnerName)) { jsonResult.Success = false; jsonResult.ErrorMessage.Add("Missing Owner name"); return(false); } return(result); }
internal static void UpdateAccount(AbstractAccount data) { dblayer.ME.UpdateItem(data); }
internal void UpdateItem(AbstractAccount data) { string dataJson = Newtonsoft.Json.JsonConvert.SerializeObject(data); WriteJSONDataFile(dataJson, data.AccountNumber); }