public void InitDatabase() { Room r = new Room { Name = "Szoba" }; CommunicationUnit e = new CommunicationUnit { Code = "espcode", IPAddress = "0.0.0.159" }; Device s = new Device { CommunicationUnit = e, CommunicationUnitId = e.Id, Room = r, RoomId = r.Id, Type = "temperature", Name = "DHT11", IO = false }; Device ss = new Device { CommunicationUnit = e, CommunicationUnitId = e.Id, Room = r, RoomId = r.Id, Type = "humidity", Name = "DHT11", IO = false }; Device sss = new Device { CommunicationUnit = e, CommunicationUnitId = e.Id, Room = r, RoomId = r.Id, Type = "heater", Name = "lampa", IO = true }; _ctx.Add(r); _ctx.Add(e); _ctx.Add(s); _ctx.Add(ss); _ctx.Add(sss); _ctx.SaveChanges(); }
public void AddNewRoom(string name) { Room r = new Room { Name = name }; _ctx.Add(r); _ctx.SaveChangesAsync(); }
public void InitDevice(Device device) { Device d = (from q in _ctx.Devices where q.CommunicationUnitId == device.CommunicationUnitId && q.Type == device.Type select q).FirstOrDefault(); if (d == null) { _ctx.Add(device); _ctx.SaveChanges(); } }
public int InsertNewCommunicationUnit(string chipId) { CommunicationUnit c = _ctx.CommunicationUnits.Where(w => w.Code == chipId).FirstOrDefault(); if (c == null) { c = new CommunicationUnit { Code = chipId }; _ctx.Add(c); _ctx.SaveChanges(); } return(c.Id); }