/// <summary> /// Delete a debt holder /// </summary> /// <returns>True for sucess</returns> public override ErrorCode Delete(ConsumerTrust record) { DataModel dataModel = new DataModel(); DataModelTransaction transaction = DataModelTransaction.Current; if (record.RowId == null || DataModel.ConsumerTrust.ConsumerTrustKey.Find(record.RowId) == null) { return(ErrorCode.RecordNotFound); } ConsumerTrustRow consumerTrust = DataModel.ConsumerTrust.ConsumerTrustKey.Find(record.RowId); consumerTrust.AcquireReaderLock(transaction); Guid debtId = consumerTrust.ConsumerTrustId; ConsumerRow consumer = consumerTrust.ConsumerRow; DebtRuleRow debtRule = consumerTrust.DebtRuleRow; consumerTrust.ReleaseReaderLock(transaction.TransactionId); #if false // If we switch from explicitly deleting the working order to explicitly deleting the security, then we need this. if (!TradingSupport.HasAccess(transaction, debtId, AccessRight.Write)) { return(ErrorCode.AccessDenied); } #endif consumerTrust.AcquireWriterLock(transaction); if (consumerTrust.RowState != DataRowState.Deleted && consumerTrust.RowState != DataRowState.Detached) { dataModel.DestroyConsumerTrust(new object[] { consumerTrust.ConsumerTrustId }, record.RowVersion); } consumerTrust.ReleaseWriterLock(transaction.TransactionId); consumer.AcquireWriterLock(transaction); if (consumer.RowState != DataRowState.Deleted && consumer.RowState != DataRowState.Detached) { dataModel.DestroyConsumer(new object[] { consumer.ConsumerId }, consumer.RowVersion); } consumer.ReleaseWriterLock(transaction.TransactionId); if (debtRule != null) { debtRule.AcquireReaderLock(transaction); if (debtRule.RowState != DataRowState.Deleted && debtRule.RowState != DataRowState.Detached && debtRule.GetDebtRuleMapRows().Length == 0) { DebtRulePersistence debtRulePersistence = new DebtRulePersistence(); Guid debtRuleId = debtRule.DebtRuleId; long rowVersion = debtRule.RowVersion; debtRule.ReleaseReaderLock(transaction.TransactionId); debtRulePersistence.Delete(new Records.DebtRule { RowId = debtRuleId, RowVersion = rowVersion }); } else { debtRule.ReleaseReaderLock(transaction.TransactionId); } } return(ErrorCode.Success); }
/// <summary> /// Delete a debt holder /// </summary> /// <returns>True for sucess</returns> public override ErrorCode Delete(DebtNegotiator record) { DataModel dataModel = new DataModel(); DataModelTransaction transaction = DataModelTransaction.Current; WorkingOrderPersistence workingOrderPersistence = new WorkingOrderPersistence(); DebtRulePersistence debtRulePersistence = new DebtRulePersistence(); DebtNegotiatorRow debtNegotiatorRow = DataModel.DebtNegotiator.DebtNegotiatorKey.Find(record.RowId); // If/when we get these translations, we'll need this stuff. //DebtNegotiatorImportTranslationRow debtNegotiatorImportTranslationRow; DebtClassRow debtClassRow; BlotterRow blotterRow; WorkingOrderRow[] workingOrderRows; DebtRuleMapRow[] debtRuleMapRows; EntityRow entityRow; EntityTreeRow[] children; Guid entityId; Int64 entityRowVersion; //Guid debtNegotiatorImportTranslationId = Guid.Empty; //Int64 debtNegotiatorImportTranslationRowVersion = 0; if (record.RowId == null || debtNegotiatorRow == null) { return(ErrorCode.RecordNotFound); } if (!DataModelFilters.HasAccess(transaction, TradingSupport.UserId, record.RowId, AccessRight.Write)) { return(ErrorCode.AccessDenied); } debtNegotiatorRow.AcquireReaderLock(transaction); debtClassRow = debtNegotiatorRow.DebtClassRow; //debtNegotiatorImportTranslationRow = debtNegotiatorRow.DebtNegotiatorImportTranslationRow; debtNegotiatorRow.ReleaseReaderLock(transaction.TransactionId); #if false // If/when we get these translations, we'll need this stuff. if (debtHolderImportTranslationRow != null) { debtNegotiatorImportTranslationRow.AcquireReaderLock(transaction); debtNegotiatorImportTranslationId = debtNegotiatorImportTranslationRow.DebtNegotiatorImportTranslationId; debtNegotiatorImportTranslationRowVersion = debtNegotiatorImportTranslationRow.RowVersion; debtNegotiatorImportTranslationRow.ReleaseReaderLock(transaction.TransactionId); } #endif debtClassRow.AcquireReaderLock(transaction); blotterRow = debtClassRow.BlotterRow; debtRuleMapRows = debtClassRow.GetDebtRuleMapRows(); debtClassRow.ReleaseReaderLock(transaction.TransactionId); blotterRow.AcquireReaderLock(transaction); entityRow = blotterRow.EntityRow; workingOrderRows = blotterRow.GetWorkingOrderRows(); blotterRow.ReleaseLock(transaction.TransactionId); entityRow.AcquireReaderLock(transaction); children = entityRow.GetEntityTreeRowsByFK_Entity_EntityTree_ParentId(); entityId = entityRow.EntityId; entityRowVersion = entityRow.RowVersion; entityRow.ReleaseReaderLock(transaction.TransactionId); // Fail if the debt class has any children. if (children.Length != 0) { return(ErrorCode.AccessDenied); } // Destroy the import translation. //if (debtHolderImportTranslationRow != null) // dataModel.DestroyDebtNegotiatorImportTranslation(new object[] { debtNegotiatorImportTranslationId }, debtNegotiatorImportTranslationRowVersion); // Delete any rules this debt class may own. foreach (DebtRuleMapRow debtRuleMapRow in debtRuleMapRows) { DebtRuleRow debtRuleRow; debtRuleMapRow.AcquireReaderLock(transaction); debtRuleRow = debtRuleMapRow.DebtRuleRow; debtRuleMapRow.ReleaseReaderLock(transaction.TransactionId); debtRulePersistence.DeleteRow(dataModel, transaction, debtRuleRow); } // Delete any working orders this debt class may contain. foreach (WorkingOrderRow workingOrderRow in workingOrderRows) { workingOrderPersistence.DeleteRow(dataModel, transaction, workingOrderRow); } // Delete the entity itself. dataModel.DestroyEntity(new object[] { entityId }, entityRowVersion); return(ErrorCode.Success); }