public override void Update(DebtRule record) { DataModel dataModelClient = new DataModel(); DataModelTransaction transaction = DataModelTransaction.Current; DebtRuleRow debtRuleRow = DataModel.DebtRule.DebtRuleKey.Find(record.RowId); DebtRuleMapRow[] debtRuleMapRows; List <Guid> paymentMethod = record.PaymentMethod.ToList(); if (record.RowId == null || debtRuleRow == null) { throw new FaultException <RecordNotFoundFault>(new RecordNotFoundFault("DebtRule", new object[] { record.RowId }), "DebtRule could not be found"); } debtRuleRow.AcquireReaderLock(transaction); debtRuleMapRows = debtRuleRow.GetDebtRuleMapRows(); // There really should be at most one of these, but there may be none. foreach (DebtRuleMapRow debtRuleMapRow in debtRuleMapRows) { debtRuleMapRow.AcquireReaderLock(transaction); if (!DataModelFilters.HasAccess(transaction, TradingSupport.UserId, debtRuleMapRow.DebtClassId, AccessRight.Write)) { throw new SecurityAccessDeniedException("Current user does not have right access to the debt class that owns this debt rule"); } debtRuleMapRow.ReleaseLock(transaction.TransactionId); } foreach (DebtRulePaymentMethodRow methodRow in debtRuleRow.GetDebtRulePaymentMethodRows()) { methodRow.AcquireReaderLock(transaction); if (paymentMethod.Contains(methodRow.PaymentMethodTypeId)) { paymentMethod.Remove(methodRow.PaymentMethodTypeId); } else { dataModelClient.DestroyDebtRulePaymentMethod(new object[] { methodRow.DebtRulePaymentMethodId }, methodRow.RowVersion); } methodRow.ReleaseLock(transaction.TransactionId); } foreach (Guid method in paymentMethod) { dataModelClient.CreateDebtRulePaymentMethod(record.RowId, Guid.NewGuid(), method); } debtRuleRow.ReleaseLock(transaction.TransactionId); dataModelClient.UpdateDebtRule( null, new object[] { record.RowId }, null, record.IsAutoSettled, record.Name, record.PaymentLength, record.PaymentStartDateLength, record.PaymentStartDateUnitId, record.RowVersion, record.SettlementUnitId, record.SettlementValue); debtRuleRow.ReleaseLock(transaction.TransactionId); }