public bool TransferTo(IAccountable fromUser, string toUser, int amount, ref string msg) { if (amount <= 0) { msg = "amount must be bigger then zero"; } else if (fromUser.Balance - amount < 0) { msg = "you don't have enough money"; } else if (toUser == fromUser.Username) { msg = "you can't transfer money to yourself"; } else { var touser = FindByName(toUser); if (touser == null) { msg = "User \'" + touser + "\' not found"; } else { fromUser.Balance -= amount; touser.Balance += amount; Transactions.Add(new Transaction() { From = fromUser, To = touser, Amount = amount }); return(true); } } return(false); }
public static AccountTransaction TransferTransaction(IAccountable fromAccount, IAccountable toAccount, decimal amount, string description) { if (fromAccount.Currency != toAccount.Currency) { throw new InvalidOperationException("Accounts should have same currency."); } return(new AccountTransaction(Guid.NewGuid(), amount, DateTimeOffset.UtcNow, fromAccount.Debit(amount), toAccount.Credit(amount), description)); }
/// <summary> /// Creates a new accountant reporting its measurement to the specified <paramref name="accountable"/> object. /// </summary> /// <param name="accountable">The accountable object to report the measurement to.</param> public Accountant(IAccountable accountable) { _accountable = accountable; if (!NativeMethods.TryGetThreadCycleTime(out _cycles)) { _cycles = 0UL; } _start = Stopwatch.GetTimestamp(); }
public void GetCustomerAccounts() { //Arrange - Create a customer plus some accounts for that customer BankCustomer cust = new BankCustomer(); SavingsAccount savings = new SavingsAccount("asdf", "123"); CheckingAccount checking1 = new CheckingAccount("asdfj", "123"); CheckingAccount checking2 = new CheckingAccount("asdfj", "123"); cust.AddAccount(checking1); cust.AddAccount(checking2); cust.AddAccount(savings); //Act - call getaccounts IAccountable[] actualAccounts = cust.GetAccounts(); //assert - verify all accounts are returned IAccountable[] expectedAccounts = new IAccountable[] { savings, checking1, checking2 }; //CollectionAssert.AreEqual(expectedAccounts, actualAccounts); // has to have the same lineup in the collection that you are checking into CollectionAssert.AreEquivalent(expectedAccounts, actualAccounts); // checks to make sure the name is in the collection, order doesn't matter. }
public void getCustomerAccounts(string accountHolderName, string accountNumber) { BankCustomer cust = new BankCustomer(); SavingsAccount savings = new SavingsAccount(accountHolderName, accountNumber); CheckingAccount checking1 = new CheckingAccount(accountHolderName, accountNumber); CheckingAccount checking2 = new CheckingAccount(accountHolderName, accountNumber); IAccountable[] expectedAccounts = new IAccountable[] { savings, checking1, checking2 }; cust.AddAccount(savings); cust.AddAccount(checking2); cust.AddAccount(checking1); IAccountable[] actualAccounts = cust.GetAccounts(); //CollectionAssert.AreEqual(expectedAccounts, actualAccounts); CollectionAssert.AreEquivalent(expectedAccounts, actualAccounts); }
public void GetCustomerAccounts() { // Arrange - Create a customer plus some accounts for that customer BankCustomer cust = new BankCustomer(); SavingsAccount savings = new SavingsAccount("xxx", "123"); CheckingAccount checking1 = new CheckingAccount("xxx", "123"); CheckingAccount checking2 = new CheckingAccount("xxx", "123"); cust.AddAccount(checking1); cust.AddAccount(checking2); cust.AddAccount(savings); // Act - call GetAccounts IAccountable[] actualAccounts = cust.GetAccounts(); // Assert - verify all accounts are returned IAccountable[] expectedAccounts = new IAccountable[] { savings, checking1, checking2 }; //CollectionAssert.AreEqual(expectedAccounts, actualAccounts); CollectionAssert.AreEquivalent(expectedAccounts, actualAccounts); }
public void AddAccount(IAccountable newAccount) { this.customersAccounts.Add(newAccount); }
public void AddAccount(IAccountable account) { accounts.Add(account); }
/// <summary> /// Adds newAccount to the customer's list of accounts /// </summary> /// <param name="newAccount"></param> public void AddAccount(IAccountable newAccount) { listOfAccounts.Add(newAccount); }
public static AccountTransaction WithdrawTransaction(IAccountable account, decimal amount, string description) { return(TransferTransaction(account, SystemAccount.FromCurrency(account.Currency), amount, description)); }
public static AccountTransaction Transfer(this IAccountable fromAccount, IAccountable toAccount, decimal amount, string description) => AccountTransaction.TransferTransaction(fromAccount, toAccount, amount, description);
public static AccountTransaction Withdraw(this IAccountable account, decimal amount, string description) => AccountTransaction.WithdrawTransaction(account, amount, description);
public static AccountTransaction Deposit(this IAccountable account, decimal amount, string description) => AccountTransaction.DepositTransaction(account, amount, description);
public void CreateAccountingEntry(DeepBlue.Models.Accounting.Enums.AccountingTransactionType accountingTransactionType, int fundID, int entityID, IAccountable accountableItem, decimal? amount = null, int? accountingTransactionSubTypeID = null) { DeepBlueEntities context = new DeepBlueEntities(); decimal amt = amount.HasValue ? amount.Value : (accountableItem.Amount.HasValue ? accountableItem.Amount.Value : 0); var query = from aet in context.AccountingEntryTemplates where aet.EntityID == entityID && aet.AccountingTransactionTypeID == (int)accountingTransactionType select aet; // See if there are any templates specific to the Fund List<AccountingEntryTemplate> templates = query.Where(x => x.FundID == fundID).ToList(); if (templates.Count <= 0) { // No templates found for this fund.. try to see if there is an Entity level template available templates = query.Where(x => x.FundID == null).ToList(); } if (templates.Count > 0) { // Filter on the sub type if (accountingTransactionSubTypeID.HasValue) { //var templatesWithSubType = templates.Where(x => x.AccountingTransactionSubTypeID == accountingTransactionSubTypeID.Value).ToList(); //if (templatesWithSubType.Count > 0) { // templates = templatesWithSubType; //} } List<AccountingEntry> accountingEntries = new List<AccountingEntry>(); foreach (AccountingEntryTemplate template in templates) { // each template will result in an accounting entry AccountingEntry entry = new AccountingEntry(); entry.AccountingEntryTemplateID = template.AccountingEntryTemplateID; DeepBlue.Models.Accounting.Enums.AccountingEntryAmountType amountType = (DeepBlue.Models.Accounting.Enums.AccountingEntryAmountType)template.AccountingEntryAmountTypeID; switch (amountType) { case DeepBlue.Models.Accounting.Enums.AccountingEntryAmountType.FixedAmount: entry.Amount = Convert.ToDecimal(template.AccountingEntryAmountTypeData); break; case DeepBlue.Models.Accounting.Enums.AccountingEntryAmountType.Percentage: decimal percent = Convert.ToDecimal(template.AccountingEntryAmountTypeData); entry.Amount = (percent * amt) / 100; break; case DeepBlue.Models.Accounting.Enums.AccountingEntryAmountType.Field: // Use reflection to get the amount PropertyInfo property = accountableItem.GetType().GetProperties().Where(x => x.Name == template.AccountingEntryAmountTypeData).FirstOrDefault(); object val = property.GetValue(accountableItem, null); if (val != null) { entry.Amount = Convert.ToDecimal(val); } break; case DeepBlue.Models.Accounting.Enums.AccountingEntryAmountType.Custom: break; default: entry.Amount = amt; break; } entry.TraceID = accountableItem.TraceID; entry.AttributedTo = accountableItem.AttributedTo; entry.AttributedToName = accountableItem.AttributedToName; entry.AttributedToType = accountableItem.AttributedToType; entry.FundID = fundID; entry.EntityID = entityID; context.AccountingEntries.AddObject(entry); context.SaveChanges(); } } }
public void AddAccount(IAccountable newAccount) { accounts.Add(newAccount); }
public void AddAccount(IAccountable newAccount) { AccountList.Add(newAccount); }
public void AddAccount(IAccountable newAccount) { customerAccounts.Add(newAccount); }