Skip to content

ClaimAuthorityService

Implements IClaimAuthorityService, coordinating the creation, update, deletion, reversion, and querying of employee payment-authority limits for the Payments and Reserve business processes. It depends on IUnitOfWork for repository access and transactions, IUserProfileService for resolving the current user and looking up employees, IValidationService for FluentValidation-based edit validation, and IEnvironmentService for production-mode checks; it also statically caches the current ISaifUserProfile and calls AuthorityMappingHelper.MapTables() in its constructor to configure AutoMapper.

Purpose

  • Validates proposed payment/reserve authority-limit edits against business rules (via ClaimAuthorityValidator) before persisting them.
  • Adds new authority limits or updates existing ones, recording each change to EmployeeAuthorityPaymentLimitHistory for audit purposes.
  • Deletes or reverts expired authority limits in bulk, restoring a prior non-expiring history record when one exists.
  • Retrieves an employee's current payment and reserve authority limits, function-type/approval-type code lists, and authority-limit change history.
  • Determines whether the current user is authorized to update claim authority records.

Context

  • Namespace: SAIF.Services.Claims.Authority
  • Assembly/package: SAIF.Services (packaged inside the SAIF.SAIFCode.Core NuGet package)

Public members

Member Signature Purpose
ClaimAuthorityService(...) public ClaimAuthorityService(IUnitOfWork unitOfWork, IUserProfileService profile, IValidationService validationService, IEnvironmentService environmentService) Wires in the unit of work, profile, validation, and environment collaborators, resolves and caches the current SAIF user profile, and registers the AutoMapper maps needed by this service.
IsValidPaymentAuthorityEdits public Boolean IsValidPaymentAuthorityEdits(PaymentAuthorityEdit authorityEdit, List<IValidationFailure> messages) Marks the edit for the Payments business process and runs full authorization/value validation, appending any failures to messages; returns whether the edit is valid.
IsValidReserveAuthorityEdits public Boolean IsValidReserveAuthorityEdits(PaymentAuthorityEdit authorityEdit, List<IValidationFailure> messages) Marks the edit for the Reserve business process and runs the same validation pipeline as the payment path, returning whether it is valid.
AddEditAuthorityLimit public List<IValidationFailure> AddEditAuthorityLimit(PaymentAuthorityEdit authorityEdit, DateTime historyTimestamp, ApprovalTypes approvalType) Validates the edit, then within a _unitOfWork transaction either inserts a new EmployeeAuthorityLimit or updates the matching existing one (by employee/function/purpose/business process), committing on success or rolling back and returning validation messages on failure.
AddAuthorityLimit public List<IValidationFailure> AddAuthorityLimit(PaymentAuthorityEdit authorityEdit, DateTime historyTimestamp, PaymentAuthorityLimit authorityLimit) Validates the edit, creates a new EmployeeAuthorityLimit (starting UpdateNumber at 1), adds it to the repository, and records the initial value in payment-limit history.
DeleteOrRevertExpiredAuthorities public void DeleteOrRevertExpiredAuthorities(List<long> expiredAuthorityId) In one transaction, for each supplied limit ID either reverts the limit to its most recent prior non-expiring history value or deletes it (zeroing amount/expiration) if no such history exists; rolls back and rethrows on any exception.
DeleteExpiredAuthorities public void DeleteExpiredAuthorities(List<long> expiredAuthorityId) In one transaction, unconditionally deletes (zeroes out and records history for) each supplied authority-limit ID; rolls back and rethrows on any exception.
GetExpiredAuthorities public IEnumerable<PaymentAuthorityLimit> GetExpiredAuthorities(DateTime runDate) Returns all EmployeeAuthorityLimit rows whose expiration date is earlier than runDate, mapped to contracts and each populated with the owning employee's UserId.
GetTerminatedAuthorities public IEnumerable<PaymentAuthorityLimit> GetTerminatedAuthorities() Joins authority limits to employees whose EmployeeStatusCode is not "A" (active), returning the limits of terminated employees ordered by user, business process, function, and purpose, each tagged with the employee's UserId.
GetClaimAuthority() public EmployeePaymentAuthority GetClaimAuthority() Returns the full payment authority (payment and reserve limits) for the currently logged-in user.
GetClaimAuthority(userId, messages) public EmployeePaymentAuthority GetClaimAuthority(string userId, List<IValidationFailure> messages) Resolves the target user (defaulting to "unknown" when blank), and in production returns an empty/invalid-user result with an error message when the user is inactive or has no employee ID; otherwise returns their payment and reserve authority limits plus whether the current user CanUpdate.
GetFunctionTypeList public IEnumerable<FunctionTypeCode> GetFunctionTypeList(string businessProcess) Returns the active AuthorityPaymentTypeCode entries for the given business process, ordered by description, mapped to FunctionTypeCode contracts.
GetApprovalTypeList public IEnumerable<ApprovalTypeCode> GetApprovalTypeList(string businessProcess) Returns the AuthorityPaymentApprovalTypeCode entries for the given business process, ordered by code, mapped to ApprovalTypeCode contracts.
CanUserUpdate public bool CanUserUpdate() Returns true when the current user is not null and holds either the ClaimAuthorityUpdate or ClaimAuthorityEAIPUpdate security permission.
GetClaimAuthorityLimitHistory public IList<PaymentAuthorityLimitHistory> GetClaimAuthorityLimitHistory(string employeeId, string businessProcess) Returns the authority-limit change history for an employee and business process, ordered by payment-type description then descending update date, mapped to contract history records.

Behavioral notes

  • Wraps multi-step writes (AddEditAuthorityLimit, DeleteOrRevertExpiredAuthorities, DeleteExpiredAuthorities) in _unitOfWork.Begin()/Commit()/Rollback() and rethrows on exception, ensuring atomic persistence.
  • Every add/update/delete/revert operation appends a corresponding row to EmployeeAuthorityPaymentLimitHistory via the private AddLimitToHistory helper, preserving an audit trail.
  • ValidateAuthorityEdit forces IsOverrideAuthority to false in production before validating, then delegates to _validationService.Validate (backed by ClaimAuthorityValidator).
  • GetClaimAuthority(userId, messages) short-circuits with an "Unknown User" validation failure when the environment is production and the resolved user is inactive or has no employee ID.
  • The static _currentUser field is set from the constructor and reused across instance methods, meaning the cached profile does not automatically refresh if the underlying user profile changes during the service's lifetime*.

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/Claims/Authority/ClaimAuthorityService.cs