Table of Contents

Class VolunteerRoleService

Namespace
Builvero.Application.Services
Assembly
Builvero.Application.dll

Service for managing volunteer roles including retrieval, activation, and deactivation.

public class VolunteerRoleService : IVolunteerRoleService
Inheritance
VolunteerRoleService
Implements
Inherited Members

Remarks

This service provides operations for volunteer role management:

  • Retrieving active roles (for public display)
  • Retrieving all roles (for admin purposes)
  • Retrieving specific roles by ID
  • Opening and closing roles (activating/deactivating)
Active roles are visible to applicants, while closed roles are hidden from public view.

Constructors

VolunteerRoleService(IVolunteerRoleRepository)

Initializes a new instance of the VolunteerRoleService class.

public VolunteerRoleService(IVolunteerRoleRepository roleRepository)

Parameters

roleRepository IVolunteerRoleRepository

Repository for volunteer role data access.

Methods

CloseRoleAsync(Guid, CancellationToken)

Closes (deactivates) a volunteer role, preventing new applications.

public Task<VolunteerRoleDto> CloseRoleAsync(Guid id, CancellationToken cancellationToken = default)

Parameters

id Guid

The unique identifier of the role to close.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<VolunteerRoleDto>

The updated volunteer role DTO.

Remarks

Sets IsActive to false and records the ClosedAtUtc timestamp. Closed roles are hidden from public view and cannot receive new applications.

Exceptions

Exception

Thrown when the role is not found.

GetActiveRolesAsync(CancellationToken)

Retrieves all active volunteer roles (visible to applicants).

public Task<List<VolunteerRoleDto>> GetActiveRolesAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<List<VolunteerRoleDto>>

A list of active volunteer role DTOs.

Remarks

Returns only roles where IsActive is true. Used for public display of available volunteer positions.

GetAllRolesAsync(CancellationToken)

Retrieves all volunteer roles including inactive ones (for admin purposes).

public Task<List<VolunteerRoleDto>> GetAllRolesAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<List<VolunteerRoleDto>>

A list of all volunteer role DTOs (both active and inactive).

Remarks

Returns all roles regardless of active status. Used by admin interfaces to manage all roles.

GetRoleByIdAsync(Guid, CancellationToken)

Retrieves a specific volunteer role by ID.

public Task<VolunteerRoleDto?> GetRoleByIdAsync(Guid id, CancellationToken cancellationToken = default)

Parameters

id Guid

The unique identifier of the role to retrieve.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<VolunteerRoleDto>

The volunteer role DTO if found; otherwise, null.

OpenRoleAsync(Guid, CancellationToken)

Opens (activates) a volunteer role, allowing new applications.

public Task<VolunteerRoleDto> OpenRoleAsync(Guid id, CancellationToken cancellationToken = default)

Parameters

id Guid

The unique identifier of the role to open.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<VolunteerRoleDto>

The updated volunteer role DTO.

Remarks

Sets IsActive to true and clears the ClosedAtUtc timestamp. Open roles are visible to applicants and can receive new applications.

Exceptions

Exception

Thrown when the role is not found.