Ejemplo n.º 1
0
        // POST api/Register
        public async Task <iotDevice> Post(string name, string type, string owner = "unk")
        {
            iotDevice device = _db.Devices.Where(d => d.Name == name).FirstOrDefault();

            if (device == null)
            {
                Device myDevice;
                try
                {
                    Device newDevice = new Device(name);
                    myDevice = await _registery.AddDeviceAsync(newDevice);
                }
                catch (DeviceAlreadyExistsException)
                {
                    myDevice = await _registery.GetDeviceAsync(name);
                }

                device = _db.Devices.Add(new iotDevice()
                {
                    Name = name,
                    //IoTHubURL = myHubURL,
                    Key        = myDevice.Authentication.SymmetricKey.PrimaryKey.ToString(),
                    Type       = type,
                    Owner      = owner,
                    RegisterDt = DateTime.UtcNow
                });

                _db.SaveChanges();
            }


            return(device);
        }
Ejemplo n.º 2
0
        public ActionResult DeleteConfirmed(string id)
        {
            iotDevice devices = db.Devices.Find(id);

            db.Devices.Remove(devices);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
 public ActionResult Edit([Bind(Include = "Id,Name,Key,Type,Owner,RegisterDt")] iotDevice devices)
 {
     if (ModelState.IsValid)
     {
         db.Entry(devices).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(devices));
 }
Ejemplo n.º 4
0
        public ActionResult Create([Bind(Include = "Id,Name,Key,Type,Owner,RegisterDt")] iotDevice devices)
        {
            if (ModelState.IsValid)
            {
                db.Devices.Add(devices);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(devices));
        }
Ejemplo n.º 5
0
        // GET: Devices/Delete/5
        public ActionResult Delete(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            iotDevice devices = db.Devices.Find(id);

            if (devices == null)
            {
                return(HttpNotFound());
            }
            return(View(devices));
        }