示例#1
0
        public async Task <IActionResult> PutTemperatureData([FromRoute] Guid id, [FromBody] TemperatureData temperatureData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != temperatureData.ID)
            {
                return(BadRequest());
            }

            _context.Entry(temperatureData).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TemperatureDataExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#2
0
        public async Task <ActionResult <Device> > RegisterDevice()
        {
            var    device    = new Device();
            string setupCode = "";

            do
            {
                setupCode = Device.CreateSetupCode();
            } while (_context.Devices.Count(x => x.SetupCode.Equals(setupCode)) != 0);

            device.SetupCode = setupCode;

            _context.Devices.Add(device);

            await _context.SaveChangesAsync();

            return(device);
        }