/// <summary> /// Find the effective (inherited) value of a column in a debt class. /// </summary> /// <typeparam name="T">The type of the column.</typeparam> /// <param name="debtClassId">The DebtClassId of the debt class in question.</param> /// <param name="field">The column to retrieve.</param> /// <returns>Effective value of the indicated column, eg. the value in the debt class with the indicated ID, or, if that debt class has no /// value for the column, the value of the column in nearest ancestor debt class that has a value for that column. If no value can be found, /// returns null.</returns> private static object FindEffectiveField <T>(Guid debtClassId, DataColumn field) { object value = null; lock (DataModel.SyncRoot) { DebtHolderRow parent = DebtHolder.FindParentWithField(debtClassId, field); if (parent != null) { value = (object)parent.Field <T>(field); } } return(value); }
/// <summary> /// Get the import translation information for this debt class. /// </summary> /// <returns></returns> public override Dictionary <String, String> GetEffectiveImportTranslation() { Dictionary <String, String> translation = new Dictionary <String, String>(); object effectiveTranslationId = DebtHolder.FindEffectiveField <Guid>(this.DebtHolderId, DataModel.DebtHolder.DebtHolderImportTranslationIdColumn); if (effectiveTranslationId != null) { DebtHolderImportTranslationRow translationRow = DataModel.DebtHolderImportTranslation.DebtHolderImportTranslationKey.Find((Guid)effectiveTranslationId); translation[translationRow.AccountBalance] = "AccountBalance"; translation[translationRow.AccountCode] = "AccountCode"; translation[translationRow.OriginalAccountNumber] = "OriginalAccountNumber"; translation[translationRow.SocialSecurityNumber] = "SocialSecurityNumber"; if (!translationRow.IsAddress1Null()) { translation[translationRow.Address1] = "Address1"; } if (!translationRow.IsAddress2Null()) { translation[translationRow.Address2] = "Address2"; } if (!translationRow.IsCityNull()) { translation[translationRow.City] = "City"; } if (!translationRow.IsDateOfBirthNull()) { translation[translationRow.DateOfBirth] = "DateOfBirth"; } if (!translationRow.IsDateOfDelinquencyNull()) { translation[translationRow.DateOfDelinquency] = "DateOfDelinquency"; } if (!translationRow.IsDebtHolderNull()) { translation[translationRow.DebtHolder] = "DebtHolder"; } if (!translationRow.IsFirstNameNull()) { translation[translationRow.FirstName] = "FirstName"; } if (!translationRow.IsLastNameNull()) { translation[translationRow.LastName] = "LastName"; } if (!translationRow.IsMiddleNameNull()) { translation[translationRow.MiddleName] = "MiddleName"; } if (!translationRow.IsPhoneNumberNull()) { translation[translationRow.PhoneNumber] = "PhoneNumber"; } if (!translationRow.IsPostalCodeNull()) { translation[translationRow.PostalCode] = "PostalCode"; } if (!translationRow.IsProvinceCodeNull()) { translation[translationRow.ProvinceCode] = "ProvinceCode"; } if (!translationRow.IsSuffixNull()) { translation[translationRow.Suffix] = "Suffix"; } if (!translationRow.IsVendorCodeNull()) { translation[translationRow.VendorCode] = "VendorCode"; } } // The default translation is the "identity" translation. else { translation["AccountBalance"] = "AccountBalance"; translation["AccountCode"] = "AccountCode"; translation["Address1"] = "Address1"; translation["Address2"] = "Address2"; translation["City"] = "City"; translation["DateOfBirth"] = "DateOfBirth"; translation["DateOfDelinquency"] = "DateOfDelinquency"; translation["DebtHolder"] = "DebtHolder"; translation["FirstName"] = "FirstName"; translation["LastName"] = "LastName"; translation["MiddleName"] = "MiddleName"; translation["OriginalAccountNumber"] = "OriginalAccountNumber"; translation["PhoneNumber"] = "PhoneNumber"; translation["PostalCode"] = "PostalCode"; translation["ProvinceCode"] = "ProvinceCode"; translation["Suffix"] = "Suffix"; translation["SocialSecurityNumber"] = "SocialSecurityNumber"; translation["VendorCode"] = "VendorCode"; } return(translation); }
/// <summary> /// Create a duplicate debt class. /// </summary> /// <param name="source">The original debt class.</param> public DebtHolder(DebtHolder source) : base(source) { this.rowVersion = source.RowVersion; }
/// <summary> /// Delete an set of debt holders. /// </summary> /// <param name="debtHolders">The set of working orders.</param> /// <returns>The actual bulk size used.</returns> protected override Int32 Delete(List <GuardianObject> debtHolders) { Int32 attemptedBulkSize = debtHolders.Count; Int32 actualBulkSize = attemptedBulkSize; GuardianObject failedObject = null; TradingSupportReference.DebtHolder[] records = new TradingSupportReference.DebtHolder[debtHolders.Count]; Dictionary <TradingSupportReference.DebtHolder, DebtHolder> recordsToHolders = new Dictionary <TradingSupportReference.DebtHolder, DebtHolder>(); // Convert the GuardianObjects to records we can push up to the server. for (Int32 index = 0; index < records.Length; ++index) { DebtHolder debtHolder = debtHolders[0] as DebtHolder; records[index] = new TradingSupportReference.DebtHolder(); debtHolder.PopulateRecord(records[index]); recordsToHolders[records[index]] = debtHolder; debtHolders.RemoveAt(0); } try { Int32 sentSize; MethodResponseErrorCode response; response = NetworkHelper.Attempt <MethodResponseErrorCode>( (client, a) => client.DeleteDebtHolder(a as TradingSupportReference.DebtHolder[]), records, true, out sentSize); if (sentSize < attemptedBulkSize) { actualBulkSize = sentSize; } if (!response.IsSuccessful) { List <TradingSupportReference.DebtHolder> retryRecords = new List <TradingSupportReference.DebtHolder>(); foreach (ErrorInfo errorInfo in response.Errors) { // The bulk index is an index into the set we sent, which may be smaller than the set passed in. failedObject = recordsToHolders[records[errorInfo.BulkIndex]]; // If the error's "just" a deadlock, we should retry it. if (errorInfo.ErrorCode == ErrorCode.Deadlock) { retryRecords.Add(records[errorInfo.BulkIndex]); } else if (errorInfo.ErrorCode == ErrorCode.RecordExists) { throw new HasSettlementsException(this.ToString() + " has settled accounts"); } // We can safely ignore not-found errors (we are deleting after all), but if the error's more severe, forget the how // thing and throw up the error. else if (errorInfo.ErrorCode != ErrorCode.RecordNotFound) { GuardianObject.ThrowErrorInfo(response.Errors[0]); } } records = retryRecords.ToArray(); } } catch (Exception exception) { // Any issues trying to communicate to the server are logged. EventLog.Error("{0}: {1}\n{2}", exception.GetType(), exception.Message, exception.StackTrace); throw new DeleteException(failedObject, exception); } return(actualBulkSize); }