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
userUserThe user entity to create.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
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
emailstringThe email address to check.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
GetByEmailAsync(string, CancellationToken)
Retrieves a user by their email address.
Task<User?> GetByEmailAsync(string email, CancellationToken cancellationToken = default)
Parameters
emailstringThe email address of the user to retrieve.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
GetByEmailWithProfileAsync(string, CancellationToken)
Retrieves a user by their email address, including their profile information.
Task<User?> GetByEmailWithProfileAsync(string email, CancellationToken cancellationToken = default)
Parameters
emailstringThe email address of the user to retrieve.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
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
idGuidThe unique identifier of the user to retrieve.
cancellationTokenCancellationTokenCancellation 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
idGuidThe unique identifier of the user to retrieve.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
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
textstringOptional search text for filtering users by name or profile summary.
categoryUserCategory?Optional user category filter (e.g., SoftwareEngineer, Designer).
skillIdsList<Guid>Optional list of skill IDs to filter users by.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
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
pageintThe page number (1-based) to retrieve.
pageSizeintThe number of users per page.
searchstringOptional search term to filter users by email or name.
statusUserStatus?Optional status filter (e.g., Active, Blocked).
roleUserRole?Optional role filter (e.g., User, Admin, Moderator).
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
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
rolesList<UserRole>List of user roles to filter by.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
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
searchstringOptional search term to filter users by email or name.
statusUserStatus?Optional status filter (e.g., Active, Blocked).
roleUserRole?Optional role filter (e.g., User, Admin, Moderator).
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
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
textstringOptional search text for filtering users by name or profile summary.
categoryUserCategory?Optional user category filter (e.g., SoftwareEngineer, Designer).
skillIdsList<Guid>Optional list of skill IDs to filter users by.
pageintThe page number (1-based) to retrieve.
pageSizeintThe number of users per page.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
UpdateAsync(User, CancellationToken)
Updates an existing user entity in the database.
Task<User> UpdateAsync(User user, CancellationToken cancellationToken = default)
Parameters
userUserThe user entity with updated values.
cancellationTokenCancellationTokenCancellation token to cancel the operation.