public async Task SetState(string deviceId, bool state) { var currentState = await Db.States.Where(x => x.DeviceId == deviceId).SingleOrDefaultAsync(); if (currentState == null) { currentState = new CombiStateEntity() { DeviceId = deviceId, CreatedAt = Now, Value = state }; Db.States.Add(currentState); } else { currentState.Value = state; } await Db.SaveChangesAsync(); }
public async Task <bool> Get(string deviceId) { var state = await Db.States.Where(x => x.DeviceId == deviceId).SingleOrDefaultAsync(); if (state != null) { return(state.Value); } else { state = new CombiStateEntity() { DeviceId = deviceId, Value = true, CreatedAt = Now }; Db.States.Add(state); await Db.SaveChangesAsync(); return(true); } }