public ActionResult DeleteConfirmed(string id)
        {
            Device device = _db.Devices.Find(id);

            _db.Devices.Remove(device);
            _deviceManager.RemoveDeviceAsync(device.DeviceName);
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        // GET: Devices/Edit/5
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Device device = _db.Devices.Find(id);

            if (device == null)
            {
                return(HttpNotFound());
            }
            return(View(new DeviceViewModel(device)));
        }
 public ActionResult Edit(DeviceViewModel vm)
 {
     if (ModelState.IsValid)
     {
         Device device = _db.Devices.Find(vm.DeviceName);
         if (device == null)
         {
             return(HttpNotFound());
         }
         vm.UpdateModel(device);
         _db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(vm));
 }
        public ActionResult Create(DeviceViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var newDevice = new Device();
                newDevice.DeviceName = vm.DeviceName;
                vm.UpdateModel(newDevice);
                _db.Devices.Add(newDevice);

                _deviceManager.AddDeviceAsync(newDevice.DeviceName);

                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(vm));
        }