/// <summary>
        /// Create a new working order.
        /// </summary>
        /// <param name="workingOrderRow">The WorkingOrderRow of the working order.</param>
        public ConsumerDebtWorkingOrder(WorkingOrderRow workingOrderRow)
            : base(workingOrderRow)
        {
            SecurityRow     securityRow     = workingOrderRow.SecurityRowByFK_Security_WorkingOrder_SecurityId;
            ConsumerDebtRow consumerDebtRow = securityRow.GetConsumerDebtRows()[0];
            ConsumerRow     consumerRow     = consumerDebtRow.ConsumerRow;

            this.consumerDebtRowVersion = consumerDebtRow.RowVersion;
            this.firstName            = consumerRow.IsFirstNameNull() ? null : consumerRow.FirstName;
            this.lastName             = consumerRow.IsLastNameNull() ? null : consumerRow.LastName;
            this.socialSecurityNumber = consumerRow.SocialSecurityNumber;
        }
        /// <summary>
        /// Count all of the working orders and matches in blotters below the parent entity. The caller should lock the DataModel.
        /// </summary>
        /// <param name="parent">The parent entity.</param>
        /// <param name="matchedDollars">The total face value of the valid matches. Should initially be 0.0.</param>
        /// <param name="totalDollars">The total face value of all the records. Should initially be 0.0.</param>
        /// <param name="totalRecords">The total number of records. Should initially be 0.</param>
        /// <param name="matchedRecords">The number of of valid matches. Should initially be 0.</param>
        private void CountChildMoney(EntityRow parent, ref decimal matchedDollars, ref decimal totalDollars, ref int totalRecords, ref int matchedRecords)
        {
            BlotterRow blotter = DataModel.Blotter.BlotterKey.Find(parent.EntityId);

            if (blotter != null)
            {
                MatchRow[]        matches = blotter.GetMatchRows();
                WorkingOrderRow[] orders  = blotter.GetWorkingOrderRows();

                matchedRecords += matches.Length;
                totalRecords   += orders.Length;

                // Count up the match/match with funds credit card balances.
                foreach (MatchRow match in matches)
                {
                    if (match.StatusRow.StatusCode == Status.ValidMatch || match.StatusRow.StatusCode == Status.ValidMatchFunds)
                    {
                        Guid security = match.WorkingOrderRow.SecurityId;
                        matchedDollars += DataModel.ConsumerDebt.ConsumerDebtKey.Find(security).CreditCardRow.AccountBalance;
                    }
                }

                // Count up the credit card balances of _everything_, matched or not.
                foreach (WorkingOrderRow order in orders)
                {
                    Guid            security = order.SecurityId;
                    ConsumerDebtRow debt     = DataModel.ConsumerDebt.ConsumerDebtKey.Find(security);

                    if (debt != null)
                    {
                        totalDollars += debt.CreditCardRow.AccountBalance;
                    }
                }
            }

            // Do the same for all of the blotters under this one.
            foreach (EntityTreeRow tree in DataModel.EntityTree)
            {
                if (tree.ParentId == parent.EntityId)
                {
                    this.CountChildMoney(tree.EntityRowByFK_Entity_EntityTree_ChildId, ref matchedDollars, ref totalDollars, ref totalRecords, ref matchedRecords);
                }
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="row"></param>
 public ConsumerDebt(ConsumerDebtRow row)
 {
     this.RowId      = row.ConsumerDebtId;
     this.RowVersion = row.RowVersion;
     this.TenantId   = row.TenantId;
 }