---
title: ImageService
summary: API reference for ImageService (SAIF.Services.Agencies.Imaging).
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-09-24
library: SAIF.Services
reference_type: package
---

# ImageService

Implements `IAgencyImageService`, coordinating retrieval, security filtering, adding, editing, and deleting images attached to agencies (`ImageAgency`). It depends on `IUnitOfWork` for repository access and transactions, `IValidationService` for edit validation, `IImagingService` to retrieve rendered PDF bytes, and `IUserProfileService` for current-user identity and confidential/deleted/edit role checks. Its static constructor registers AutoMapper maps for `ImageAgency`/`imagingDataModel.Image`→`Image` (deriving `Category`, `IsDeleted`, `IsConfidential` from a locally defined confidential security-level constant) and reuses `ImagingMappingHelper.CreateCategoryAndDocumentTypeMap()` and `AgenciesMappingHelper.CreateAgencyMap()`.

## Purpose
- Reports whether the current user can see confidential images, see deleted images, or edit images.
- Associates an existing image with an agency (`AddImage`) and retrieves/filters an agency's images subject to confidentiality/deletion visibility.
- Edits an image's date, text, document type, and confidentiality, re-associating it with a different agency if requested, with validation and authorization checks.
- Soft-deletes an image by setting its delete code, and retrieves the rendered PDF bytes for an image.
- Retrieves the available agency-image categories.

## Context
- Namespace: `SAIF.Services.Agencies.Imaging`
- Assembly/package: `SAIF.Services` (packaged inside the `SAIF.SAIFCode.Core` NuGet package)

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| ImageService(...) | `public ImageService(IUnitOfWork unitOfWork, IValidationService validationService, IImagingService imageService, IUserProfileService userProfileService)` | Validates all four collaborators are non-null and stores them. |
| MaxDescriptionLength | `public const int MaxDescriptionLength = 256;` | The maximum allowed length for an agency image's description text, referenced by `ImageEditValidator`. |
| CanUserSeeConfidentialImages | `public bool CanUserSeeConfidentialImages { get; }` | Returns whether the current user holds the confidential-images role. |
| CanUserSeeDeletedImages | `public bool CanUserSeeDeletedImages { get; }` | Returns whether the current user holds the delete role, permitting visibility of deleted images. |
| CanUserEditImages | `public bool CanUserEditImages { get; }` | Returns whether the current user holds the edit role, permitting image edits. |
| AddImage | `public long AddImage(long agencyId, long imageId, IMessageContainer messageContainer)` | Within a transaction, associates the existing image `imageId` with agency `agencyId`, returning the new `ImageAgency` ID, or `0` (with a message added) if either the agency or image cannot be found. |
| DeleteImage | `public bool DeleteImage(long id, IMessageContainer messageContainer)` | Within a transaction, marks the image's delete code as `"Y"` (if not already deleted) and stamps the update user/date; returns `false` (with a message added) if the image is not found. |
| EditImage | `public bool EditImage(long id, ImageEdit imageEdit, IMessageContainer messageContainer)` | Within a transaction, validates authorization and the edit, re-associates the agency if changed, updates document date/text/type/confidentiality, and stamps update user/date; returns `false` (with a message added) on any authorization, lookup, or validation failure. |
| GetCategories | `public IEnumerable<Category> GetCategories()` | Returns the image categories scoped to the agency image file code (`ImageFileCode.AgencyImageFileCode`). |
| GetImage | `public Image GetImage(long id)` | Returns the mapped `Image` (including its owning agency) for `id`, or `null` if not found or not visible to the current user's confidentiality/deletion permissions. |
| GetImages | `public IEnumerable<Image> GetImages(long agencyId, ImageFilterCriteria filter)` | Returns the agency's images (filtered to what the current user may see) further narrowed by `filter`, forcing `filter.ShowDeleted` off unless the user can see deleted images. |
| GetImageFile | `public byte[] GetImageFile(long imageId)` | Returns the rendered PDF bytes for the image via `IImagingService.GetPDF`. |

## Behavioral notes
- `AddImage`, `DeleteImage`, and `EditImage` each wrap their write in `unitOfWork.Begin()`/`Commit()` without an explicit `Rollback()` on the early-return failure paths, relying on the transaction never reaching `Commit()` in those cases*.
- Confidentiality is stored via private `ConfidentialSecurityLevel`/`NonConfidentialSecurityLevel` constants (50/0), independent of the constants used by `SAIF.Services.Groups.Imaging.ImageService` which reads security level from the shared `Image.ConfidentialSecurityLevel` model constant instead*.
- `GetImage`/`GetImages` apply confidentiality and deleted-visibility filtering identically: an image is excluded unless it is not deleted (or the user can see deleted images) and not confidential (or the user can see confidential images).

> **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/Agencies/Imaging/ImageService.cs
