示例#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.DebtHolder record = new TradingSupportReference.DebtHolder();

            this.PopulateRecord(record);

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

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

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

            tradingSupportClient.Close();
        }
示例#2
0
        /// <summary>
        /// Create a new DebtHolder in the data model.
        /// </summary>
        /// <param name="dataModel">The data model client to create the debt holder with.</param>
        /// <param name="typeId">The type-id of the DebtHolder type.</param>
        /// <param name="parentId">The entityId of the parent entity.</param>
        /// <param name="tenantId"></param>
        /// <returns>The entity-id of the new debt holder.</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.DebtHolder record = new TradingSupportReference.DebtHolder();

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

                    record.ConfigurationId   = "Default";
                    record.Name              = "New Debt Holder";
                    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.ParentId     = parent.DebtClassId;
                    record.Phone        = parent.IsPhoneNull()? null : parent.Phone;
                    record.PostalCode   = parent.IsPostalCodeNull()? null : parent.PostalCode;
                    record.Province     = parent.IsProvinceIdNull() ? null : (Guid?)parent.ProvinceId;
                }
                record.TenantId = tenantId;
                MethodResponseArrayOfguid response = tradingSupportClient.CreateDebtHolder(new TradingSupportReference.DebtHolder[] { 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);
        }