public async Task <bool> Log(SpindelLog data) { if (ReadOnly) { return(false); } try { var device = await _context.Devices.SingleOrDefaultAsync(d => d.Name == data.name); if (device == null) { // Create a new Device device = new Device() { Name = data.name, Token = data.token, SpindelId = data.ID, Description = "New iSpindel" }; await _context.Devices.AddAsync(device); } var log = new Log() { Angle = data.angle, Temperature = data.temperature, TempUnits = data.temp_units, Battery = data.battery, Gravity = data.gravity, Interval = data.interval, RSSI = data.interval, DeviceId = device.DeviceId }; var batch = await _context.Batches.SingleOrDefaultAsync(b => b.DeviceId == device.DeviceId && !b.EndDate.HasValue); if (batch != null) { log.BatchId = batch.BatchId; } await _context.Logs.AddAsync(log); var res = await _context.SaveChangesAsync(); return(true); } catch (Exception e) { Console.WriteLine(e); throw; } }
public async Task <ActionResult <bool> > Log(SpindelLog data) { return(await _logDb.Log(data)); }