Exemple #1
0
        /// <summary>
        /// Delete a debt holder
        /// </summary>
        /// <returns>True for sucess</returns>
        public override ErrorCode Delete(ConsumerDebt record)
        {
            DataModel            dataModel   = new DataModel();
            DataModelTransaction transaction = DataModelTransaction.Current;

            if (record.RowId == null || DataModel.ConsumerDebt.ConsumerDebtKey.Find(record.RowId) == null)
            {
                return(ErrorCode.RecordNotFound);
            }

            ConsumerDebtRow consumerDebt = DataModel.ConsumerDebt.ConsumerDebtKey.Find(record.RowId);

            consumerDebt.AcquireReaderLock(transaction);
            ConsumerRow   consumer;
            CreditCardRow card;
            DebtRuleRow   debtRule;

            try
            {
                Guid debtId = consumerDebt.ConsumerDebtId;
                consumer = consumerDebt.ConsumerRow;
                card     = consumerDebt.CreditCardRow;
                debtRule = consumerDebt.DebtRuleRow;
            }
            finally
            {
                consumerDebt.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

            consumerDebt.AcquireWriterLock(transaction);
            if (consumerDebt.RowState != DataRowState.Deleted && consumerDebt.RowState != DataRowState.Detached)
            {
                dataModel.DestroyConsumerDebt(new object[] { consumerDebt.ConsumerDebtId }, record.RowVersion);
            }
            consumerDebt.ReleaseWriterLock(transaction.TransactionId);

            consumer.AcquireWriterLock(transaction);
            if (consumer.RowState != DataRowState.Deleted && consumer.RowState != DataRowState.Detached && consumer.GetConsumerDebtRows().Length == 0)
            {
                dataModel.DestroyConsumer(new object[] { consumer.ConsumerId }, consumer.RowVersion);
            }
            consumer.ReleaseWriterLock(transaction.TransactionId);

            card.AcquireWriterLock(transaction);
            if (card.RowState != DataRowState.Deleted && card.RowState != DataRowState.Detached)
            {
                dataModel.DestroyCreditCard(new object[] { card.CreditCardId }, card.RowVersion);
            }
            card.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);
        }