Class MasterListRepository<T>
- Namespace
- adas_core.Infrastructure.Repositories
- Assembly
- adas-core.Infrastructure.dll
Generic repository implementation for managing MasterList entities in MongoDB. Provides CRUD operations and specialized queries for various master list types including options lists, diagnoses, allergies, procedures, treatments, and other reference data.
public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository<T>, IMongoRepository<T> where T : MasterList
Type Parameters
TThe type of MasterList entity to manage.
- Inheritance
-
MasterListRepository<T>
- Implements
- Inherited Members
- Extension Methods
Constructors
MasterListRepository(IOptions<ApiSettings>, IMongoDatabase)
Initializes a new instance of the MasterListRepository.
public MasterListRepository(IOptions<ApiSettings> apiSettings, IMongoDatabase database)
Parameters
apiSettingsIOptions<ApiSettings>API settings containing collection names configuration.
databaseIMongoDatabaseThe MongoDB database instance.
Exceptions
- ArgumentNullException
Thrown when apiSettings is null.
Methods
AddOptionToMasterList(ObjectId, FilterOptionListElement)
Adds a new option to a master list.
public Task<OptionList?> AddOptionToMasterList(ObjectId id, FilterOptionListElement opt)
Parameters
idObjectIdThe ObjectId of the master list.
optFilterOptionListElementThe option element to add.
Returns
- Task<OptionList>
The newly created OptionList if successful; otherwise, null if duplicate exists.
Exceptions
- Exception
Logs errors and returns null on failure.
Count()
Counts the total number of master list entities in the collection.
public Task<int> Count()
Returns
Exceptions
- Exception
Logs errors and returns 0 on failure.
CreateIndexes()
Creates necessary indexes for the MasterList collection. Currently creates text indexes for DiagnosisList on options.name, options.description, and options._id.
public override Task CreateIndexes()
Returns
Delete(ObjectId)
Deletes a master list entity by its ID.
public Task Delete(ObjectId id)
Parameters
idObjectIdThe ObjectId of the entity to delete.
Returns
Exceptions
- Exception
Throws and re-throws exceptions after logging.
DeleteMasterListOption(ObjectId, ObjectId)
Deletes a specific option from a master list.
public Task<bool> DeleteMasterListOption(ObjectId id, ObjectId deleteOptId)
Parameters
idObjectIdThe ObjectId of the master list.
deleteOptIdObjectIdThe ObjectId of the option to delete.
Returns
FindById(ObjectId)
Finds a master list entity by its ID with options projection limited to 100 items.
public Task<T?> FindById(ObjectId id)
Parameters
idObjectIdThe ObjectId of the entity to retrieve.
Returns
- Task<T>
The MasterList entity if found; otherwise, null.
Exceptions
- Exception
Logs errors and returns null on failure.
FindById(ObjectId, LocaleEnum?)
Finds a master list entity by its ID with optional locale translation for options. Uses MongoDB aggregation to unwind options and apply translations.
public Task<T?> FindById(ObjectId id, LocaleEnum? locale)
Parameters
idObjectIdThe ObjectId of the entity to retrieve.
localeLocaleEnum?Optional locale for translated option names.
Returns
- Task<T>
The MasterList entity with translated options if found; otherwise, null.
Exceptions
- Exception
Logs errors and returns null on failure.
FindByName(string)
Finds a master list entity by its name.
public Task<T?> FindByName(string name)
Parameters
namestringThe name of the master list to retrieve.
Returns
- Task<T>
The MasterList entity if found; otherwise, null.
Exceptions
- Exception
Logs errors and returns null on failure.
FindOptionItemById(ObjectId, ObjectId)
Finds a specific option within a master list by master and option IDs without locale translation.
public Task<OptionList?> FindOptionItemById(ObjectId masterId, ObjectId optionId)
Parameters
masterIdObjectIdThe ObjectId of the master list.
optionIdObjectIdThe ObjectId of the option to retrieve.
Returns
- Task<OptionList>
The OptionList if found; otherwise, null.
Exceptions
- Exception
Logs errors and returns null on failure.
FindOptionItemById(ObjectId, ObjectId, LocaleEnum)
Finds a specific option within a master list by master and option IDs with locale translation. Uses MongoDB aggregation to apply translations and return the translated option.
public Task<OptionList?> FindOptionItemById(ObjectId masterId, ObjectId optionId, LocaleEnum locale)
Parameters
masterIdObjectIdThe ObjectId of the master list.
optionIdObjectIdThe ObjectId of the option to retrieve.
localeLocaleEnumThe locale for translation.
Returns
- Task<OptionList>
The OptionList with translated fields if found; otherwise, null.
Exceptions
- Exception
Logs errors and returns null on failure.
GetAll()
Retrieves all master list entities.
public Task<IEnumerable<T>> GetAll()
Returns
- Task<IEnumerable<T>>
An enumerable of all MasterList entities.
Exceptions
- Exception
Logs errors and returns empty list on failure.
GetAllWithoutOptions()
Retrieves all master list entities without options, returning only metadata.
public Task<IEnumerable<MasterListDto>> GetAllWithoutOptions()
Returns
- Task<IEnumerable<MasterListDto>>
An enumerable of MasterListDto containing id, name, description, listType, and options count.
Exceptions
- Exception
Logs errors and returns empty list on failure.
GetCollectionName()
Gets the name of the collection based on the entity type T. Maps different MasterList subtypes to their corresponding MongoDB collection names.
public override string GetCollectionName()
Returns
- string
The collection name for the current MasterList type.
GetMasterListByIdAndSearchOptions(ObjectId, FilterOptionListElement?)
Searches for options within a master list using multiple filter criteria. Uses MongoDB aggregation pipeline to apply filters and locale translations.
public Task<List<OptionList>> GetMasterListByIdAndSearchOptions(ObjectId id, FilterOptionListElement? filters)
Parameters
idObjectIdThe ObjectId of the master list.
filtersFilterOptionListElementThe filter criteria including text, name, description, and optionType.
Returns
- Task<List<OptionList>>
A list of matching OptionList items ordered by name.
Exceptions
- Exception
Logs errors and returns empty list on failure.
GetMasterListByIdAndTextSearchContaining(ObjectId, string?)
Gets options from a master list filtered by text search.
public Task<List<OptionList>> GetMasterListByIdAndTextSearchContaining(ObjectId id, string? textSearch)
Parameters
idObjectIdThe ObjectId of the master list.
textSearchstringOptional text to search within options.
Returns
- Task<List<OptionList>>
A list of matching OptionList items.
GetMasterListByTextSearch(string?)
Searches for options across all master lists using text search.
public Task<List<OptionList>> GetMasterListByTextSearch(string? textSearch)
Parameters
textSearchstringOptional text to search within options.
Returns
- Task<List<OptionList>>
A list of matching OptionList items.
GetPaginatedMasterList(PaginationFilter)
Retrieves paginated master lists with optional text filtering.
public IFindFluent<T, T> GetPaginatedMasterList(PaginationFilter filter)
Parameters
filterPaginationFilterThe pagination and filtering parameters.
Returns
- IFindFluent<T, T>
A fluent queryable for MasterList results.
GetPaginatedOptions(PaginationFilter, ObjectId)
Retrieves paginated options within a master list with optional text filtering.
public Task<List<OptionList>> GetPaginatedOptions(PaginationFilter filter, ObjectId listId)
Parameters
filterPaginationFilterThe pagination and filtering parameters.
listIdObjectIdThe ObjectId of the master list.
Returns
- Task<List<OptionList>>
A list of filtered OptionList items.
InsertOneAsync(T)
Inserts a new master list entity into the database.
public override Task InsertOneAsync(T entity)
Parameters
entityTThe entity to insert.
Returns
Exceptions
- Exception
Throws and re-throws exceptions after logging.
RemoveMasterListOption(ObjectId, OptionList)
Removes an option from a master list by matching all its properties.
public Task<bool> RemoveMasterListOption(ObjectId id, OptionList oldOpt)
Parameters
idObjectIdThe ObjectId of the master list.
oldOptOptionListThe OptionList to remove.
Returns
Exceptions
- Exception
Logs errors and returns false on failure.
Update(T)
Updates an existing master list entity with full replacement.
public Task Update(T entity)
Parameters
entityTThe entity with updated values.
Returns
Exceptions
- Exception
Throws and re-throws exceptions after logging.
UpdateFullMasterListOption(ObjectId, OptionList)
Updates a specific option within a master list with full property replacement.
public Task<OptionList?> UpdateFullMasterListOption(ObjectId id, OptionList newOpt)
Parameters
idObjectIdThe ObjectId of the master list.
newOptOptionListThe OptionList with updated values.
Returns
- Task<OptionList>
The updated OptionList if found; otherwise, null.
UpdateMasterListDescription(ObjectId, string)
Updates the description of a master list.
public Task<bool> UpdateMasterListDescription(ObjectId id, string description)
Parameters
idObjectIdThe ObjectId of the master list.
descriptionstringThe new description.
Returns
Exceptions
- Exception
Logs errors and returns false on failure.
UpdateMasterListName(ObjectId, string)
Updates the name of a master list.
public Task<bool> UpdateMasterListName(ObjectId id, string name)
Parameters
idObjectIdThe ObjectId of the master list.
namestringThe new name.
Returns
Exceptions
- Exception
Logs errors and returns false on failure.
UpdateMasterListOption(ObjectId, OptionList)
Updates a specific option within a master list with full replacement.
public Task<OptionList?> UpdateMasterListOption(ObjectId id, OptionList newOpt)
Parameters
idObjectIdThe ObjectId of the master list.
newOptOptionListThe OptionList with updated values.
Returns
- Task<OptionList>
The updated OptionList if successful; otherwise, null.
Exceptions
- Exception
Logs errors and returns null on failure.
UpdateMasterListOption(ObjectId, OptionList, LocaleEnum)
Updates a specific option within a master list with locale-aware field updates.
public Task<OptionList?> UpdateMasterListOption(ObjectId id, OptionList newOpt, LocaleEnum locale)
Parameters
idObjectIdThe ObjectId of the master list.
newOptOptionListThe OptionList with updated values.
localeLocaleEnumThe locale for translation updates.
Returns
- Task<OptionList>
The updated OptionList if successful; otherwise, null.
Exceptions
- Exception
Logs errors and returns null on failure.
UpdateOptionDetailsToMasterList(ObjectId, UpdateMasterListDetailsDto)
Updates the metadata details for a master list.
public Task<UpdateMasterListDetailsDto?> UpdateOptionDetailsToMasterList(ObjectId id, UpdateMasterListDetailsDto opt)
Parameters
idObjectIdThe ObjectId of the master list.
optUpdateMasterListDetailsDtoThe UpdateMasterListDetailsDto with updated values.
Returns
- Task<UpdateMasterListDetailsDto>
The updated UpdateMasterListDetailsDto if successful; otherwise, null.
Exceptions
- Exception
Logs errors and returns null on failure.