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); }
/// <summary> /// Create a new DebtRule /// </summary> /// <returns></returns> public override Guid Create(DebtRule record) { DataModel dataModelClient = new DataModel(); Guid debtRuleId = Guid.NewGuid(); // These fields are required by this method, but not by the record itself, so bark if they're missing. if (record.IsAutoSettled == null) { throw new FaultException("IsAutoSettled cannot be null"); } if (record.Owner == null) { throw new FaultException("Owner cannot be null"); } if (record.PaymentLength == null) { throw new FaultException("PaymentLength cannot be null"); } if (record.PaymentMethod == null) { throw new FaultException("SettlementValue cannot be null"); } if (record.PaymentStartDateLength == null) { throw new FaultException("PaymentStartDateLength cannot be null"); } if (record.PaymentStartDateUnitId == null) { throw new FaultException("PaymentStartDateUnitId cannot be null"); } if (record.SettlementUnitId == null) { throw new FaultException("SettlementUnitId cannot be null"); } if (record.SettlementValue == null) { throw new FaultException("SettlementValue cannot be null"); } if (!DataModelFilters.HasAccess(DataModelTransaction.Current, TradingSupport.UserId, record.Owner.Value, AccessRight.Write)) { throw new SecurityAccessDeniedException("Current user does not have right access to the debt class that would own this debt rule"); } dataModelClient.CreateDebtRule( debtRuleId, null, record.IsAutoSettled, record.Name, record.PaymentLength.Value, record.PaymentStartDateLength.Value, record.PaymentStartDateUnitId.Value, record.SettlementUnitId.Value, record.SettlementValue.Value); dataModelClient.CreateDebtRuleMap(record.Owner.Value, debtRuleId, Guid.NewGuid(), null); foreach (Guid paymentMethod in record.PaymentMethod) { dataModelClient.CreateDebtRulePaymentMethod(debtRuleId, Guid.NewGuid(), paymentMethod); } return(debtRuleId); }