Exemplo n.º 1
0
        public IActionResult Put([FromBody] DeviceConfigurationViewModel model)
        {
            if (model == null)
            {
                return(StatusCode(500, new InternalServerError()));
            }

            var deviceConfiguration = new DeviceConfiguration
            {
                DeviceId  = model.DeviceId,
                MeasureId = model.MeasureId,
                Value     = model.Value
            };

            _context.DeviceConfigurations.Add(deviceConfiguration);
            _context.SaveChanges();

            deviceConfiguration.Measure = _context.Measures.Where(p => p.Id == deviceConfiguration.MeasureId).FirstOrDefault();
            deviceConfiguration.Device  = _context.Devices.Where(p => p.Id == deviceConfiguration.DeviceId).FirstOrDefault();

            return(Json(deviceConfiguration.Adapt <DeviceConfigurationViewModel>()));
        }