public Transaction Copy() { lock (this.lockMutex) { var tNew = new Transaction(this.TransactionId, this.BaseSecurity); using (var tLock = tNew.Lock()) { tNew.SetDate(this.Date, tLock); foreach (var split in this.splits) { var sNew = tNew.AddSplit(tLock); sNew.SetAccount(split.Account, tLock); sNew.SetAmount(split.Amount, tLock); sNew.SetDateCleared(split.DateCleared, tLock); sNew.SetIsReconciled(split.IsReconciled, tLock); sNew.SetSecurity(split.Security, tLock); sNew.SetTransactionAmount(split.TransactionAmount, tLock); } } return tNew; } }
public void AddTransaction(TransactionData transaction) { lock (this) { var baseSecurity = this.destinationBook.Securities.Where(s => s.SecurityId == transaction.BaseSecurityId).Single(); var newTransaction = new Transaction( transaction.TransactionId, baseSecurity); using (var tlock = newTransaction.Lock()) { newTransaction.SetDate(transaction.Date, tlock); foreach (var split in transaction.Splits) { var newSplit = newTransaction.AddSplit(tlock); var account = this.destinationBook.Accounts.Where(a => a.AccountId == split.AccountId).Single(); var security = this.destinationBook.Securities.Where(s => s.SecurityId == split.SecurityId).Single(); newSplit.SetAccount(account, tlock); newSplit.SetSecurity(security, tlock); newSplit.SetAmount(split.Amount, tlock); newSplit.SetTransactionAmount(split.TransactionAmount, tlock); newSplit.SetDateCleared(split.DateCleared, tlock); newSplit.SetIsReconciled(split.IsReconciled, tlock); } } this.destinationBook.AddTransaction( newTransaction); } }