Search Results for

    Show / Hide Table of Contents

    Class OrganizationService

    Service for managing organizations

    Inheritance
    object
    OrganizationService
    Implements
    IOrganizationService
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: OEMS.Core.Application.ApplicationServices
    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
    Type Name Description
    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

    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 there are any events scheduled at a specific location.

    Declaration
    public Task<(bool, List<string>)> CheckIfEventAtLocation(Guid orgId, Guid locationId)
    Parameters
    Type Name Description
    Guid orgId

    The unique identifier of the organization.

    Guid locationId

    The unique identifier of the location to check.

    Returns
    Type Description
    Task<(bool hasAny, List<string> eventNames)>

    A task that represents the asynchronous operation. The task result contains a tuple indicating whether events exist and a list of event names.

    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
    Type Description
    Task<(bool hasAny, List<string> eventNames)>

    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
    Type Name Description
    Guid orgId
    CreateCategoryDto createCategoryDto
    Returns
    Type Description
    Task
    Exceptions
    Type Condition
    InvalidOperationException

    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
    Type Name Description
    Guid orgId
    CreateLocationDto locationDto
    Returns
    Type Description
    Task
    Exceptions
    Type Condition
    InvalidOperationException

    CreateOrganizationAsync(CreateOrganizationDto)

    Creates a new organization with admin registration token

    Declaration
    public Task<OrganizationCreationResultDto> CreateOrganizationAsync(CreateOrganizationDto dto)
    Parameters
    Type Name Description
    CreateOrganizationDto dto
    Returns
    Type Description
    Task<OrganizationCreationResultDto>

    CreateOrganizationLegacyAsync(CreateOrganizationDto)

    Legacy method for creating organization (to be deprecated)

    Declaration
    public Task<CreateOrganizationDto> CreateOrganizationLegacyAsync(CreateOrganizationDto dto)
    Parameters
    Type Name Description
    CreateOrganizationDto dto
    Returns
    Type Description
    Task<CreateOrganizationDto>

    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
    Type Description
    Task
    Exceptions
    Type Condition
    KeyNotFoundException

    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
    Type Description
    Task
    Exceptions
    Type Condition
    KeyNotFoundException

    DeleteMemberAsync(Guid, Guid)

    Removes a member from an organization.

    Declaration
    public Task DeleteMemberAsync(Guid userId, Guid organizationId)
    Parameters
    Type Name Description
    Guid userId

    The unique identifier of the user to remove.

    Guid organizationId

    The unique identifier of the organization.

    Returns
    Type Description
    Task

    A task that represents the asynchronous operation.

    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)

    Retrieves all event categories for a specific organization.

    Declaration
    public Task<List<EventCategoryDto>> GetAllCategorysByOrganizationAsync(Guid organizationId)
    Parameters
    Type Name Description
    Guid organizationId

    The unique identifier of the organization.

    Returns
    Type Description
    Task<List<EventCategoryDto>>

    A task that represents the asynchronous operation. The task result contains a list of event category data transfer objects.

    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
    Type Description
    Task<List<LocationDto>>

    GetAllOrganizationsAsync(Guid)

    Gets all organizations for a user.

    Declaration
    public Task<IEnumerable<OrganizationDto>> GetAllOrganizationsAsync(Guid userId)
    Parameters
    Type Name Description
    Guid userId
    Returns
    Type Description
    Task<IEnumerable<OrganizationDto>>

    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
    Type Description
    Task<Organization>
    Exceptions
    Type Condition
    KeyNotFoundException

    GetOrganisationUserByIdAsync(Guid, Guid)

    Declaration
    public Task<UserDto> GetOrganisationUserByIdAsync(Guid userId, Guid orgaId)
    Parameters
    Type Name Description
    Guid userId
    Guid orgaId
    Returns
    Type Description
    Task<UserDto>

    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

    This method is primarily used by the organization settings UI to load current branding configuration. The returned DTO includes all organization details with focus on branding-related properties like BrandingSettings (JSON color configuration) and FileID (logo reference).

    Examples
    var branding = await organizationService.GetOrganizationBrandingAsync(organizationId);
    if (branding != null)
    {
        var colors = JsonSerializer.Deserialize<JsonElement>(branding.BrandingSettings);
        var primaryColor = colors.GetProperty("color1").GetString();
    }

    GetOrganizationDashboardInformation(Guid)

    Gets the organization dashboard information for a user.

    Declaration
    public Task<IEnumerable<OrganizationDashboardDto>> GetOrganizationDashboardInformation(Guid userId)
    Parameters
    Type Name Description
    Guid userId
    Returns
    Type Description
    Task<IEnumerable<OrganizationDashboardDto>>

    GetOrganizationMembersAsync(Guid)

    Gets all members of an organization.

    Declaration
    public Task<List<MemberDto>> GetOrganizationMembersAsync(Guid organizationId)
    Parameters
    Type Name Description
    Guid organizationId
    Returns
    Type Description
    Task<List<MemberDto>>

    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
    Type Description
    Task

    ShowAllLocations(Guid)

    Declaration
    public Task ShowAllLocations(Guid orgID)
    Parameters
    Type Name Description
    Guid orgID
    Returns
    Type Description
    Task

    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
    Type Description
    Task
    Exceptions
    Type Condition
    KeyNotFoundException

    Thrown when organization or users are not found

    InvalidOperationException

    Thrown when operation cannot be performed

    UpdateCategoryByIdAsync(EventCategoryDto)

    Updates an existing event category.

    Declaration
    public Task<EventCategoryDto> UpdateCategoryByIdAsync(EventCategoryDto updateCategoryDto)
    Parameters
    Type Name Description
    EventCategoryDto updateCategoryDto

    The event category data transfer object containing updated information.

    Returns
    Type Description
    Task<EventCategoryDto>

    A task that represents the asynchronous operation. The task result contains the updated event category data transfer object.

    UpdateEventCategory(EventCategoryDto)

    Updates an existing event category. Throws an exception if the category is null.

    Declaration
    public Task UpdateEventCategory(EventCategoryDto eventCategoryDto)
    Parameters
    Type Name Description
    EventCategoryDto eventCategoryDto
    Returns
    Type Description
    Task
    Exceptions
    Type Condition
    KeyNotFoundException

    UpdateLocation(LocationDto)

    Updates an existing location. Throws an exception if the location is null.

    Declaration
    public Task UpdateLocation(LocationDto locationDto)
    Parameters
    Type Name Description
    LocationDto locationDto
    Returns
    Type Description
    Task
    Exceptions
    Type Condition
    KeyNotFoundException

    UpdateLocationByIdAsync(LocationDto)

    Updates an existing location.

    Declaration
    public Task<LocationDto> UpdateLocationByIdAsync(LocationDto updateLocationDto)
    Parameters
    Type Name Description
    LocationDto updateLocationDto

    The location data transfer object containing updated information.

    Returns
    Type Description
    Task<LocationDto>

    A task that represents the asynchronous operation. The task result contains the updated location data transfer object.

    UpdateMemberDetailsAsync(MemberDto)

    Updates the details of an existing organization member.

    Declaration
    public Task UpdateMemberDetailsAsync(MemberDto member)
    Parameters
    Type Name Description
    MemberDto member

    The member data transfer object containing updated information.

    Returns
    Type Description
    Task

    A task that represents the asynchronous operation.

    UpdateMemberRolesAsync(Guid, Guid, bool, bool, bool, bool)

    Updates the roles and permissions of a member within an organization.

    Declaration
    public Task UpdateMemberRolesAsync(Guid userId, Guid organizationId, bool isAdmin, bool isOrganizer, bool isDesigner, bool isExternal)
    Parameters
    Type Name Description
    Guid userId

    The unique identifier of the user whose roles are being updated.

    Guid organizationId

    The unique identifier of the organization.

    bool isAdmin

    Indicates whether the user should have administrator privileges.

    bool isOrganizer

    Indicates whether the user should have organizer privileges.

    bool isDesigner

    Indicates whether the user should have designer privileges.

    bool isExternal

    Indicates whether the user is an external member.

    Returns
    Type Description
    Task

    A task that represents the asynchronous operation.

    UpdateOrganizationAsync(UpdateOrganizationDto)

    Updates an existing organization's information.

    Declaration
    public Task UpdateOrganizationAsync(UpdateOrganizationDto dto)
    Parameters
    Type Name Description
    UpdateOrganizationDto dto

    The organization update data transfer object.

    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

    This method is used by the organization settings UI to save branding changes made by OrgAdmin users. The branding settings should be valid JSON in the expected format. The method preserves the existing logo if no new logo file ID is provided, allowing for color-only updates.

    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

    IOrganizationService
    In this article
    Back to top Generated by DocFX