# Class NoticeService

Namespace
  adas_core.Application.Services

Assembly
  adas-core.Application.dll

    public class NoticeService : INoticeService

Inheritance
  object
  NoticeService

Implements
  INoticeService

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

### NoticeService(ILogger<NoticeService>, ISubscribersService, INoticeRepository, IClientMessageService, IDisplayService, IHttpContextAccessor, ILocalAuditService)

    public NoticeService(ILogger<NoticeService> logger, ISubscribersService subscribersService, INoticeRepository noticeRepository, IClientMessageService clientMessageService, IDisplayService displayService, IHttpContextAccessor httpContextAccessor, ILocalAuditService auditService)

#### Parameters

`logger` ILogger<NoticeService>
`subscribersService` ISubscribersService
`noticeRepository` INoticeRepository
`clientMessageService` IClientMessageService
`displayService` IDisplayService
`httpContextAccessor` IHttpContextAccessor
`auditService` ILocalAuditService

## Methods

### DeleteNoticeAsync(Notice)

Deletes the specified notice by delegating to the ID-based deletion routine.

    public Task DeleteNoticeAsync(Notice notice)

#### Parameters

`notice` Notice

  The notice to delete; its `Id` is used to identify the record to remove.

#### Returns

Task

### DeleteNoticeByIdAsync(ObjectId)

Deletes a notice identified by its unique ID, creating an audit log entry and broadcasting the deletion when successful. If the notice is not found, the operation is logged and the method returns without making changes; any unexpected exception is logged without being rethrown.

    public Task DeleteNoticeByIdAsync(ObjectId noticeId)

#### Parameters

`noticeId` ObjectId

  The unique identifier of the notice to delete.

#### Returns

Task

### GetNoticeByIdAsync(ObjectId)

Retrieves a notice by its unique identifier asynchronously. Returns `null` if an error occurs during the lookup, with the exception being logged.

    public Task<Notice?> GetNoticeByIdAsync(ObjectId noticeId)

#### Parameters

`noticeId` ObjectId

  The unique MongoDB.Bson.ObjectId of the notice to retrieve.

#### Returns

Task<Notice>

  A Notice instance if found; otherwise, `null` when an exception is thrown during the search.

### GetNoticeByTypeAsync(string)

Asynchronously retrieves a collection of notices filtered by the specified notice type. If no notices are found for the given type, a NotFoundException is thrown.

    public Task<IEnumerable<Notice>?> GetNoticeByTypeAsync(string noticeType)

#### Parameters

`noticeType` string

  The type of notice to filter the search by.

#### Returns

Task<IEnumerable<Notice>>

  A task that represents the asynchronous operation, containing a collection of Notice objects matching the specified type.

#### Exceptions

NotFoundException

  Thrown when no notices are found for the specified `noticeType`.

### GetNoticesAsync()

Retrieves all notices from the repository asynchronously.

    public Task<IEnumerable<Notice>> GetNoticesAsync()

#### Returns

Task<IEnumerable<Notice>>

  A task that represents the asynchronous operation. The task result contains a collection of all Notice entities.

### GetNoticesByDisplayId(ObjectId)

Retrieves a collection of notices associated with the specified display identifier. Returns null if an error occurs while querying the notice repository.

    public Task<IEnumerable<Notice>?> GetNoticesByDisplayId(ObjectId displayId)

#### Parameters

`displayId` ObjectId

  The ObjectId of the display used to look up associated notices.

#### Returns

Task<IEnumerable<Notice>>

  A task containing an IEnumerable<T> of Notice objects matching the display, or null if the operation fails.

### InsertNotice(Notice)

Inserts a new notice, creates an audit log entry, and broadcasts a notification about the new notice. Returns null if an exception occurs during the operation.

    public Task<Notice?> InsertNotice(Notice notice)

#### Parameters

`notice` Notice

  The notice to insert. A new identifier is assigned before persistence.

#### Returns

Task<Notice>

  The inserted notice with its newly assigned identifier, or null if the operation fails.

### SaveRequest(ApiRequest)

Processes an API request to create, update, or delete a notice based on the request type. Validates required fields for new and updated notices, skips processing when the notice or its description is missing, and logs any exceptions encountered.

    public Task SaveRequest(ApiRequest apiRequest)

#### Parameters

`apiRequest` ApiRequest

  The API request containing the notice payload and the operation type (NewNotice, UpdateNotice, or DeleteNotice) to perform.

#### Returns

Task

### SaveRequestAsync(ApiRequest)

Asynchronously saves the specified API request by executing the save operation on a background thread.

    public Task SaveRequestAsync(ApiRequest apiRequest)

#### Parameters

`apiRequest` ApiRequest

  The API request to save.

#### Returns

Task

  A task that represents the asynchronous save operation.

### UpdateNoticeAsync(Notice)

Updates an existing notice, records an audit log entry, and broadcasts the update notification. If no notice is found by the supplied identifier, a conflict exception is thrown. Errors are caught and logged.

    public Task UpdateNoticeAsync(Notice notice)

#### Parameters

`notice` Notice

  The notice entity containing the updated data.

#### Returns

Task

#### Exceptions

ConflictException

  Thrown when the notice cannot be found in the repository.