public async Task <IActionResult> Get([FromQuery] Guid?siteId = null, [FromQuery] Guid?userId = null, [FromQuery] int skip = 0, [FromQuery] int take = 0)
        {
            IEnumerable <Lock> locks = null;
            var user    = Request.GetCurrentUser();
            var isAdmin = user.IsAdministrator();

            try
            {
                if (siteId.HasValue && siteId.Value != Guid.Empty)
                {
                    locks = await _lockService.GetLocksOfUserBySiteAsync(user.Id, siteId.Value, isAdmin);
                }
                else
                {
                    locks = await _lockService.GetLocksOfUserAsync(user.Id, isAdmin);
                }
            }
            catch (Exception e)
            {
                _logger.LogError($"An error occured while getting locks of user with exception: {e}");
                return(e.Handle());
            }

            if (locks != null && locks.Any())
            {
                var locksDtos = locks.Select(l =>
                {
                    var dto   = l.ToDto();
                    dto.State = _deviceBusService.GetLockState(dto.Id);
                    return(dto);
                });
                return(Ok(locks));
            }
            return(NoContent());
        }
        public LockState ActivateLock(Guid userId, Guid lockId)
        {
            if (!HasLockPermission(userId, lockId).Result)
            {
                throw new InsufficientPermissionException(userId, lockId, PermissionLevel.LockUser);
            }
            _deviceBusService.SetLockState(lockId, LockState.Unlocked); //Set
            var state = _deviceBusService.GetLockState(lockId);         //Confirm
            var evt   = new AuditEvent
            {
                ObjectId = lockId,
                UserId   = userId
            };

            if (state == LockState.Unlocked)
            {
                evt.EventKey = AuditEventKeys.SuccessLockActivated;
            }
            else
            {
                evt.EventKey = AuditEventKeys.FailureLockActivated;
            }

            _auditLoggerService.LogEvent(evt);
            return(state);
        }