// 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); }
public ActionResult DeleteConfirmed(string id) { iotDevice devices = db.Devices.Find(id); db.Devices.Remove(devices); db.SaveChanges(); return(RedirectToAction("Index")); }
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)); }
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)); }
// 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)); }