/// <summary>
        /// Create a new Consumer Trust record.
        /// </summary>
        /// <returns></returns>
        public override Guid Create(ConsumerTrust record)
        {
            DataModel dataModel       = new DataModel();
            Guid      consumerTrustId = Guid.NewGuid();

            DataModelTransaction dataModelTransaction = DataModelTransaction.Current;

            ////Create a entry in credit card
            dataModel.CreateConsumerTrust(
                record.ConsumerId.GetValueOrDefault(),
                consumerTrustId,
                record.DebtRuleId,
                record.ExternalId0,
                record.SavingsAccount,
                record.SavingsBalance,
                record.Tag,
                record.TenantId,
                record.VendorCode);

            return(consumerTrustId);
        }
        /// <summary>
        /// Create a new consumer.
        /// </summary>
        /// <returns>The ConsumerId of the consumer.</returns>
        private Guid CreateConsumer()
        {
            DataModel            dataModel            = new DataModel();
            DataModelTransaction dataModelTransaction = DataModelTransaction.Current;
            Guid       userId         = TradingSupport.UserId;
            Guid       tenantId       = PersistenceHelper.GetTenantForEntity(DataModelTransaction.Current, this.Record.Blotter);
            Guid       entityId       = Guid.NewGuid();
            Guid       consumerId     = Guid.NewGuid();
            Guid       creditCardId   = Guid.NewGuid();
            Guid       workingOrderId = Guid.NewGuid();
            CountryRow country;
            Guid       countryId;
            Guid?      provinceId = null;
            EntityRow  dollars;
            Guid       dollarsId;
            TypeRow    type;
            Guid       typeId;
            ImageRow   image;
            Guid       imageId;
            DateTime   currentUTCTime = DateTime.UtcNow;

            country = TradingSupport.FindCountryByKey(
                this.Record.ConfigurationId,
                "FK_Country_Security",
                new object[] { this.Record.CountryCode });
            countryId = country.CountryId;
            country.ReleaseReaderLock(dataModelTransaction.TransactionId);

            if (this.Record.ProvinceCode != null)
            {
                ProvinceRow province = TradingSupport.FindProvinceByKey(
                    this.Record.ConfigurationId,
                    "FK_Province_Consumer",
                    new object[] { this.Record.ProvinceCode });
                provinceId = province.ProvinceId;
                province.ReleaseReaderLock(dataModelTransaction.TransactionId);
            }

            dollars = TradingSupport.FindEntityByKey(
                this.Record.ConfigurationId,
                "FK_Security_WorkingOrder_SettlementId",
                new object[] { this.Record.Currency });
            dollarsId = dollars.EntityId;
            dollars.ReleaseReaderLock(dataModelTransaction.TransactionId);

            image = TradingSupport.FindImageByKey(
                this.Record.ConfigurationId,
                "FK_Image_Entity",
                new object[] { "OBJECT" });
            imageId = image.ImageId;
            image.ReleaseReaderLock(dataModelTransaction.TransactionId);

            type = TradingSupport.FindTypeByKey(
                this.Record.ConfigurationId,
                "FK_Type_Entity",
                new object[] { "CONSUMER TRUST" });
            typeId = type.TypeId;
            type.ReleaseReaderLock(dataModelTransaction.TransactionId);

            dataModel.CreateEntity(
                currentUTCTime,
                null,
                entityId,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                this.Record.CustomerCode,
                imageId,
                false,
                false,
                currentUTCTime,
                this.Record.SavingsEntityCode,
                tenantId,
                typeId);

            dataModel.CreateSecurity(
                null,
                countryId,
                null,
                null,
                null,
                1,
                1,
                entityId,
                this.Record.AccountCode,
                tenantId,
                VolumeCategoryMap.FromCode(VolumeCategory.Unknown));

            dataModel.CreateConsumer(
                this.Record.Address1,
                this.Record.Address2,
                this.Record.BankAccountNumber,
                this.Record.BankRoutingNumber,
                this.Record.City,
                consumerId,
                this.Record.DateOfBirth != null ? (object)this.Record.DateOfBirth.Value : null,
                null,
                null,
                this.Record.FirstName,
                this.Record.IsEmployed != null ? (object)this.Record.IsEmployed.Value : null,
                this.Record.LastName,
                this.Record.MiddleName,
                StringUtilities.CleanUpAlphaNumericString(this.Record.PhoneNumber),
                this.Record.PostalCode,
                provinceId,
                this.Record.Salutation,
                StringUtilities.CleanUpAlphaNumericString(this.Record.SocialSecurityNumber),
                this.Record.Suffix);
            dataModel.CreateConsumerTrust(
                consumerId,
                entityId,
                null,
                null,
                this.Record.SavingsAccount,
                this.Record.SavingsBalance,
                this.Record.Tag,
                tenantId,
                this.Record.VendorCode);

            //If this not found, there will be an exception. Let the exception propagate up.
            dataModel.CreateWorkingOrder(
                null,
                this.Record.Blotter,
                currentUTCTime,
                userId,
                CrossingMap.FromCode(Crossing.AlwaysMatch),
                null,
                null,
                null,
                null,
                true,
                true,
                true,
                null,
                DateTime.UtcNow,
                TradingSupport.UserId,
                OrderTypeMap.FromCode(OrderType.Market),
                entityId,
                DateTime.UtcNow,
                dollarsId,
                SideMap.FromCode(Side.Sell),
                DateTime.UtcNow,
                StatusMap.FromCode(Status.New),
                null,
                null,
                null,
                null,
                TimeInForceMap.FromCode(TimeInForce.GoodTillCancel),
                DateTime.UtcNow,
                DateTime.UtcNow,
                workingOrderId);

            // Create the access control record for this new entity.
            dataModel.CreateAccessControl(
                Guid.NewGuid(),
                AccessRightMap.FromCode(AccessRight.FullControl),
                entityId,
                userId,
                tenantId);

            return(consumerId);
        }