Interface IAdminService
- Namespace
- Builvero.Application.Services
- Assembly
- Builvero.Application.dll
Defines the contract for administrative operations including user management, invitation management, and bulk email communications.
public interface IAdminService
Remarks
This interface provides methods for administrative tasks that require elevated permissions (AdminRead or AdminWrite policies). All operations are designed to be safe for concurrent access and include proper error handling.
Methods
BlockUserAsync(Guid, CancellationToken)
Blocks a user account, preventing them from logging in or accessing the platform.
Task BlockUserAsync(Guid userId, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe unique identifier of the user to block.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task
- Defines the contract for administrative operations including user management, invitation management, and bulk email communications.
Exceptions
- Exception
Thrown when the user is not found.
ChangeUserRoleAsync(Guid, string, CancellationToken)
Changes the role assigned to a user, affecting their permissions and access level.
Task ChangeUserRoleAsync(Guid userId, string role, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe unique identifier of the user whose role should be changed.
rolestringThe new role as a string (e.g., "Admin", "Moderator", "User"). Must match a UserRole enum value.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task
- Defines the contract for administrative operations including user management, invitation management, and bulk email communications.
Exceptions
- Exception
Thrown when the role is invalid or the user is not found.
CreateInvitationAsync(Guid, CreateInvitationRequest, string, CancellationToken)
Creates a new invitation code that can be used for user registration.
Task<InvitationDto> CreateInvitationAsync(Guid createdByUserId, CreateInvitationRequest request, string baseUrl, CancellationToken cancellationToken = default)
Parameters
createdByUserIdGuidThe unique identifier of the admin user creating the invitation.
requestCreateInvitationRequestThe invitation creation request containing max uses, expiration date, and optional label.
baseUrlstringThe base URL of the application, used to construct the full invitation link.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<InvitationDto>
An InvitationDto containing the created invitation details including the generated code and full invitation link.
GetInvitationsAsync(int, int, CancellationToken)
Retrieves a paginated list of all invitation codes in the system.
Task<(List<InvitationDto> Invitations, int TotalCount)> GetInvitationsAsync(int page, int pageSize, CancellationToken cancellationToken = default)
Parameters
pageintThe page number (1-based) to retrieve.
pageSizeintThe number of invitations per page.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<(List<InvitationDto> Invitations, int TotalCount)>
A tuple containing the list of invitations and the total count of all invitations.
GetUserProfileAsync(Guid, CancellationToken)
Retrieves the complete profile information for a user, including profile photo with presigned URL.
Task<ProfileDto> GetUserProfileAsync(Guid userId, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe unique identifier of the user whose profile should be retrieved.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<ProfileDto>
A ProfileDto containing all profile information.
Exceptions
- Exception
Thrown when the user is not found, user email is missing, or profile is not found.
GetUserProjectsAsync(Guid, CancellationToken)
Retrieves all projects associated with a user, including projects they own and projects they are members of.
Task<List<ProjectDto>> GetUserProjectsAsync(Guid userId, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe unique identifier of the user whose projects should be retrieved.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<List<ProjectDto>>
A list of ProjectDto objects representing all projects for the user.
GetUsersAsync(int, int, string?, string?, string?, CancellationToken)
Retrieves a paginated list of users with optional filtering by search term, status, and role.
Task<(List<UserListDto> Users, int TotalCount)> GetUsersAsync(int page, int pageSize, string? search = null, string? status = null, string? 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.
statusstringOptional status filter (e.g., "Active", "Blocked"). Must match UserStatus enum values.
rolestringOptional role filter (e.g., "User", "Admin"). Must match UserRole enum values.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<(List<UserListDto> Users, int TotalCount)>
A tuple containing the list of users and the total count matching the filters.
SendAdminUpdatesAsync(List<UserRole>, string, CancellationToken)
Sends admin update emails to all active users with the specified roles using the SendGrid AdminUpdates template.
Task<AdminUpdateSendResult> SendAdminUpdatesAsync(List<UserRole> roles, string htmlContent, CancellationToken cancellationToken = default)
Parameters
rolesList<UserRole>List of user roles to target. At least one role must be specified.
htmlContentstringRaw HTML content for the email body. Must not be empty or whitespace.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<AdminUpdateSendResult>
An AdminUpdateSendResult containing detailed statistics about the email sending operation.
Remarks
This method automatically excludes users with email addresses containing "demo.builvero.local". Emails are sent in batches of 100 recipients with a maximum of 10 concurrent sends to avoid rate limiting. Individual failures are collected without aborting the entire operation.
The email subject is defined in the SendGrid template and cannot be overridden. The HTML content is sent as-is
to the template's content_html dynamic field.
Exceptions
- ArgumentException
Thrown when roles list is null/empty or htmlContent is null/empty/whitespace.
SendInvitationEmailsAsync(Guid, List<string>, string, Guid, string?, CancellationToken)
Sends invitation emails to multiple recipients for a specific invitation code.
Task<SendInvitationResponse> SendInvitationEmailsAsync(Guid invitationId, List<string> emails, string baseUrl, Guid senderUserId, string? supportEmail = null, CancellationToken cancellationToken = default)
Parameters
invitationIdGuidThe unique identifier of the invitation to send.
emailsList<string>List of email addresses to send invitations to.
baseUrlstringThe base URL of the frontend application, used to construct invitation links.
senderUserIdGuidThe unique identifier of the admin user sending the invitations.
supportEmailstringOptional support email address to include in invitation emails.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<SendInvitationResponse>
A SendInvitationResponse containing per-email results (sent and failed).
Exceptions
- Exception
Thrown when the invitation is not found.
UnblockUserAsync(Guid, CancellationToken)
Unblocks a user account, restoring their access to the platform.
Task UnblockUserAsync(Guid userId, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe unique identifier of the user to unblock.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task
- Defines the contract for administrative operations including user management, invitation management, and bulk email communications.
Exceptions
- Exception
Thrown when the user is not found.
UpdateInvitationAsync(Guid, UpdateInvitationRequest, CancellationToken)
Updates an existing invitation code's properties (max uses, expiration date, label).
Task<InvitationDto> UpdateInvitationAsync(Guid invitationId, UpdateInvitationRequest request, CancellationToken cancellationToken = default)
Parameters
invitationIdGuidThe unique identifier of the invitation to update.
requestUpdateInvitationRequestThe update request containing the fields to modify. Only provided fields are updated.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<InvitationDto>
An InvitationDto representing the updated invitation.
Exceptions
- Exception
Thrown when the invitation is not found or max uses is set to less than the current usage count.
UpdateUserAsync(Guid, UpdateUserRequest, CancellationToken)
Updates user account information including email, password, role, and status.
Task<UserListDto> UpdateUserAsync(Guid userId, UpdateUserRequest request, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe unique identifier of the user to update.
requestUpdateUserRequestThe update request containing the fields to modify. Only provided fields are updated.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<UserListDto>
A UserListDto representing the updated user information.
Exceptions
- Exception
Thrown when the user is not found, email is already in use by another user, or invalid role/status values are provided.