# Class AuthorityService

Namespace
  adas_core.Authentication

Assembly
  adas-core.Authentication.dll

    public class AuthorityService : IAuthorityService

Inheritance
  object
  AuthorityService

Implements
  IAuthorityService

Inherited Members
  object.Equals(object)
  object.Equals(object, object)
  object.GetHashCode()
  object.GetType()
  object.MemberwiseClone()
  object.ReferenceEquals(object, object)
  object.ToString()

Extension Methods
  NumberUtils.IsNumber(object)
  NumberUtils.ToDouble(object)
  ObjectUtils.ToStr(object?)

## Constructors

### AuthorityService(IAuthorityRepository, IHttpContextAccessor, ILocalAuditService)

    public AuthorityService(IAuthorityRepository authorityRepository, IHttpContextAccessor httpContextAccessor, ILocalAuditService auditService)

#### Parameters

`authorityRepository` IAuthorityRepository
`httpContextAccessor` IHttpContextAccessor
`auditService` ILocalAuditService

## Methods

### CreateNew(string, ObjectId)

Creates a new authority for the specified user with the given role name by delegating to the authority repository.

    public void CreateNew(string roleName, ObjectId userId)

#### Parameters

`roleName` string

  The name of the role to associate with the authority.

`userId` ObjectId

  The unique identifier of the user for whom the authority is being created.

### CreateNewUserAuthority(Authorization)

Creates a new user authority by persisting the provided authorization record and writing an audit log entry for the operation.

    public Task<Authorization?> CreateNewUserAuthority(Authorization authorization)

#### Parameters

`authorization` Authorization

  The authorization entity to be created and stored.

#### Returns

Task<Authorization>

  The created Authorization entity.

### DeleteAuthoritiesForUser(ObjectId)

Deletes all authorities associated with the specified user and records an audit log entry for each removed authority. Returns `false` if no authorities were deleted or if an exception is encountered during processing.

    public Task<bool> DeleteAuthoritiesForUser(ObjectId id)

#### Parameters

`id` ObjectId

  The unique identifier of the user whose authorities should be deleted.

#### Returns

Task<bool>

  `true` if the authorities were successfully deleted; otherwise, `false`.

### DeleteUserAuthority(ObjectId)

Deletes a user authority by its parsed identifier and records an audit log entry when the deletion succeeds. Returns `true` if the authority was found and removed, and `false` when the entity is not found or an exception occurs during processing.

    public Task<bool> DeleteUserAuthority(ObjectId userAuthorityIdParsed)

#### Parameters

`userAuthorityIdParsed` ObjectId

  The parsed identifier of the user authority to delete.

#### Returns

Task<bool>

  `true` if the user authority was successfully deleted; otherwise, `false`.

### EditUserAuthority(Authorization)

Edits an existing user authority, records the change in an audit log, and returns the updated authorization. Returns `null` if the update operation fails due to an exception.

    public Task<Authorization?> EditUserAuthority(Authorization authorization)

#### Parameters

`authorization` Authorization

  The authorization entity containing the updated information to persist.

#### Returns

Task<Authorization>

  The updated Authorization on success, or `null` if an error occurs during the operation.

### GetAllAuthorities()

Retrieves all available authorities from the underlying repository.

    public Task<List<Authorization>> GetAllAuthorities()

#### Returns

Task<List<Authorization>>

  A task that represents the asynchronous operation, containing a list of all Authorization records.

### GetUserAuthorities(ObjectId)

Retrieves the authorities of the specified user.

    public Task<List<Authorization>> GetUserAuthorities(ObjectId userId)

#### Parameters

`userId` ObjectId

#### Returns

Task<List<Authorization>>

  A list of the user's authorities.

### InsertOne(Authorization)

Inserts a new `authorization` into the authority repository and records an audit log entry for the operation using the current HTTP context user.

    public Task InsertOne(Authorization authorization)

#### Parameters

`authorization` Authorization

  The authorization entity to be inserted and tracked in the audit log.

#### Returns

Task

### updateOne(Authorization)

Updates an existing authorization record in the repository and records an audit log entry capturing the previous and updated states for the current user.

    public Task updateOne(Authorization authorization)

#### Parameters

`authorization` Authorization

  The authorization entity containing the identifier of the record to update and its new values.

#### Returns

Task