public void Seed() { if ( _context.Commands.Any() || _context.TemperatureAndHumidity.Any() ) { return; //DB has been seeded. } Commands com1 = new Commands { Id = 1, ComponentName = "White LED", On = 1, Off = 2, Status = 2 }; Commands com2 = new Commands { Id = 2, ComponentName = "Yellow LED", On = 3, Off = 4, Status = 4 }; Commands com3 = new Commands { Id = 3, ComponentName = "Red LED", On = 5, Off = 6, Status = 6 }; Commands com4 = new Commands { Id = 4, ComponentName = "Green LED", On = 7, Off = 8, Status = 8 }; _context.AddRange(com1, com2, com3, com4); _context.SaveChanges(); }
public string SendCommand(int id, string command) { var component = _context.Commands.First(x => x.Id == id); if (command == "On") { component.Status = component.On; component.Status_Enum = Models.Enums.StatusEnum.On; } else { component.Status = component.Off; component.Status_Enum = Models.Enums.StatusEnum.Off; } _context.Commands.Update(component); _context.SaveChanges(); return(command); }