Table of Contents

Class DisplayRepository

Namespace
adas_core.Infrastructure.Repositories
Assembly
adas-core.Infrastructure.dll

Repository implementation for managing Display entities in MongoDB. Provides CRUD operations and specialized queries for display devices.

public class DisplayRepository : MongoRepository<Display>, IDisplayRepository, IMongoRepository<Display>
Inheritance
DisplayRepository
Implements
Inherited Members
Extension Methods

Constructors

DisplayRepository(IOptions<ApiSettings>, IMongoDatabase, ILogger<DisplayRepository>)

Initializes a new instance of the DisplayRepository.

public DisplayRepository(IOptions<ApiSettings> apiSettings, IMongoDatabase database, ILogger<DisplayRepository> logger)

Parameters

apiSettings IOptions<ApiSettings>

API settings containing collection names configuration.

database IMongoDatabase

The MongoDB database instance.

logger ILogger<DisplayRepository>

Logger for repository operations.

Methods

CountByUnitId(ObjectId)

Counts the number of displays associated with a specific unit.

public Task<long> CountByUnitId(ObjectId unitId)

Parameters

unitId ObjectId

The ObjectId of the unit.

Returns

Task<long>

The count of displays for the unit, or 0 if an error occurs.

Exceptions

Exception

Logs errors and returns 0 on failure.

CreateIndexes()

Creates the necessary indexes for the Display collection. Creates indexes on displayConfigId and unitId fields for improved query performance.

public override Task CreateIndexes()

Returns

Task

DeleteManyByUnitId(ObjectId)

Deletes all displays associated with a specific unit.

public Task<bool> DeleteManyByUnitId(ObjectId unitId)

Parameters

unitId ObjectId

The ObjectId of the unit whose displays should be deleted.

Returns

Task<bool>

True if deletion was successful; otherwise, false.

Exceptions

Exception

Logs errors and returns false on failure.

GetAll()

Retrieves all displays from the database.

public Task<List<Display>> GetAll()

Returns

Task<List<Display>>

A list of all Display entities.

GetByCardConfigId(ObjectId)

Retrieves all displays that use a specific card configuration through their display configuration. Performs an aggregation to join Display with DisplayConfig and filter by cardConfigId.

public Task<List<Display>> GetByCardConfigId(ObjectId configId)

Parameters

configId ObjectId

The ObjectId of the card configuration.

Returns

Task<List<Display>>

A list of Display entities using the specified card config, or empty list on error.

Exceptions

Exception

Logs errors and returns empty list on failure.

GetByConfigId(ObjectId)

Retrieves all displays associated with a specific display configuration.

public Task<List<Display>> GetByConfigId(ObjectId id)

Parameters

id ObjectId

The ObjectId of the display configuration.

Returns

Task<List<Display>>

A list of Display entities using the specified configuration.

GetById(ObjectId)

Retrieves a display by its ID.

public Task<Display?> GetById(ObjectId id)

Parameters

id ObjectId

The ObjectId of the display to retrieve.

Returns

Task<Display>

The Display if found; otherwise, null.

GetByIdWithConfigDisplay(ObjectId)

Retrieves a display by its ID with the associated display configuration. Performs a MongoDB lookup to join the display with its configuration.

public Task<Display?> GetByIdWithConfigDisplay(ObjectId id)

Parameters

id ObjectId

The ObjectId of the display to retrieve.

Returns

Task<Display>

The Display with DisplayConfig populated if found; otherwise, null.

GetByName(string)

Retrieves a display by its name.

public Task<Display?> GetByName(string name)

Parameters

name string

The name of the display to retrieve.

Returns

Task<Display>

The Display if found; otherwise, null.

GetByPointOfCare(PointOfCare)

Retrieves all displays associated with a specific point of care.

public Task<List<Display>> GetByPointOfCare(PointOfCare pointOfCare)

Parameters

pointOfCare PointOfCare

The PointOfCare to filter by.

Returns

Task<List<Display>>

A list of Display entities associated with the point of care.

GetByUnitId(ObjectId)

Retrieves all displays associated with a specific unit.

public Task<List<Display>> GetByUnitId(ObjectId id)

Parameters

id ObjectId

The ObjectId of the unit.

Returns

Task<List<Display>>

A list of Display entities associated with the unit.

GetCollectionName()

Gets the name of the collection for displays.

public override string GetCollectionName()

Returns

string

The collection name from API settings.

GetPaginatedDisplays(PaginationFilter)

Retrieves paginated displays with optional filtering. Supports filtering by text, unit ID, unit name, and display type.

public IFindFluent<Display, Display> GetPaginatedDisplays(PaginationFilter filter)

Parameters

filter PaginationFilter

The pagination and filtering parameters.

Returns

IFindFluent<Display, Display>

A fluent queryable for Display results.

Exceptions

BadRequestException

Thrown when the text filter exceeds 100 characters.

IsDisplayConfigInUse(ObjectId)

Checks if a display configuration is currently in use by any displays.

public Task<long> IsDisplayConfigInUse(ObjectId displayConfigId)

Parameters

displayConfigId ObjectId

The ObjectId of the display configuration to check.

Returns

Task<long>

The count of displays using the configuration.

UpdateConfig(ObjectId, DisplayConfig)

Updates the display configuration for a specific display.

public Task<Display?> UpdateConfig(ObjectId objectId, DisplayConfig config)

Parameters

objectId ObjectId

The ObjectId of the display to update.

config DisplayConfig

The new DisplayConfig to set.

Returns

Task<Display>

The updated Display if successful; otherwise, null.

Exceptions

Exception

Logs errors and returns null on failure.

UpdateConfigId(ObjectId, ObjectId)

Updates the display configuration ID reference for a specific display.

public Task<Display?> UpdateConfigId(ObjectId objectId, ObjectId displayConfigId)

Parameters

objectId ObjectId

The ObjectId of the display to update.

displayConfigId ObjectId

The new display configuration ObjectId to set.

Returns

Task<Display>

The updated Display if successful; otherwise, null.

Exceptions

Exception

Logs errors and returns null on failure.

UpdateConfigPreset(ObjectId, ObjectId)

Updates the display configuration preset for a specific display.

public Task<Display?> UpdateConfigPreset(ObjectId objectIdDisplay, ObjectId objectIdConfigDisplay)

Parameters

objectIdDisplay ObjectId

The ObjectId of the display to update.

objectIdConfigDisplay ObjectId

The ObjectId of the display configuration preset.

Returns

Task<Display>

The updated Display if successful; otherwise, null.

Exceptions

Exception

Logs errors and returns null on failure.

UpdateName(Display, string)

Updates the name of a specific display.

public Task<Display> UpdateName(Display display, string name)

Parameters

display Display

The Display entity to update.

name string

The new name for the display.

Returns

Task<Display>

The updated Display if successful.

Exceptions

Exception

Throws an exception if MongoDB update fails.

UpdatePointOfCareList(ObjectId, List<ObjectId>)

Updates the point of care list for a specific display.

public Task<Display?> UpdatePointOfCareList(ObjectId objectId, List<ObjectId> listPocObId)

Parameters

objectId ObjectId

The ObjectId of the display to update.

listPocObId List<ObjectId>

The new list of point of care ObjectIds.

Returns

Task<Display>

The updated Display if successful; otherwise, null.

Exceptions

Exception

Logs errors and returns null on failure.