Пример #1
0
        public void UpdateDeviceCommand(int commandId, JObject command)
        {
            if (commandId == 0)
            {
                throw new WebSocketRequestException("Please specify valid commandId");
            }

            if (command == null)
            {
                throw new WebSocketRequestException("Please specify command");
            }

            var commandEntity = DataContext.DeviceCommand.Get(commandId);

            if (commandEntity == null || commandEntity.DeviceID != CurrentDevice.ID)
            {
                throw new WebSocketRequestException("Device command not found");
            }

            CommandMapper.Apply(commandEntity, command);
            commandEntity.Device = CurrentDevice;
            Validate(commandEntity);

            DataContext.DeviceCommand.Save(commandEntity);
            _messageBus.Notify(new DeviceCommandUpdatedMessage(CurrentDevice.ID, commandEntity.ID));

            command = CommandMapper.Map(commandEntity);
            SendResponse(new JProperty("command", command));
        }