public IActionResult RegisterDevice([FromBody] DeviceRequest request) { if (request == null || string.IsNullOrWhiteSpace(request.Token) || !AdamantUtilities.IsValidAdamantAddress(request.Address)) { return(BadRequest()); } // Drop previous registration, if exist var prevDevice = _context.Devices.FirstOrDefault(d => d.Token == request.Token); if (prevDevice != null) { _context.Devices.Remove(prevDevice); } // Add new device var device = new Device { Address = request.Address, Token = request.Token, RegistrationDate = DateTime.Now }; _context.Devices.Add(device); // Save changes _context.SaveChanges(); return(Ok()); }
public IActionResult Delete(int Id) { //here, get the student from the database in the real application //getting a student from collection for demo purpose var std = db.Products.Where(s => s.Id == Id).FirstOrDefault(); db.Products.Remove(std); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Add(string deviceType) { Device newDevice; Factory factory = new Factory(); switch (deviceType) { default: newDevice = factory.GetConditioner(); break; case "convector": newDevice = factory.GetConvector(); break; case "energyMeter": newDevice = factory.GetEnergyMeter(); break; case "temperatureSensor": newDevice = factory.GetTemperatureSensor(); break; } db.Devices.Add(newDevice); db.SaveChanges(); return(RedirectToAction("Index")); }
public void Delete(int id) { try { TeleVision tv = dbconnect.TeleVision.Include(p => p.DVDs).Where(p => p.Id == id).FirstOrDefault(); dbconnect.TeleVision.Remove(tv); dbconnect.SaveChanges(); IDictionary <int, Models.Devices.Device> filtrDevice = new SortedDictionary <int, Models.Devices.Device>(); } catch { IDictionary <int, Models.Devices.Device> filtrDevice = new SortedDictionary <int, Models.Devices.Device>(); } }
public MoveSensorController(DevicesContext context) { this.db = context; if (!db.MoveSensors.Any()) { db.MoveSensors.Add(new MoveSensor { Name = "SCP-173", Company = "Secure Contain Protect", Power = false, IsConect = false, IsMove = false, IsSecureMod = false }); db.MoveSensors.Add(new MoveSensor { Name = "Move-500", Company = "Shield", Power = true, IsConect = false, IsMove = false, IsSecureMod = false }); db.SaveChanges(); } }
public LampController(DevicesContext context) { this.db = context; if (!db.Lamps.Any()) { db.Lamps.Add(new Lamp { Name = "Lamp 220v", Company = "Light And Magic", Power = false, IsConect = true, Brightness = 0 }); db.Lamps.Add(new Lamp { Name = "Lamp 220v", Company = "Light And Magic", Power = false, IsConect = false, Brightness = 0 }); db.Lamps.Add(new Lamp { Name = "Lamp 100w", Company = "Panasonic", Power = true, IsConect = true, Brightness = 255 }); db.SaveChanges(); } }
public DoorLockController(DevicesContext context) { this.db = context; if (!db.DoorLocks.Any()) { db.DoorLocks.Add(new DoorLock { Name = "Замок ESP8266", Company = "OOO Electronic", Power = false, IsConect = false, IsOpen = false }); db.DoorLocks.Add(new DoorLock { Name = "Замок Малютка", Company = "www.DoorLocks.com", Power = false, IsConect = false, IsOpen = false }); db.DoorLocks.Add(new DoorLock { Name = "Еврозамок", Company = "www.DoorLocks.com", Power = false, IsConect = true, IsOpen = true }); db.SaveChanges(); } }
public AirConditionerController(DevicesContext context) { this.db = context; if (!db.AirConditioners.Any()) { db.AirConditioners.Add(new AirConditioner { Name = "Кондиционер А-505", Company = "Bosh", Power = false, IsConect = false, Mode = 0, Temperature = 0, TemperatureSensorReadings = 0, IsWater = false }); db.AirConditioners.Add(new AirConditioner { Name = "Ионизатор воздуха напольный R-351", Company = "Polaris", Power = true, IsConect = false, Mode = 5, Temperature = 20, TemperatureSensorReadings = 15, IsWater = true }); db.SaveChanges(); } }
public string ConnectDevice(string name) { Device doorLock = db.DoorLocks.FirstOrDefault(x => x.Name == name); if (doorLock == null) { return("device is not found"); } if (doorLock.IsConect) { return("device is already connected"); } else { doorLock.IsConect = true; db.Update(doorLock); db.SaveChanges(); return("device is connected"); } }
public string ConnectDevice(string name) { Device lamp = db.Lamps.FirstOrDefault(x => x.Name == name); if (lamp == null) { return("device is not found"); } if (lamp.IsConect) { return("device is already connected"); } else { lamp.IsConect = true; db.Update(lamp); db.SaveChanges(); return("device is connected"); } }
public string ConnectDevice(string name) { Device temperatureSensor = db.TemperatureSensors.FirstOrDefault(x => x.Name == name); if (temperatureSensor == null) { return("device is not found"); } if (temperatureSensor.IsConect) { return("device is already connected"); } else { temperatureSensor.IsConect = true; db.Update(temperatureSensor); db.SaveChanges(); return("device is connected"); } }
public string ConnectDevice(string name) { Device heater = db.Heaters.FirstOrDefault(x => x.Name == name); if (heater == null) { return("device is not found"); } if (heater.IsConect) { return("device is already connected"); } else { heater.IsConect = true; db.Update(heater); db.SaveChanges(); return("device is connected"); } }
public string ConnectDevice(string name) { Device powerSocket = db.PowerSockets.FirstOrDefault(x => x.Name == name); if (powerSocket == null) { return("device is not found"); } if (powerSocket.IsConect) { return("device is already connected"); } else { powerSocket.IsConect = true; db.Update(powerSocket); db.SaveChanges(); return("device is connected"); } }
//TODO public string InsertCounter(string serial, string brand, string model, string type) { using (var db = new DevicesContext(_options)) { db.Devices.Add(new Device { d_serial = serial }); db.Counters.Add(new Counter { c_serial = serial, c_brand = brand, c_model = model, c_type = type }); db.SaveChanges(); } return("Counter registered successfully."); }
//TODO public string InsertGateway(string serial, string brand, string ip, string port) { using (var db = new DevicesContext(_options)) { db.Devices.Add(new Device { d_serial = serial }); db.Gateways.Add(new Gateway { g_serial = serial, g_brand = brand, g_ip = ip, g_port = port }); db.SaveChanges(); } return("Gateway registered successfully."); }
public Device Off(Guid id) { Device device = db.Devices.Find(id); if (device.State == true) { device.Off(); } else { device.On(); } db.Entry(device).State = EntityState.Modified; db.SaveChanges(); return(device); }
public PowerSocketController(DevicesContext context) { this.db = context; if (!db.PowerSockets.Any()) { db.PowerSockets.Add(new PowerSocket { Name = "Розетка 1", Company = "Electronic", Power = false, IsConect = false, IsOn = true }); db.PowerSockets.Add(new PowerSocket { Name = "Розетка 2", Company = "Thunderstorm", Power = true, IsConect = false, IsOn = false }); db.SaveChanges(); } }
public TemperatureSensorController(DevicesContext context) { this.db = context; if (!db.TemperatureSensors.Any()) { db.TemperatureSensors.Add(new TemperatureSensor { Name = "SCP-106", Company = "Secure Contain Protect", Power = false, IsConect = false, TemperatureSensorReadings = 0 }); db.TemperatureSensors.Add(new TemperatureSensor { Name = "Температурный датчик Е241", Company = "Polaris", Power = true, IsConect = false, TemperatureSensorReadings = 15, }); db.SaveChanges(); } }
public HeaterController(DevicesContext context) { this.db = context; if (!db.Heaters.Any()) { db.Heaters.Add(new Heater { Name = "Обогреватель Ламповый", Company = "PodogrevPlus", Power = false, IsConect = false, Temperature = 0 }); db.Heaters.Add(new Heater { Name = "Обогреватель 11Mega", Company = "iChill", Power = true, IsConect = false, Temperature = 20 }); db.SaveChanges(); } }
public async Task <ActionResult <NotificationFromDevice> > PostNotificationFromDevice(NotificationFromDevice notificationFromDevice) { char[] spearator = { ',' }; string[] massages = notificationFromDevice.Massage.Split(spearator); Boolean isANewDevice = false; int id = notificationFromDevice.ProductId; Product product = _context.Products.Find(id); if (product == null) { Device device = _context.Devices.Find(Int32.Parse(massages[1])); if (device == null) { device = new Device { Id = Int32.Parse(massages[1]), Name = massages[0], UserRosbery = massages[0] }; isANewDevice = true; } product = new Product { Id = notificationFromDevice.ProductId, Name = massages[2], Device = device, Count = 1 }; if (isANewDevice) { _context.Devices.Add(device); try { _context.Database.OpenConnection(); _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Devices ON"); _context.SaveChanges(); _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Devices OFF"); _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Products ON"); _context.Products.Add(product); _context.SaveChanges(); _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Products OFF"); } finally { _context.Database.CloseConnection(); } } else { try { _context.Database.OpenConnection(); _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Products ON"); _context.Products.Add(product); _context.SaveChanges(); _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Products OFF"); _context.Devices.Add(device); } finally { _context.Database.CloseConnection(); } } device.Products.Add(product); } else { if (massages[3].Equals("in")) { product.Count += 1; } else { if (product.Count > 0) { product.Count -= 1; } else { product.Count = 0; } } } _context.NotificationFromDevices.Add(notificationFromDevice); await _context.SaveChangesAsync(); return(CreatedAtAction("GetNotificationFromDevice", new { id = notificationFromDevice.Id }, notificationFromDevice)); }
public void Add(Checkout newCheckout) { _context.Add(newCheckout); _context.SaveChanges(); }
public void Add(User newUser) { _context.Add(newUser); _context.SaveChanges(); }
private void SaveChange(int id, string type, IDictionary <int, Models.Devices.Device> device) { switch (type) { case "cond": Conditioner cond = dbconnect.Conditioner.Find(id); cond.Programm = ((Models.Devices.Conditioner)device[0]).Programm; cond.State = ((Models.Devices.Conditioner)device[0]).State; dbconnect.SaveChanges(); break; case "tr": TapRecoder tr = dbconnect.TapeReoder.Find(id); tr.State = ((Models.Devices.TapRecoder)device[0]).State; tr.Mode = ((Models.Devices.TapRecoder)device[0]).Mode; tr.Volume = ((Models.Devices.TapRecoder)device[0]).Volume; dbconnect.SaveChanges(); break; case "lamp": Lamp lamp = dbconnect.Lamp.Find(id); lamp.State = ((Models.Devices.Lamp)device[0]).State; lamp.CurrentColor = ((Models.Devices.Lamp)device[0]).currentcolor; lamp.Brightness = ((Models.Devices.Lamp)device[0]).Brightness; dbconnect.SaveChanges(); break; case "fridge": Fridge fridge = dbconnect.Fridge.Find(id); fridge.Programm = ((Models.Devices.Fridge)device[0]).Programm; fridge.State = ((Models.Devices.Fridge)device[0]).State; fridge.StateFrize = ((Models.Devices.Fridge)device[0]).StateFrize; dbconnect.SaveChanges(); break; case "kettle": Kettle kettle = dbconnect.Kettle.Find(id); kettle.State = ((Models.Devices.Kettle)device[0]).State; dbconnect.SaveChanges(); break; case "tv": TeleVision tv = dbconnect.TeleVision.Find(id); tv.State = ((Models.Devices.TeleVision)device[0]).State; tv.Mode = ((Models.Devices.TeleVision)device[0]).Mode; tv.Volume = ((Models.Devices.TeleVision)device[0]).Volume; tv.CurrentChanel = ((Models.Devices.TeleVision)device[0]).Chanel.ToString(); tv.Brightness = ((Models.Devices.TeleVision)device[0]).Brightness; dbconnect.SaveChanges(); break; } }
public void Add(Device newDevice) { _context.Add(newDevice); _context.SaveChanges(); }
public ActionResult Add(string type, string Namedevice) { switch (type) { case "cond": Device d = new Device { Type = "cond", img = "~/Content/Images/MainScreen/cond.jpg" }; Conditioner c = new Conditioner { Name = Namedevice, State = false, Programm = 2, Device = d }; Session["Filtr"] = type; dbconnect.Conditioner.Add(c); dbconnect.SaveChanges(); break; case "tr": Device d1 = new Device { Type = "tr", img = "~/Content/Images/MainScreen/TR.jpg" }; TapRecoder tr = new TapRecoder { Name = Namedevice, State = false, Mode = false, Volume = 20, Device = d1 }; Session["Filtr"] = type; dbconnect.TapeReoder.Add(tr); dbconnect.SaveChanges(); break; case "lamp": Device d2 = new Device { Type = "lamp", img = "~/Content/Images/MainScreen/lamp.jpg" }; Lamp l = new Lamp { Name = Namedevice, State = false, Brightness = 20, CurrentColor = 1, Device = d2 }; Session["Filtr"] = type; dbconnect.Lamp.Add(l); dbconnect.SaveChanges(); break; case "fridge": Device d3 = new Device { Type = "fridge", img = "~/Content/Images/MainScreen/fridge.jpg" }; Fridge f = new Fridge { Name = Namedevice, State = false, StateFrize = false, Programm = 1, Device = d3 }; Session["Filtr"] = type; dbconnect.Fridge.Add(f); dbconnect.SaveChanges(); break; case "kettle": Device d4 = new Device { Type = "kettle", img = "~/Content/Images/MainScreen/kettle.jpg" }; Kettle k = new Kettle { Name = Namedevice, State = false, Device = d4 }; Session["Filtr"] = type; dbconnect.Kettle.Add(k); dbconnect.SaveChanges(); break; case "tv": Device d5 = new Device { Type = "tv", img = "~/Content/Images/MainScreen/tv.jpg" }; TeleVision tv = new TeleVision { Name = Namedevice, State = false, CurrentChanel = "ICTV", Volume = 20, Brightness = 30, Mode = false, Device = d5 }; DVD dvd = new DVD { State = false, IsDiskboxOpen = false, IsPlay = false, TeleVision = tv }; Session["Filtr"] = type; dbconnect.TeleVision.Add(tv); dbconnect.DVD.Add(dvd); dbconnect.SaveChanges(); break; } IDictionary <int, Models.Devices.Device> filtrDevice = new SortedDictionary <int, Models.Devices.Device>(); return(View("Index", filtrDevice)); }
public void Add(Site newSite) { _context.Add(newSite); _context.SaveChanges(); }