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

# ImageService

Implements `IImageService`, the group-imaging facade coordinating retrieval, security filtering, and mutation of images attached to groups. It depends on `IUnitOfWork` for transaction boundaries, `IGroupImageRepository` and `IImageCategoryCodeRepository` for data access, `IGroupImageSecurityProvider` for confidentiality/deletion visibility and edit authorization, and delegates writes to injected `IImageUpdater`/`IImageDeleter` collaborators. Its static constructor registers AutoMapper maps for `ImageGroup`→`Image` and `imagingDataModel.Image`→`Image` (deriving `Category`, `IsDeleted`, `IsConfidential`) and reuses `GroupsMappingHelper.CreateGroupMap()` and `ImagingMappingHelper.CreateCategoryAndDocumentTypeMap()`.

## Purpose
- Reports whether the current user can see confidential images, see deleted images, or edit images (delegated to `IGroupImageSecurityProvider`).
- Retrieves a single image by ID, optionally tolerating a missing image (`GetImageOrDefault`).
- Retrieves all images for a group, applying an optional `ImageFilterCriteria` combined with the current user's confidential/deleted visibility.
- Updates or deletes an image within a transaction, delegating the actual mutation to `IImageUpdater`/`IImageDeleter`.
- Retrieves the available image categories.

## Context
- Namespace: `SAIF.Services.Groups.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, IGroupImageSecurityProvider securityProvider, IGroupImageRepository groupImageRepository, IImageCategoryCodeRepository imageCategoryCodeRepository, IImageUpdater imageUpdater, IImageDeleter imageDeleter)` | Validates the unit of work and validation service are non-null, and stores all injected collaborators. |
| CanUserSeeConfidentialImages | `public bool CanUserSeeConfidentialImages()` | Returns whether the current user is authorized to see confidential images. |
| CanUserSeeDeletedImages | `public bool CanUserSeeDeletedImages()` | Returns whether the current user is authorized to see deleted images. |
| CanUserEditImages | `public bool CanUserEditImages()` | Returns whether the current user is authorized to edit images. |
| GetImage | `public Image GetImage(long groupImageId)` | Returns the mapped `Image` for the given group-image ID (throws if not found, per repository behavior). |
| GetImageOrDefault | `public Image GetImageOrDefault(long groupImageId)` | Returns the mapped `Image` for the given group-image ID, or `null` if it does not exist. |
| GetImages(groupId) | `public IEnumerable<Image> GetImages(string groupId)` | Returns all images for the group, applying an empty (default) filter. |
| GetImages(groupId, filter) | `public IEnumerable<Image> GetImages(string groupId, ImageFilterCriteria filter)` | Returns images for the group matching `filter`, constrained by the current user's confidential/deleted visibility. |
| UpdateImage | `public void UpdateImage(ImageEdit imageEdit)` | Begins a transaction, delegates the update to `IImageUpdater.Update`, then commits. |
| DeleteImage | `public void DeleteImage(ImageDelete imageDelete)` | Begins a transaction, delegates the deletion to `IImageDeleter.Delete`, then commits. |
| GetCategories | `public IEnumerable<Category> GetCategories()` | Returns all image categories mapped from `IImageCategoryCodeRepository.GetImageCategoryCodes()`. |

## Behavioral notes
- `UpdateImage` and `DeleteImage` wrap their delegated operation in `unitOfWork.Begin()`/`Commit()`, but do not catch exceptions or call `Rollback()`, so any thrown validation/repository exception propagates without an explicit rollback call*.
- `CreateGroupImageRepositoryFilter` always overrides the caller-supplied filter's `CanUserSeeConfidentialImages`/`CanUserSeeDeletedImages` flags with the security provider's live result, preventing callers from bypassing visibility rules through the filter object.
- The static constructor participates in the same shared AutoMapper configuration as `GroupService` and `NoteService` via `GroupsMappingHelper.CreateGroupMap()`*.

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