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()); }