Skip to content

Instantly share code, notes, and snippets.

@bradirby
Last active November 12, 2019 20:22
Show Gist options
  • Save bradirby/f51a0e9f4cf0792ff7c55ff7de0245ce to your computer and use it in GitHub Desktop.
Save bradirby/f51a0e9f4cf0792ff7c55ff7de0245ce to your computer and use it in GitHub Desktop.
public class Contract{
public void AddAsset(decimal assetValue, int assetType)
{
Asset a = CreateAsset(assetValue, assetType);
AddAssetToCollection(a);
Save();
}
private Asset CreateAsset(decimal assetValue, int assetType)
{
return new Asset(assetValue, assetType);
}
private void AddAssetToCollection(Asset a)
{
this.Assets.Add(a);
AccountingRules rules = this.IAccountingRulesRepo.GetByAssetID(assetType);
Account accountDebit = new Account(rules.DebitAccount);
Account accountCredit = new Account(rules.CreditAccount);
accountCredit.Credit(assetValue);
accountDebit.Debit(assetValue);
}
private void Save()
{
using (Transaction trans = this.IAccountingRulesRepo.StartTransaction())
{
try
{
this.IAccountRepo.Save(accountCredit);
this.IAccountRepo.Save(accountDebit);
trans.commit
}
except (exception e)
{
trans.rollback();
throw;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment