public override IValidationResult IsValid(UpdateFanTaskProcessorRequestVersionOne record) { var existingRelays = _relayClient.GetRelays(); var jobExists = JobStateHelper.GetJobByName(record.JobName) != null; if (record?.RelayGpioPin != null && !existingRelays.Any(r => r.GpioPin == record.RelayGpioPin)) { return(new ValidationResult { Message = $"Could not find a relay with the gpio pin: {record.RelayGpioPin}", StatusCode = System.Net.HttpStatusCode.NotFound }); } if (!jobExists) { return(new ValidationResult { Message = $"Could not find any jobs with the name: {record.JobName}", StatusCode = System.Net.HttpStatusCode.NotFound }); } return(null); }
public override IValidationResult IsValid(GetRelayStateProcessorRequestVersionOne record) { var existingRelays = _relayClient.GetRelays(); if (existingRelays.FirstOrDefault(r => r.GpioPin == record?.GpioPin) != null) { return(null); } return(new ValidationResult { Message = $"Could not find a relay with the gpio pin: {record.GpioPin}", StatusCode = System.Net.HttpStatusCode.NotFound }); }
public override IActionResult ProcessRequest(GetRelaysProcessorRequestVersionOne record) { var result = _relayClient.GetRelays(); if (result == null) { return(new ObjectResult(new GetRelaysProcessorResponseVersionOne() { IsSuccess = false, Errors = new List <string> { "No relays exist." }, Relays = null, StatusCode = System.Net.HttpStatusCode.NotFound })); } return(new ObjectResult(new GetRelaysProcessorResponseVersionOne() { IsSuccess = true, Relays = result, StatusCode = System.Net.HttpStatusCode.OK })); }