# Class RelayController

Namespace
  adas_core.Controllers

Assembly
  adas-core.dll

    [ApiController]
    [Route("Relay")]
    public class RelayController : ControllerBase

Inheritance
  object
  ControllerBase
  RelayController

Inherited Members
  ControllerBase.StatusCode(int)
  ControllerBase.StatusCode(int, object)
  ControllerBase.Content(string)
  ControllerBase.Content(string, string)
  ControllerBase.Content(string, string, Encoding)
  ControllerBase.Content(string, MediaTypeHeaderValue)
  ControllerBase.NoContent()
  ControllerBase.Ok()
  ControllerBase.Ok(object)
  ControllerBase.Redirect(string)
  ControllerBase.RedirectPermanent(string)
  ControllerBase.RedirectPreserveMethod(string)
  ControllerBase.RedirectPermanentPreserveMethod(string)
  ControllerBase.LocalRedirect(string)
  ControllerBase.LocalRedirectPermanent(string)
  ControllerBase.LocalRedirectPreserveMethod(string)
  ControllerBase.LocalRedirectPermanentPreserveMethod(string)
  ControllerBase.RedirectToAction()
  ControllerBase.RedirectToAction(string)
  ControllerBase.RedirectToAction(string, object)
  ControllerBase.RedirectToAction(string, string)
  ControllerBase.RedirectToAction(string, string, object)
  ControllerBase.RedirectToAction(string, string, string)
  ControllerBase.RedirectToAction(string, string, object, string)
  ControllerBase.RedirectToActionPreserveMethod(string, string, object, string)
  ControllerBase.RedirectToActionPermanent(string)
  ControllerBase.RedirectToActionPermanent(string, object)
  ControllerBase.RedirectToActionPermanent(string, string)
  ControllerBase.RedirectToActionPermanent(string, string, string)
  ControllerBase.RedirectToActionPermanent(string, string, object)
  ControllerBase.RedirectToActionPermanent(string, string, object, string)
  ControllerBase.RedirectToActionPermanentPreserveMethod(string, string, object, string)
  ControllerBase.RedirectToRoute(string)
  ControllerBase.RedirectToRoute(object)
  ControllerBase.RedirectToRoute(string, object)
  ControllerBase.RedirectToRoute(string, string)
  ControllerBase.RedirectToRoute(string, object, string)
  ControllerBase.RedirectToRoutePreserveMethod(string, object, string)
  ControllerBase.RedirectToRoutePermanent(string)
  ControllerBase.RedirectToRoutePermanent(object)
  ControllerBase.RedirectToRoutePermanent(string, object)
  ControllerBase.RedirectToRoutePermanent(string, string)
  ControllerBase.RedirectToRoutePermanent(string, object, string)
  ControllerBase.RedirectToRoutePermanentPreserveMethod(string, object, string)
  ControllerBase.RedirectToPage(string)
  ControllerBase.RedirectToPage(string, object)
  ControllerBase.RedirectToPage(string, string)
  ControllerBase.RedirectToPage(string, string, object)
  ControllerBase.RedirectToPage(string, string, string)
  ControllerBase.RedirectToPage(string, string, object, string)
  ControllerBase.RedirectToPagePermanent(string)
  ControllerBase.RedirectToPagePermanent(string, object)
  ControllerBase.RedirectToPagePermanent(string, string)
  ControllerBase.RedirectToPagePermanent(string, string, string)
  ControllerBase.RedirectToPagePermanent(string, string, object, string)
  ControllerBase.RedirectToPagePreserveMethod(string, string, object, string)
  ControllerBase.RedirectToPagePermanentPreserveMethod(string, string, object, string)
  ControllerBase.File(byte[], string)
  ControllerBase.File(byte[], string, bool)
  ControllerBase.File(byte[], string, string)
  ControllerBase.File(byte[], string, string, bool)
  ControllerBase.File(byte[], string, DateTimeOffset?, EntityTagHeaderValue)
  ControllerBase.File(byte[], string, DateTimeOffset?, EntityTagHeaderValue, bool)
  ControllerBase.File(byte[], string, string, DateTimeOffset?, EntityTagHeaderValue)
  ControllerBase.File(byte[], string, string, DateTimeOffset?, EntityTagHeaderValue, bool)
  ControllerBase.File(Stream, string)
  ControllerBase.File(Stream, string, bool)
  ControllerBase.File(Stream, string, string)
  ControllerBase.File(Stream, string, string, bool)
  ControllerBase.File(Stream, string, DateTimeOffset?, EntityTagHeaderValue)
  ControllerBase.File(Stream, string, DateTimeOffset?, EntityTagHeaderValue, bool)
  ControllerBase.File(Stream, string, string, DateTimeOffset?, EntityTagHeaderValue)
  ControllerBase.File(Stream, string, string, DateTimeOffset?, EntityTagHeaderValue, bool)
  ControllerBase.File(string, string)
  ControllerBase.File(string, string, bool)
  ControllerBase.File(string, string, string)
  ControllerBase.File(string, string, string, bool)
  ControllerBase.File(string, string, DateTimeOffset?, EntityTagHeaderValue)
  ControllerBase.File(string, string, DateTimeOffset?, EntityTagHeaderValue, bool)
  ControllerBase.File(string, string, string, DateTimeOffset?, EntityTagHeaderValue)
  ControllerBase.File(string, string, string, DateTimeOffset?, EntityTagHeaderValue, bool)
  ControllerBase.PhysicalFile(string, string)
  ControllerBase.PhysicalFile(string, string, bool)
  ControllerBase.PhysicalFile(string, string, string)
  ControllerBase.PhysicalFile(string, string, string, bool)
  ControllerBase.PhysicalFile(string, string, DateTimeOffset?, EntityTagHeaderValue)
  ControllerBase.PhysicalFile(string, string, DateTimeOffset?, EntityTagHeaderValue, bool)
  ControllerBase.PhysicalFile(string, string, string, DateTimeOffset?, EntityTagHeaderValue)
  ControllerBase.PhysicalFile(string, string, string, DateTimeOffset?, EntityTagHeaderValue, bool)
  ControllerBase.Unauthorized()
  ControllerBase.Unauthorized(object)
  ControllerBase.NotFound()
  ControllerBase.NotFound(object)
  ControllerBase.BadRequest()
  ControllerBase.BadRequest(object)
  ControllerBase.BadRequest(ModelStateDictionary)
  ControllerBase.UnprocessableEntity()
  ControllerBase.UnprocessableEntity(object)
  ControllerBase.UnprocessableEntity(ModelStateDictionary)
  ControllerBase.Conflict()
  ControllerBase.Conflict(object)
  ControllerBase.Conflict(ModelStateDictionary)
  ControllerBase.Problem(string, string, int?, string, string)
  ControllerBase.ValidationProblem(ValidationProblemDetails)
  ControllerBase.ValidationProblem(ModelStateDictionary)
  ControllerBase.ValidationProblem()
  ControllerBase.ValidationProblem(string, string, int?, string, string, ModelStateDictionary)
  ControllerBase.Created()
  ControllerBase.Created(string, object)
  ControllerBase.Created(Uri, object)
  ControllerBase.CreatedAtAction(string, object)
  ControllerBase.CreatedAtAction(string, object, object)
  ControllerBase.CreatedAtAction(string, string, object, object)
  ControllerBase.CreatedAtRoute(string, object)
  ControllerBase.CreatedAtRoute(object, object)
  ControllerBase.CreatedAtRoute(string, object, object)
  ControllerBase.Accepted()
  ControllerBase.Accepted(object)
  ControllerBase.Accepted(Uri)
  ControllerBase.Accepted(string)
  ControllerBase.Accepted(string, object)
  ControllerBase.Accepted(Uri, object)
  ControllerBase.AcceptedAtAction(string)
  ControllerBase.AcceptedAtAction(string, string)
  ControllerBase.AcceptedAtAction(string, object)
  ControllerBase.AcceptedAtAction(string, string, object)
  ControllerBase.AcceptedAtAction(string, object, object)
  ControllerBase.AcceptedAtAction(string, string, object, object)
  ControllerBase.AcceptedAtRoute(object)
  ControllerBase.AcceptedAtRoute(string)
  ControllerBase.AcceptedAtRoute(string, object)
  ControllerBase.AcceptedAtRoute(object, object)
  ControllerBase.AcceptedAtRoute(string, object, object)
  ControllerBase.Challenge()
  ControllerBase.Challenge(params string[])
  ControllerBase.Challenge(AuthenticationProperties)
  ControllerBase.Challenge(AuthenticationProperties, params string[])
  ControllerBase.Forbid()
  ControllerBase.Forbid(params string[])
  ControllerBase.Forbid(AuthenticationProperties)
  ControllerBase.Forbid(AuthenticationProperties, params string[])
  ControllerBase.SignIn(ClaimsPrincipal)
  ControllerBase.SignIn(ClaimsPrincipal, string)
  ControllerBase.SignIn(ClaimsPrincipal, AuthenticationProperties)
  ControllerBase.SignIn(ClaimsPrincipal, AuthenticationProperties, string)
  ControllerBase.SignOut()
  ControllerBase.SignOut(AuthenticationProperties)
  ControllerBase.SignOut(params string[])
  ControllerBase.SignOut(AuthenticationProperties, params string[])
  ControllerBase.TryUpdateModelAsync<TModel>(TModel)
  ControllerBase.TryUpdateModelAsync<TModel>(TModel, string)
  ControllerBase.TryUpdateModelAsync<TModel>(TModel, string, IValueProvider)
  ControllerBase.TryUpdateModelAsync<TModel>(TModel, string, params Expression<Func<TModel, object>>[])
  ControllerBase.TryUpdateModelAsync<TModel>(TModel, string, Func<ModelMetadata, bool>)
  ControllerBase.TryUpdateModelAsync<TModel>(TModel, string, IValueProvider, params Expression<Func<TModel, object>>[])
  ControllerBase.TryUpdateModelAsync<TModel>(TModel, string, IValueProvider, Func<ModelMetadata, bool>)
  ControllerBase.TryUpdateModelAsync(object, Type, string)
  ControllerBase.TryUpdateModelAsync(object, Type, string, IValueProvider, Func<ModelMetadata, bool>)
  ControllerBase.TryValidateModel(object)
  ControllerBase.TryValidateModel(object, string)
  ControllerBase.HttpContext
  ControllerBase.Request
  ControllerBase.Response
  ControllerBase.RouteData
  ControllerBase.ModelState
  ControllerBase.ControllerContext
  ControllerBase.MetadataProvider
  ControllerBase.ModelBinderFactory
  ControllerBase.Url
  ControllerBase.ObjectValidator
  ControllerBase.ProblemDetailsFactory
  ControllerBase.User
  ControllerBase.Empty
  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

### RelayController(IOptions<RecordingSettings>, IRelayService, ILogger<RelayController>, IPointOfCareService)

    public RelayController(IOptions<RecordingSettings> recordingSettings, IRelayService relayService, ILogger<RelayController> logger, IPointOfCareService pointOfCareService)

#### Parameters

`recordingSettings` IOptions<RecordingSettings>
`relayService` IRelayService
`logger` ILogger<RelayController>
`pointOfCareService` IPointOfCareService

## Methods

### CheckRelayStatus(int, string, string, int, string, int, string, string)

Checks the status of a relay device by building a relay configuration from the supplied parameters and delegating the status check to the relay service.

    [HttpPost]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthAdmin)]
    [Route("{id}/status")]
    public IActionResult CheckRelayStatus(int id, string driver, string host, int port, string relayName, int total, string username, string password)

#### Parameters

`id` int

  The relay number identifier used to select the specific relay.

`driver` string

  The driver type used to communicate with the relay.

`host` string

  The host IP address of the relay device.

`port` int

  The network port used to connect to the relay device.

`relayName` string

  The name assigned to the relay configuration.

`total` int

  The total number of relays in the configuration.

`username` string

  The username used for relay authentication.

`password` string

  The password used for relay authentication.

#### Returns

IActionResult

  An IActionResult containing the relay status result returned by the relay service.

### CheckSectionStatus()

Retrieves the status of point-of-care sections by querying the relay status for each configured box and its associated relays. Returns a 404 Not Found when no configurations are available, or a list containing the unit, bed, and status for each relay when configurations exist.

    [HttpGet]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    [Route("status")]
    public Task<IActionResult> CheckSectionStatus()

#### Returns

Task<IActionResult>

  An IActionResult that is either a 404 Not Found when no configurations are found, or an HTTP 200 OK response containing a collection of objects with the unit name, bed, and relay status.

### CreateRelay(Relay?)

Creates a new relay based on the provided request payload. Throws a bad request exception if the request body is missing required parameters.

    [HttpPost]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    public Task<IActionResult> CreateRelay(Relay? request)

#### Parameters

`request` Relay

  The relay data to create, supplied in the request body.

#### Returns

Task<IActionResult>

  An IActionResult containing the created relay.

#### Exceptions

BadRequestException

  Thrown when the `request` is null.

### GetPaginatedUnits(PaginationFilter, bool)

Retrieves a paginated list of relays based on the provided pagination filter.

    [HttpPost("paginated")]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    public Task<IActionResult> GetPaginatedUnits(PaginationFilter request, bool withPoCs)

#### Parameters

`request` PaginationFilter

  The pagination filter containing the paging parameters.

`withPoCs` bool

  Flag indicating whether to include related point of contact data in the response.

#### Returns

Task<IActionResult>

  An IActionResult containing the paginated relays.

#### Exceptions

BadRequestException

  Thrown when the `request` is null.

### ManualSwitch(string, string, string)

Manually switches a relay for a specific point of connection (POC) to a given status and type. Validates the input parameters and returns a bad request if the status, type, or POC identifier cannot be parsed; returns an internal server error if an unexpected exception occurs, otherwise returns a successful response.

    [HttpPost]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    [Route("manual/{status}")]
    public IActionResult ManualSwitch(string status, string pocId, string type)

#### Parameters

`status` string

  The desired relay status as a string, which is parsed into RelayEnum.Status.

`pocId` string

  The identifier of the point of connection, which must be a valid ObjectId string.

`type` string

  The relay type as a string, which is parsed into RelayEnum.Type.

#### Returns

IActionResult

  An IActionResult indicating the outcome: BadRequestResult for invalid input, StatusCodeResult for internal server errors, or OkObjectResult with `false` on success.

### PowerOff(int, string, string, int, string, int, string, string?)

Powers off a relay identified by the given id using the provided relay configuration parameters. On failure to power off the relay, returns an Internal Server Error status; otherwise returns OK with a false result.

    [HttpPost]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    [Route("{id}/power/off")]
    public IActionResult PowerOff(int id, string driver, string host, int port, string relayName, int total, string username, string? password)

#### Parameters

`id` int

  The identifier of the relay to power off.

`driver` string

  The relay driver type to use for the operation.

`host` string

  The host address of the relay device.

`port` int

  The port number used to communicate with the relay device.

`relayName` string

  The name assigned to the relay.

`total` int

  The total number of relays managed by the device.

`username` string

  The username used for relay authentication.

`password` string

  The optional password used for relay authentication.

#### Returns

IActionResult

  An IActionResult indicating the outcome: Ok with a false value on success, or an Internal Server Error status if the power off operation fails.

### PowerOffPoC(PowerActionRequest)

Powers off the relay configuration for the specified unit, point of care, and bed by delegating the operation to the relay service.

    [HttpPost]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    [Route("powerOff")]
    public Task<IActionResult> PowerOffPoC(PowerActionRequest action)

#### Parameters

`action` PowerActionRequest

  The power action request containing the unit identifier, point of care identifier, and bed information.

#### Returns

Task<IActionResult>

  An IActionResult representing the result of the power off operation.

### PowerOn(int, string, string, int, string, int, string, string?)

Powers on the relay identified by the specified id using the provided connection configuration. Returns HTTP 200 with a success indicator when the relay is powered on, or HTTP 500 if the relay service throws an exception.

    [HttpPost]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    [Route("{id}/power/on")]
    public IActionResult PowerOn(int id, string driver, string host, int port, string relayName, int total, string username, string? password)

#### Parameters

`id` int

  The identifier of the relay to power on.

`driver` string

  The relay driver to use for the connection.

`host` string

  The host address of the relay device.

`port` int

  The port number used to connect to the relay device.

`relayName` string

  The name assigned to the relay.

`total` int

  The total number of relays managed by the device.

`username` string

  The username used to authenticate with the relay device.

`password` string

  The optional password used to authenticate with the relay device.

#### Returns

IActionResult

  An IActionResult containing HTTP 200 with a success value on success, or HTTP 500 if the relay service fails.

### PowerOnPoC(PowerActionRequest)

Handles a power-on request for a Point of Care (PoC) device by delegating to the shared power action pipeline and turning on the configured relay for the specified unit, point of care, and bed.

    [HttpPost]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    [Route("powerOn")]
    public Task<IActionResult> PowerOnPoC(PowerActionRequest action)

#### Parameters

`action` PowerActionRequest

  The request payload containing the identifiers of the unit, point of care, and bed to power on.

#### Returns

Task<IActionResult>

  An IActionResult representing the result of the power-on operation.

### UpdateRelay(Relay, string)

Updates an existing relay identified by the specified id with the provided relay data.

    [HttpPut("{id}")]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    public Task<IActionResult> UpdateRelay(Relay relay, string id)

#### Parameters

`relay` Relay

  The relay data to apply to the existing record.

`id` string

  The identifier of the relay to update, expected to be a valid ObjectId.

#### Returns

Task<IActionResult>

  An IActionResult containing the updated relay when the operation succeeds.

#### Exceptions

BadRequestException

  Thrown when the provided `id` cannot be parsed as a valid ObjectId.