コード例 #1
0
        /// <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);
        }