Table of Contents

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

apiSettings IOptions<ApiSettings>
database IMongoDatabase

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

id ObjectId

The MongoDB.Bson.ObjectId of the user to look up.

Returns

Task<User>

A User instance if a matching document exists; otherwise, null.

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

name string

The name of the user to look up.

Returns

Task<User>

A User instance if a match is found; otherwise, null.

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

name string

The 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 null if 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

name string

The username used to look up the user.

Returns

Task<User>

A User instance if a match is found; otherwise, null.

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

filteredRequest PaginationFilter

The 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

username string

The username to look up in the collection.

password string

The password that must match the stored value for the user to be returned.

Returns

Task<User>

A User instance when a matching record is found; otherwise, null.

InsertInitialLoad()

Inserts the initial load of data by ensuring that the system user exists, creating one if necessary.

public override sealed Task InsertInitialLoad()

Returns

Task

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

user User

The user entity whose fields will be applied to the existing record, identified by Id.

updatePass bool

If true, the password field is included in the update; if false, the password is not modified.

Returns

Task<User>

The updated User retrieved after the update, or null if no matching user was found.