Beispiel #1
0
        public ActionResult Pair(PairingRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user    = UserManager.FindById(User.Identity.GetUserId());
            var authKey = Guid.NewGuid().ToString();
            var chair   = new SmartChairModels()
            {
                AuthKey = authKey,
                Name    = "TODO GIVE THE CHAIR A NAME"
            };

            // update the current pending status with the new AuthKey
            var pairingdb      = new PairingOperationsContext();
            var pairingRequest = pairingdb.PairingOperations.SingleOrDefault(e => e.ID == model.PairingCode);

            pairingdb.Entry(pairingRequest).State = System.Data.Entity.EntityState.Modified;
            pairingRequest.AuthKey = authKey;
            pairingdb.SaveChanges();

            user.PairedChairs.Add(chair);

            UserManager.Update(user);

            return(RedirectToAction("Index", "Home"));
        }
Beispiel #2
0
        public IHttpActionResult GetFinishPairing(string id, string uuid)
        {
            PairingOperation pairingOperation = db.PairingOperations.Find(id);

            if (pairingOperation == null)
            {
                return(NotFound());
            }

            if (pairingOperation.DeviceUUID == uuid)
            {
                // only allow the pairing session to be closed by the original device
                db.Entry(pairingOperation).State = EntityState.Deleted;
                db.SaveChanges();

                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }