示例#1
0
        /// <summary>
        /// Commit changes or create a new rule.
        /// </summary>
        /// <param name="tradingSupport">The trading support client.</param>
        /// <param name="owner">The debt class that owns the rule.</param>
        private void CommitModified(TradingSupportClient tradingSupport, Guid owner)
        {
            Guid[] paymentMethod = new Guid[this.PaymentMethod.Count];

            this.PaymentMethod.CopyTo(paymentMethod, 0);

            if (this.DebtRuleId != null)
            {
                TradingSupportReference.MethodResponseErrorCode response = tradingSupport.UpdateDebtRule(new TradingSupportReference.DebtRule[] { new TradingSupportReference.DebtRule()
                                                                                                                                                  {
                                                                                                                                                      IsAutoSettled          = this.IsAutoSettled,
                                                                                                                                                      Name                   = this.Name,
                                                                                                                                                      Owner                  = owner,
                                                                                                                                                      PaymentLength          = this.PaymentLength,
                                                                                                                                                      PaymentMethod          = paymentMethod,
                                                                                                                                                      PaymentStartDateLength = this.PaymentStartDateLength,
                                                                                                                                                      PaymentStartDateUnitId = this.PaymentStartDateUnitId,
                                                                                                                                                      RowId                  = this.DebtRuleId.Value,
                                                                                                                                                      RowVersion             = this.RowVersion,
                                                                                                                                                      SettlementUnitId       = this.settlementUnitId,
                                                                                                                                                      SettlementValue        = this.SettlementValue
                                                                                                                                                  } });

                if (!response.IsSuccessful && (response.Errors.Length == 0 || response.Errors[0].ErrorCode != ErrorCode.Deadlock))
                {
                    GuardianObject.ThrowErrorInfo(response.Errors[0]);
                }
            }
            else
            {
                MethodResponseArrayOfguid guids = tradingSupport.CreateDebtRule(new TradingSupportReference.DebtRule[] { new TradingSupportReference.DebtRule()
                                                                                                                         {
                                                                                                                             IsAutoSettled          = this.isAutoSettled,
                                                                                                                             Name                   = this.Name,
                                                                                                                             Owner                  = owner,
                                                                                                                             PaymentLength          = this.PaymentLength,
                                                                                                                             PaymentMethod          = paymentMethod,
                                                                                                                             PaymentStartDateLength = this.PaymentStartDateLength,
                                                                                                                             PaymentStartDateUnitId = this.PaymentStartDateUnitId,
                                                                                                                             SettlementUnitId       = this.settlementUnitId,
                                                                                                                             SettlementValue        = this.SettlementValue
                                                                                                                         } });

                if (guids.IsSuccessful)
                {
                    this.DebtRuleId = guids.Result[0];
                }
                else
                {
                    throw new Exception("Failed to create debt rule.");
                }
            }
        }