Class OrganizationService
Service for managing organizations
Inheritance
OrganizationService
Assembly: OEMS.Core.dll
Syntax
public class OrganizationService : IOrganizationService
Constructors
OrganizationService(IUserRepository, IOrganisationUserRepository, IOrganizationRepository, IMapper, IFileRepository, ITokenService, IAuthService, ILogger<OrganizationService>, IConfiguration, IDbContextFactory<OEMSDBContext>, IEventCategoryRepository, ILocationRepository)
Initializes a new instance of the OrganizationService
Declaration
public OrganizationService(IUserRepository userRepository, IOrganisationUserRepository organizationUserRepository, IOrganizationRepository organizationRepository, IMapper mapper, IFileRepository fileRepository, ITokenService tokenService, IAuthService authService, ILogger<OrganizationService> logger, IConfiguration configuration, IDbContextFactory<OEMSDBContext> contextFactory, IEventCategoryRepository eventCategoryRepository, ILocationRepository locationRepository)
Parameters
Methods
AssignOrgAdminAsync(Guid, Guid)
Assigns administrator privileges to a user within an organization.
Declaration
public Task AssignOrgAdminAsync(Guid orgId, Guid userId)
Parameters
Type |
Name |
Description |
Guid |
orgId |
The unique identifier of the organization.
|
Guid |
userId |
The unique identifier of the user to make an administrator.
|
Returns
Type |
Description |
Task |
A task that represents the asynchronous operation.
|
CheckIfEventAtLocation(Guid, Guid)
Checks if a location is associated with an event.
Declaration
public Task<(bool, List<string>)> CheckIfEventAtLocation(Guid orgId, Guid locationId)
Parameters
Type |
Name |
Description |
Guid |
orgId |
org GUID
|
Guid |
locationId |
location GUID
|
Returns
CheckIfEventWithCategory(Guid, Guid)
Declaration
public Task<(bool hasAny, List<string> categoryNames)> CheckIfEventWithCategory(Guid orgId, Guid categoryId)
Parameters
Type |
Name |
Description |
Guid |
orgId |
|
Guid |
categoryId |
|
Returns
CreateEventCategory(Guid, CreateCategoryDto)
Creates a new event category for the given organization. Checks if the category name already exists.
Declaration
public Task CreateEventCategory(Guid orgId, CreateCategoryDto createCategoryDto)
Parameters
Returns
Exceptions
CreateLocation(Guid, CreateLocationDto)
Creates a new location for the given organization. Checks if the location name already exists.
Declaration
public Task CreateLocation(Guid orgId, CreateLocationDto locationDto)
Parameters
Returns
Exceptions
CreateOrganizationAsync(CreateOrganizationDto)
Creates a new organization with admin registration token
Declaration
public Task<OrganizationCreationResultDto> CreateOrganizationAsync(CreateOrganizationDto dto)
Parameters
Returns
CreateOrganizationLegacyAsync(CreateOrganizationDto)
Legacy method for creating organization (to be deprecated)
Declaration
public Task<CreateOrganizationDto> CreateOrganizationLegacyAsync(CreateOrganizationDto dto)
Parameters
Returns
DeleteCategoryByIdAsync(Guid)
Deletes an event category by its unique identifier.
Declaration
public Task DeleteCategoryByIdAsync(Guid categoryId)
Parameters
Type |
Name |
Description |
Guid |
categoryId |
The unique identifier of the category to delete.
|
Returns
Type |
Description |
Task |
A task that represents the asynchronous operation.
|
DeleteEventCategoryAsync(Guid)
Deletes an event category by its ID. Throws an exception if the category is null.
Declaration
public Task DeleteEventCategoryAsync(Guid eventCategoryId)
Parameters
Type |
Name |
Description |
Guid |
eventCategoryId |
|
Returns
Exceptions
DeleteLocationByIdAsync(Guid)
Deletes a location by its ID. Throws an exception if the location is null.
Declaration
public Task DeleteLocationByIdAsync(Guid locationId)
Parameters
Type |
Name |
Description |
Guid |
locationId |
|
Returns
Exceptions
DeleteMemberAsync(Guid, Guid)
Removes a member from an organization. Checks if member is last orgAdmin. If so,cant be removed.
Declaration
public Task DeleteMemberAsync(Guid userId, Guid organizationId)
Parameters
Type |
Name |
Description |
Guid |
userId |
user GUID
|
Guid |
organizationId |
organization GUID
|
Returns
Exceptions
DeleteOrganizationAsync(Guid)
Deletes an organization from the system.
Declaration
public Task DeleteOrganizationAsync(Guid orgId)
Parameters
Type |
Name |
Description |
Guid |
orgId |
The unique identifier of the organization to delete.
|
Returns
Type |
Description |
Task |
A task that represents the asynchronous operation.
|
GetAllCategorysByOrganizationAsync(Guid)
Gets a list of all categorys for an organization
Declaration
public Task<List<EventCategoryDto>> GetAllCategorysByOrganizationAsync(Guid organizationId)
Parameters
Type |
Name |
Description |
Guid |
organizationId |
|
Returns
GetAllLocationsByOrganizationAsync(Guid)
Gets all locations for a given organization, here the currently selected one
Declaration
public Task<List<LocationDto>> GetAllLocationsByOrganizationAsync(Guid organizationId)
Parameters
Type |
Name |
Description |
Guid |
organizationId |
|
Returns
GetAllOrganizationsAsync(Guid)
Gets all organizations for a user.
Declaration
public Task<IEnumerable<OrganizationDto>> GetAllOrganizationsAsync(Guid userId)
Parameters
Type |
Name |
Description |
Guid |
userId |
|
Returns
GetOrganisationByIdAsync(Guid)
Gets an organization by its ID. Throws an exception if the organization is null.
Declaration
public Task<Organization> GetOrganisationByIdAsync(Guid orgId)
Parameters
Type |
Name |
Description |
Guid |
orgId |
|
Returns
Exceptions
GetOrganizationBrandingAsync(Guid)
Retrieves organization branding settings for the specified organization.
Declaration
public Task<OrganizationDto?> GetOrganizationBrandingAsync(Guid organizationId)
Parameters
Type |
Name |
Description |
Guid |
organizationId |
The unique identifier of the organization to retrieve branding for
|
Returns
Type |
Description |
Task<OrganizationDto> |
An OrganizationDto containing the organization's branding information including colors and logo,
or null if the organization is not found
|
Remarks
Examples
var branding = await organizationService.GetOrganizationBrandingAsync(organizationId);
if (branding != null)
{
var colors = JsonSerializer.Deserialize<JsonElement>(branding.BrandingSettings);
var primaryColor = colors.GetProperty("color1").GetString();
}
Gets the organization dashboard information for a user.
Declaration
public Task<IEnumerable<OrganizationDashboardDto>> GetOrganizationDashboardInformation(Guid userId)
Parameters
Type |
Name |
Description |
Guid |
userId |
user GUID
|
Returns
GetOrganizationMembersAsync(Guid)
Gets all members of an organization.
Declaration
public Task<List<MemberDto>> GetOrganizationMembersAsync(Guid organizationId)
Parameters
Type |
Name |
Description |
Guid |
organizationId |
|
Returns
InviteMemberAsync(string, Guid)
Invites a new member to join an organization by email.
Declaration
public Task InviteMemberAsync(string email, Guid organizationId)
Parameters
Type |
Name |
Description |
string |
email |
The email address of the person to invite.
|
Guid |
organizationId |
The unique identifier of the organization.
|
Returns
Type |
Description |
Task |
A task that represents the asynchronous operation.
|
RemoveOrgAdminAsync(Guid, Guid)
Removes administrator privileges from a user within an organization.
Declaration
public Task RemoveOrgAdminAsync(Guid orgId, Guid userId)
Parameters
Type |
Name |
Description |
Guid |
orgId |
The unique identifier of the organization.
|
Guid |
userId |
The unique identifier of the user to remove administrator privileges from.
|
Returns
Type |
Description |
Task |
A task that represents the asynchronous operation.
|
ShowAllCategories(Guid)
Declaration
public Task ShowAllCategories(Guid orgID)
Parameters
Type |
Name |
Description |
Guid |
orgID |
|
Returns
ShowAllLocations(Guid)
Declaration
public Task ShowAllLocations(Guid orgID)
Parameters
Type |
Name |
Description |
Guid |
orgID |
|
Returns
TransferOrganizationAdminAsync(Guid, Guid, Guid)
Transfers organization admin rights from one user to another.
Declaration
public Task TransferOrganizationAdminAsync(Guid organizationId, Guid currentAdminUserId, Guid newAdminUserId)
Parameters
Type |
Name |
Description |
Guid |
organizationId |
The organization ID
|
Guid |
currentAdminUserId |
The current admin user ID
|
Guid |
newAdminUserId |
The new admin user ID
|
Returns
Exceptions
UpdateCategoryByIdAsync(EventCategoryDto)
Updates an event category
Declaration
public Task<EventCategoryDto> UpdateCategoryByIdAsync(EventCategoryDto updateCategoryDto)
Parameters
Returns
Exceptions
UpdateEventCategory(EventCategoryDto)
Updates an existing event category. Throws an exception if the category is null.
Declaration
public Task UpdateEventCategory(EventCategoryDto eventCategoryDto)
Parameters
Returns
Exceptions
UpdateLocation(LocationDto)
Updates an existing location. Throws an exception if the location is null.
Declaration
public Task UpdateLocation(LocationDto locationDto)
Parameters
Returns
Exceptions
UpdateLocationByIdAsync(LocationDto)
Declaration
public Task<LocationDto> UpdateLocationByIdAsync(LocationDto updateLocationDto)
Parameters
Type |
Name |
Description |
LocationDto |
updateLocationDto |
LocationDto of location to be updated
|
Returns
Exceptions
UpdateMemberDetailsAsync(MemberDto)
Changes details of a member
Declaration
public Task UpdateMemberDetailsAsync(MemberDto member)
Parameters
Type |
Name |
Description |
MemberDto |
member |
MemberDto
|
Returns
Exceptions
UpdateMemberRolesAsync(Guid, Guid, bool, bool, bool, bool)
Updates Member permissions
Declaration
public Task UpdateMemberRolesAsync(Guid userId, Guid organizationId, bool isAdmin, bool isOrganizer, bool isDesigner, bool isExternal)
Parameters
Type |
Name |
Description |
Guid |
userId |
user GUID of user whos permissions change
|
Guid |
organizationId |
organization GUID user is a part of
|
bool |
isAdmin |
bool for org admin permission
|
bool |
isOrganizer |
bool for event organizer permission
|
bool |
isDesigner |
bool for designer permission
|
bool |
isExternal |
bool for external profiles
|
Returns
UpdateOrganizationAsync(UpdateOrganizationDto)
Updates an existing organization's information.
Declaration
public Task UpdateOrganizationAsync(UpdateOrganizationDto dto)
Parameters
Returns
Type |
Description |
Task |
A task that represents the asynchronous operation.
|
UpdateOrganizationBrandingAsync(Guid, string, Guid?)
Updates organization branding settings including colors and optionally the logo.
Declaration
public Task<bool> UpdateOrganizationBrandingAsync(Guid organizationId, string brandingSettings, Guid? logoFileId = null)
Parameters
Type |
Name |
Description |
Guid |
organizationId |
The unique identifier of the organization to update
|
string |
brandingSettings |
JSON string containing branding configuration. Expected format:
{ "color1": "#primaryColor", "color2": "#secondaryColor" }
|
Guid? |
logoFileId |
Optional file ID for a new organization logo. If provided and not empty,
the organization's logo will be updated. If null or empty, the existing logo is preserved.
|
Returns
Type |
Description |
Task<bool> |
True if the update was successful, false otherwise
|
Remarks
Examples
// Update only colors, preserve existing logo
var newBranding = "{ \"color1\": \"#ff0000\", \"color2\": \"#00ff00\" }";
var success = await organizationService.UpdateOrganizationBrandingAsync(orgId, newBranding);
// Update colors and logo
var success2 = await organizationService.UpdateOrganizationBrandingAsync(orgId, newBranding, newLogoFileId);
Exceptions
Type |
Condition |
KeyNotFoundException |
Thrown when the specified organization ID does not exist in the database
|
Implements