Last active
November 12, 2019 20:22
-
-
Save bradirby/f51a0e9f4cf0792ff7c55ff7de0245ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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