Exemple #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();
        }
Exemple #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);
        }
Exemple #3
0
        /// <summary>
        /// Commit the new link to the database.
        /// </summary>
        /// <param name="parent">The parent folder.</param>
        /// <param name="child">The child folder.</param>
        private void Commit(Entity parent, Entity child)
        {
            try
            {
                TradingSupportClient      client   = new TradingSupportClient(Properties.Settings.Default.TradingSupportEndpoint);
                MethodResponseArrayOfguid response = client.CreateEntityTree(new EntityTree[] { new EntityTree()
                                                                                                {
                                                                                                    ChildId = child.EntityId, ParentId = parent.EntityId
                                                                                                } });

                if (!response.IsSuccessful)
                {
                    if (response.Errors.Length > 0)
                    {
                        GuardianObject.ThrowErrorInfo(response.Errors[0]);
                    }
                    else
                    {
                        Application.Current.Dispatcher.BeginInvoke(new WaitCallback(data =>
                                                                                    MessageBox.Show(
                                                                                        Application.Current.MainWindow,
                                                                                        String.Format(FluidTrade.Guardian.Properties.Resources.LinkFolderFailed, data),
                                                                                        Application.Current.MainWindow.Title)),
                                                                   DispatcherPriority.Normal,
                                                                   child);
                    }
                }

                client.Close();
            }
            catch (FaultException <RecordExistsFault> exception)
            {
                EventLog.Warning("{0}: {1}\n{2}", exception.GetType(), exception.Message, exception.StackTrace);
                Application.Current.Dispatcher.BeginInvoke(new WaitCallback(data =>
                                                                            MessageBox.Show(
                                                                                Application.Current.MainWindow,
                                                                                String.Format(FluidTrade.Guardian.Properties.Resources.LinkFolderFailedRecordExists, data),
                                                                                Application.Current.MainWindow.Title)),
                                                           DispatcherPriority.Normal,
                                                           child);
            }
            catch (Exception exception)
            {
                EventLog.Error("{0}: {1}\n{2}", exception.GetType(), exception.Message, exception.StackTrace);
                Application.Current.Dispatcher.BeginInvoke(new WaitCallback(data =>
                                                                            MessageBox.Show(
                                                                                Application.Current.MainWindow,
                                                                                String.Format(FluidTrade.Guardian.Properties.Resources.LinkFolderFailed, data),
                                                                                Application.Current.MainWindow.Title)),
                                                           DispatcherPriority.Normal,
                                                           child);
            }
        }
Exemple #4
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.");
                }
            }
        }
Exemple #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="consumerTrusts"></param>
        /// <returns></returns>
        public static MethodResponseArrayOfguid CreateReport(Report[] reports)
        {
            MethodResponseArrayOfguid response = null;
            // Update the database.
            TradingSupportClient tradingSupportClient = new TradingSupportClient(Guardian.Properties.Settings.Default.TradingSupportEndpoint);

            try
            {
                response = tradingSupportClient.CreateReport(reports);
            }
            catch (Exception exception)
            {
                // Any issues trying to communicate to the server are logged.
                EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace);
            }
            finally
            {
                if (tradingSupportClient != null && tradingSupportClient.State == CommunicationState.Opened)
                {
                    tradingSupportClient.Close();
                }
            }
            return(response);
        }