示例#1
0
        /// <summary>
        /// Commit any changes to the debt class to the server.
        /// </summary>
        protected override void CommitDebtClass()
        {
            TradingSupportClient tradingSupportClient = new TradingSupportClient(Guardian.Properties.Settings.Default.TradingSupportEndpoint);

            TradingSupportReference.DebtNegotiator record = new TradingSupportReference.DebtNegotiator();

            this.PopulateRecord(record);

            if (this.EntityId == Guid.Empty)
            {
                MethodResponseArrayOfguid response = tradingSupportClient.CreateDebtNegotiator(new TradingSupportReference.DebtNegotiator[] { record });

                if (!response.IsSuccessful)
                {
                    Entity.ThrowErrorInfo(response.Errors[0]);
                }
            }
            else
            {
                MethodResponseErrorCode response = tradingSupportClient.UpdateDebtNegotiator(new TradingSupportReference.DebtNegotiator[] { record });

                if (!response.IsSuccessful)
                {
                    Entity.ThrowErrorInfo(response.Errors[0]);
                }
            }

            tradingSupportClient.Close();
        }
示例#2
0
        /// <summary>
        /// Create a new DebtNegotiator in the data model.
        /// </summary>
        /// <param name="dataModel">The data model client to create the negotiator with.</param>
        /// <param name="typeId">The type-id of the DebtNegotiator type.</param>
        /// <param name="parentId">The entityId of the parent entity.</param>
        /// <param name="tenantId"></param>
        /// <returns>The entity-id of the new debt negotiator.</returns>
        public static new Guid Create(DataModelClient dataModel, Guid typeId, Guid parentId, Guid tenantId)
        {
            Guid entityId = Guid.Empty;
            TradingSupportClient tradingSupportClient = new TradingSupportClient(Guardian.Properties.Settings.Default.TradingSupportEndpoint);

            try
            {
                TradingSupportReference.DebtNegotiator record = new TradingSupportReference.DebtNegotiator();

                lock (DataModel.SyncRoot)
                {
                    DebtClassRow parent = DataModel.DebtClass.DebtClassKey.Find(parentId);

                    record.ConfigurationId = "Default";
                    record.Name            = "New Debt Negotiator";
                    record.ParentId        = parentId;
                    record.TenantId        = tenantId;

                    if (parent != null)
                    {
                        record.Address1          = parent.IsAddress1Null() ? null : parent.Address1;
                        record.Address2          = parent.IsAddress2Null() ? null : parent.Address2;
                        record.BankAccountNumber = parent.IsBankAccountNumberNull() ? null : parent.BankAccountNumber;
                        record.BankRoutingNumber = parent.IsBankRoutingNumberNull() ? null : parent.BankRoutingNumber;
                        record.City         = parent.IsCityNull() ? null : parent.City;
                        record.CompanyName  = parent.IsCompanyNameNull() ? null : parent.CompanyName;
                        record.ContactName  = parent.IsContactNameNull() ? null : parent.ContactName;
                        record.Department   = parent.IsDepartmentNull() ? null : parent.Department;
                        record.Email        = parent.IsEmailNull() ? null : parent.Email;
                        record.Fax          = parent.IsFaxNull() ? null : parent.Fax;
                        record.ForBenefitOf = parent.IsForBenefitOfNull() ? null : parent.ForBenefitOf;
                        record.Phone        = parent.IsPhoneNull() ? null : parent.Phone;
                        record.PostalCode   = parent.IsPostalCodeNull() ? null : parent.PostalCode;
                        record.Province     = parent.IsProvinceIdNull() ? null : (Guid?)parent.ProvinceId;
                    }
                }

                MethodResponseArrayOfguid response = tradingSupportClient.CreateDebtNegotiator(new TradingSupportReference.DebtNegotiator[] { record });
                if (response.IsSuccessful)
                {
                    entityId = response.Result[0];
                }
                else
                {
                    throw new Exception(String.Format("Server error: {0}, {1}", response.Errors[0].ErrorCode, response.Errors[0].Message));
                }
            }
            catch (Exception exception)
            {
                // Any issues trying to communicate to the server are logged.
                EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace);
                throw;
            }
            finally
            {
                if (tradingSupportClient != null && tradingSupportClient.State == CommunicationState.Opened)
                {
                    tradingSupportClient.Close();
                }
            }

            return(entityId);
        }