Class UserRepository
- Namespace
- adas_core.Infrastructure.Repositories
- Assembly
- adas-core.Infrastructure.dll
Represents a MongoDB-backed repository for managing User entities.
public class UserRepository : MongoRepository<User>, IUserRepository, IMongoRepository<User>
- Inheritance
-
UserRepository
- Implements
- Inherited Members
- Extension Methods
Remarks
Inherits core data access functionality from MongoRepository<T> and implements the IUserRepository contract.
Constructors
UserRepository(IOptions<ApiSettings>, IMongoDatabase)
public UserRepository(IOptions<ApiSettings> apiSettings, IMongoDatabase database)
Parameters
apiSettingsIOptions<ApiSettings>databaseIMongoDatabase
Methods
GetById(ObjectId)
Retrieves a user from the collection by their unique identifier, returning null when no matching document is found.
public Task<User?> GetById(ObjectId id)
Parameters
idObjectIdThe MongoDB.Bson.ObjectId of the user to look up.
Returns
GetByName(string)
Retrieves a user from the data store whose name exactly matches the specified value, returning null if no matching user exists.
public Task<User?> GetByName(string name)
Parameters
namestringThe name of the user to look up.
Returns
GetByUserAndAuthoritesName(string)
Retrieves a user by their username along with their associated authorizations, using a MongoDB aggregation pipeline that joins the user with the authorizations collection and resolves the user's role (Admin role is preserved, otherwise mapped to "Some"). Returns null when no user matches the provided username.
public Task<User?> GetByUserAndAuthoritesName(string name)
Parameters
namestringThe username used to match the user document in the collection.
Returns
- Task<User>
A Task<TResult> that yields the matching User with its authorizations and resolved role, or
nullif no user is found.
GetByUserName(string)
Retrieves a user from the data store by their unique username.
Returns null when no user matches the provided username.
public Task<User?> GetByUserName(string name)
Parameters
namestringThe username used to look up the user.
Returns
GetCollectionName()
Retrieves the API collection name for users from the configured API settings.
public override string GetCollectionName()
Returns
- string
The configured name of the users collection.
GetOrCreateSystemUser()
Retrieves the system user identified by the username "System", creating and inserting a new one with default credentials if no existing user is found.
public Task<User> GetOrCreateSystemUser()
Returns
- Task<User>
The existing system user if found; otherwise, the newly created and inserted system user.
GetPaginatedUsers(PaginationFilter)
Retrieves a paginated and filterable queryable collection of users based on the supplied pagination and filter criteria. Applies a case-insensitive text search across the user's Name, Email, and UserName fields when a text filter is provided, and conditionally combines user status and user type filters; when no filter payload is supplied, returns the base sorted find fluent without applying additional filters.
public IFindFluent<User, User> GetPaginatedUsers(PaginationFilter filteredRequest)
Parameters
filteredRequestPaginationFilterThe pagination filter containing paging details and the optional filter payload (text, user status, and user type) used to build the MongoDB query.
Returns
- IFindFluent<User, User>
An MongoDB.Driver.IFindFluent<TDocument, TProjection> of User sorted ascending by user name and shaped by the assembled filter definitions.
GetUser(string, string)
Retrieves a user from the collection whose username and password match the provided credentials.
Returns the first matching user, or null when no user with the given username and password combination is found.
public Task<User?> GetUser(string username, string password)
Parameters
usernamestringThe username to look up in the collection.
passwordstringThe password that must match the stored value for the user to be returned.
Returns
InsertInitialLoad()
Inserts the initial load of data by ensuring that the system user exists, creating one if necessary.
public override sealed Task InsertInitialLoad()
Returns
UpdateUser(User, bool)
Updates an existing user in the data store with the provided information, optionally including the password.
When updatePass is true, the user's password is also persisted; otherwise, it is left unchanged.
public Task<User?> UpdateUser(User user, bool updatePass)
Parameters
userUserThe user entity whose fields will be applied to the existing record, identified by Id.
updatePassboolIf
true, the password field is included in the update; iffalse, the password is not modified.