public DevicesServiceImpl(ApplicationClass application) { if (devicesDao == null) { devicesDao = new DevicesDao(application); } }
public void DeleteDevice(int id) { DevicesDao toDelete = _ctx.Devices.First(d => d.DeviceId == id); _ctx.Devices.Remove(toDelete); _ctx.SaveChanges(); }
public IotDevice ReadDevice(int deviceId, bool details) { DevicesDao deviceDao = details ? _ctx.Devices.AsNoTracking().First(d => d.DeviceId == deviceId) : _ctx.Devices.First(d => d.DeviceId == deviceId); ExtensionMethods.CheckForNotFound(deviceDao, "IOT_Device", deviceId); return(ConvertToDomain(deviceDao)); }
private IotDevice ConvertToDomain(DevicesDao dao) { return(new IotDevice { Id = dao.DeviceId, LocationX = dao.LocationX, LocationY = dao.LocationY }); }
public void Update(IotDevice obj) { DevicesDao newDevice = ConvertToDao(obj); DevicesDao foundDevice = _ctx.Devices.First(d => d.DeviceId == obj.Id); if (foundDevice != null) { foundDevice.LocationX = newDevice.LocationX; foundDevice.LocationY = newDevice.LocationY; } _ctx.SaveChanges(); }