CertificatePreferenceService¶
Manages per-policy certificate delivery preferences (delivery method, renewal notification type, email address, fax number) by reading and writing CertData.CertificatePreference records through IUnitOfWork, validating edits via IValidationService, and gating writes with an IUserProfileService-resolved current-user authorization check. It is consumed by CertificateService.SetCertificateBatchPrintStatus to decide certificate-holder/policyholder mail distribution status.
Purpose¶
- Retrieves a single policy's certificate preference (mapped to the
CertificatePreferencecontract, including converting the stored fax number into aPhoneNumber) or preferences for a batch of policy numbers. - Creates a new certificate preference for a policy, or updates an existing one, both after validating the edit DTO and confirming the current user is authorized to update preferences.
- Reports whether a policy already has a stored preference, and whether the current user is authorized to save preferences at all.
Context¶
- Namespace:
SAIF.Services.Policies.Certificates - Assembly/package:
SAIF.Services(packaged inside theSAIF.SAIFCode.CoreNuGet package).
Public members¶
| Member | Signature | Purpose |
|---|---|---|
| CertificatePreferenceService (constructor) | public CertificatePreferenceService(IUnitOfWork unitOfWork, IValidationService validationService, IUserProfileService userProfileService) |
Wires the unit of work, validation service, and user-profile service used by every preference read/write operation. |
| GetPreference | public CertificatePreference GetPreference(long policyNumber) |
Loads the policy's stored certificate preference and maps it to the CertificatePreference contract, or throws CertificateServiceException if none exists. |
| GetPreferences | public IEnumerable<CertificatePreference> GetPreferences(List<long> policyNumberList) |
Returns the mapped certificate preferences for every policy number in the supplied list. |
| AddPreference | public void AddPreference(long policyNumber, CertificatePreferenceEdit certificatePreferenceEdit) |
Validates the current user's authorization and the edit DTO, then creates and persists a new CertData.CertificatePreference for the policy with create/update user and timestamp set to the current user and time, committing the transaction. |
| SavePreference | public void SavePreference(long policyNumber, CertificatePreferenceEdit certificatePreferenceEdit) |
Validates the current user's authorization and the edit DTO, then loads the policy's existing preference, applies the edit's field changes, updates the update-user/date, and commits the transaction. |
| HasPreference | public bool HasPreference(long policyNumber) |
Returns whether any stored CertificatePreference record exists for the policy number. |
| HasSecurityToSavePreference | public bool HasSecurityToSavePreference() |
Returns whether the current user holds the Preference, PreferenceExternal, or "Certs" authorization resource, i.e. can save preferences at all. |
Behavioral notes¶
- A static constructor registers an AutoMapper mapping from
CertData.CertificatePreferencetoCertificatePreference, resolving theFaxproperty from the storedFaxNumberstring viaPhoneNumber, once per process. AddPreferencewraps its repository insert inunitOfWork.Begin()/unitOfWork.Commit();SavePreferencewraps its lookup-and-update inunitOfWork.Begin()/unitOfWork.Commit()as well.GetPreferenceByPolicyNumbercatchesInvalidOperationExceptionfrom aSingle()lookup and rethrows asCertificateServiceException("Error: Preference not found.").ValidateCertificatePreferenceEditthrowsSaifValidationExceptionwhenIValidationService.Validatereports the edit DTO invalid.ValidateUserCanUpdatePreferencethrowsCertificateServiceException("Error: You are not authorized to update preferences")when the current user lacks thePreference/PreferenceExternal/"Certs"authorization resource.MapContractToDataObjectisinternal static, converting the edit DTO'sDeliveryMethodandRenewalNotificationTypeenums to their data-layer equivalents, copying the email address, and setting the fax number only when a non-nullFaxvalue is supplied.*
Constraints and usage notes¶
- All three constructor parameters (
unitOfWork,validationService,userProfileService) are null-checked viaEnforce.ArgumentNotNull. AddPreferencesetsCreateUser/UpdateUserto the current user's uppercased user ID, whileSavePreferencesetsUpdateUserto the non-uppercased user ID — an inconsistency in casing between the two write paths.*- Both
AddPreferenceandSavePreferencerequire the current user to passValidateUserCanUpdatePreferencebefore any data is written, regardless of whether the caller already checkedHasSecurityToSavePreference.*
Note: Statements marked with * were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts. Statements marked with ** could not be confirmed; treat as unknown until verified.
Sources¶
Services/SAIF.Services/Policies/Certificates/CertificatePreferenceService.cs