Table of Contents

Interface IUserRepository

Namespace
Builvero.Application.Interfaces.Repositories
Assembly
Builvero.Application.dll

Defines the contract for user data access operations including retrieval, creation, updates, and search.

public interface IUserRepository

Remarks

This repository interface provides methods for managing user entities and their associated data. It supports user lookup by ID and email, user creation and updates, email existence checks, paginated user listings with filtering, and user search functionality with category and skill filtering.

Methods

CreateAsync(User, CancellationToken)

Creates a new user entity in the database.

Task<User> CreateAsync(User user, CancellationToken cancellationToken = default)

Parameters

user User

The user entity to create.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<User>

The created user entity with generated ID and timestamps.

EmailExistsAsync(string, CancellationToken)

Checks if a user with the specified email address exists in the database.

Task<bool> EmailExistsAsync(string email, CancellationToken cancellationToken = default)

Parameters

email string

The email address to check.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<bool>

True if a user with the email exists; otherwise, false.

GetByEmailAsync(string, CancellationToken)

Retrieves a user by their email address.

Task<User?> GetByEmailAsync(string email, CancellationToken cancellationToken = default)

Parameters

email string

The email address of the user to retrieve.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<User>

The user entity if found; otherwise, null.

GetByEmailWithProfileAsync(string, CancellationToken)

Retrieves a user by their email address, including their profile information.

Task<User?> GetByEmailWithProfileAsync(string email, CancellationToken cancellationToken = default)

Parameters

email string

The email address of the user to retrieve.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<User>

The user entity with profile information if found; otherwise, null.

Remarks

This method eagerly loads the user's profile to avoid lazy loading issues.

GetByIdAsNoTrackingAsync(Guid, CancellationToken)

Retrieves a user by their unique identifier without tracking (AsNoTracking).

Task<User?> GetByIdAsNoTrackingAsync(Guid id, CancellationToken cancellationToken = default)

Parameters

id Guid

The unique identifier of the user to retrieve.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<User>

The user entity with all related entities loaded, but not tracked by EF Core, or null if not found.

Remarks

This method is useful for reading fresh data after SaveChanges when you need to ensure navigation properties reflect the latest database state without EF Core change tracking interference. Uses the same eager loading as GetByIdAsync but with AsNoTracking().

GetByIdAsync(Guid, CancellationToken)

Retrieves a user by their unique identifier.

Task<User?> GetByIdAsync(Guid id, CancellationToken cancellationToken = default)

Parameters

id Guid

The unique identifier of the user to retrieve.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<User>

The user entity if found; otherwise, null.

GetSearchUsersCountAsync(string?, UserCategory?, List<Guid>?, CancellationToken)

Gets the total count of users matching the specified search criteria.

Task<int> GetSearchUsersCountAsync(string? text, UserCategory? category, List<Guid>? skillIds, CancellationToken cancellationToken = default)

Parameters

text string

Optional search text for filtering users by name or profile summary.

category UserCategory?

Optional user category filter (e.g., SoftwareEngineer, Designer).

skillIds List<Guid>

Optional list of skill IDs to filter users by.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<int>

The total count of users matching the search criteria.

GetUsersAsync(int, int, string?, UserStatus?, UserRole?, CancellationToken)

Retrieves a paginated list of users with optional filtering by search term, status, and role.

Task<List<User>> GetUsersAsync(int page, int pageSize, string? search = null, UserStatus? status = null, UserRole? role = null, CancellationToken cancellationToken = default)

Parameters

page int

The page number (1-based) to retrieve.

pageSize int

The number of users per page.

search string

Optional search term to filter users by email or name.

status UserStatus?

Optional status filter (e.g., Active, Blocked).

role UserRole?

Optional role filter (e.g., User, Admin, Moderator).

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<List<User>>

A list of users matching the filters.

GetUsersByRolesAsync(List<UserRole>, CancellationToken)

Gets all active users whose role is in the specified list of roles. Used for sending bulk admin updates to specific user groups.

Task<List<User>> GetUsersByRolesAsync(List<UserRole> roles, CancellationToken cancellationToken = default)

Parameters

roles List<UserRole>

List of user roles to filter by.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<List<User>>

List of active users with the specified roles.

Remarks

This method is used by the admin bulk email feature to retrieve users by role for sending administrative updates. Only active users are returned.

GetUsersCountAsync(string?, UserStatus?, UserRole?, CancellationToken)

Gets the total count of users matching the specified filters.

Task<int> GetUsersCountAsync(string? search = null, UserStatus? status = null, UserRole? role = null, CancellationToken cancellationToken = default)

Parameters

search string

Optional search term to filter users by email or name.

status UserStatus?

Optional status filter (e.g., Active, Blocked).

role UserRole?

Optional role filter (e.g., User, Admin, Moderator).

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<int>

The total count of users matching the filters.

SearchUsersAsync(string?, UserCategory?, List<Guid>?, int, int, CancellationToken)

Searches for users matching the specified criteria with pagination support.

Task<List<User>> SearchUsersAsync(string? text, UserCategory? category, List<Guid>? skillIds, int page, int pageSize, CancellationToken cancellationToken = default)

Parameters

text string

Optional search text for filtering users by name or profile summary.

category UserCategory?

Optional user category filter (e.g., SoftwareEngineer, Designer).

skillIds List<Guid>

Optional list of skill IDs to filter users by.

page int

The page number (1-based) to retrieve.

pageSize int

The number of users per page.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<List<User>>

A list of users matching the search criteria.

UpdateAsync(User, CancellationToken)

Updates an existing user entity in the database.

Task<User> UpdateAsync(User user, CancellationToken cancellationToken = default)

Parameters

user User

The user entity with updated values.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<User>

The updated user entity.