public ExecuteSmartObjectCommandResult Execute(string smartObjectId, [FromBody] ExecuteSmartObjectCommand command) { if (command == null) { command = new ExecuteSmartObjectCommand(); } command.SetSmartObjectId(smartObjectId); return(Execute <ExecuteSmartObjectCommand, ExecuteSmartObjectCommandResult>(command)); }
public ExecuteSmartObjectCommandResult Handle(ExecuteSmartObjectCommand command) { ExecuteSmartObjectCommandResult result = new ExecuteSmartObjectCommandResult(); ObjectId smartObjectId = new ObjectId(); if (string.IsNullOrEmpty(command.SmartObjectId) || !ObjectId.TryParse(command.SmartObjectId, out smartObjectId)) { AddNotification(nameof(command.SmartObjectId), ENotifications.InvalidId); } if (Valid) { SmartObject smartObject = _smartObjectRepository.Get(smartObjectId); if (smartObject == null && _smartObjectRepository.Valid) { AddNotification(nameof(smartObject), ENotifications.DoesNotExist); } if (Valid) { SmartObjectExecutionResult executionResult = _smartObjectCommunicationService.Execute(smartObject.IpAddress, smartObject.Port, command.Action); if (executionResult.Valid) { result = new ExecuteSmartObjectCommandResult(HttpStatusCode.OK, Notifications, executionResult.Result); } } else { result = new ExecuteSmartObjectCommandResult(HttpStatusCode.BadRequest, Notifications); } } else { result = new ExecuteSmartObjectCommandResult(HttpStatusCode.BadRequest, Notifications); } return(result); }