示例#1
0
        public bool ModifyLockState(int lockId, int userId, LockState state)
        {
            using (var smartLock = new SmartLockEntities())
            {
                LockInfo lockInfo = smartLock.LockInfoes.FirstOrDefault(l => l.LockId == lockId);
                if (lockInfo == null)
                {
                    // lock not found.
                    throw new LockNotFoundException("Lock not found.");
                }

                LockAccess lockAccess =
                    smartLock.LockAccesses.FirstOrDefault(l => l.UserId == userId && l.LockId == lockId);

                // TODO: Expand check to limit access based on time
                if (lockAccess == null)
                {
                    // user does not have access to the lock. Throw exception.
                    throw new UnauthorizedUserException("User unauthorized.");
                }

                // modify lock state.
                lockInfo.State = String.Concat(state.ToString(), "ed");

                int changes = smartLock.SaveChanges();
                return(changes == 1 ? true : false);
            }
        }
示例#2
0
        public bool ModifyLockState(int lockId, int userId, LockState state)
        {
            LockInfo lockInfo;

            if (!this.LockData.TryGetValue(lockId, out lockInfo))
            {
                throw new LockNotFoundException("Not found.");
            }

            LockAccess lockAccess =
                this.LockAccessData.SingleOrDefault(l => l.UserId == userId && l.LockId == lockId);

            if (lockAccess == null)
            {
                throw new UnauthorizedUserException("Unauthorized");
            }

            lockInfo.State = String.Concat(state.ToString(), "ed");

            return(true);
        }