Exemplo n.º 1
0
        public HttpResponseMessage SetDeviceState(string deviceId, string state = null)
        {
            var device = _deviceRepository.FindById(deviceId);

            if (device == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, $"The device with id '{deviceId}' does not exist."));
            }

            device.State = _deviceStateSerializer.Deserialize(state);
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Exemplo n.º 2
0
        public ActionResult Device(string id, string state = null)
        {
            var device = _deviceRepository.FindById(id);

            if (device == null)
            {
                return(HttpNotFound($"The device with {id} does not exist."));
            }

            if (state != null)
            {
                device.State = _deviceStateSerializer.Deserialize(state);
                _deviceRepository.Save(device);
            }

            var deviceModel = Mapper.Map <DeviceDetailModel>(device);

            return(View(deviceModel));
        }