コード例 #1
0
        public static async Task <IActionResult> GetUserDevices(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "user/devices/")] HttpRequest req,
            [CosmosDB(databaseName: "devicedata",
                      collectionName: "deviceusers",
                      ConnectionStringSetting = "DeviceUserDBConnectionString")] DocumentClient client,
            ILogger log,
            ClaimsPrincipal claimsPrincipal)
        {
            var aadUserId = Shared.ValidateAuth(claimsPrincipal);

            if (!string.IsNullOrWhiteSpace(aadUserId))
            {
                var options = new FeedOptions
                {
                    EnableCrossPartitionQuery = true
                };

                Uri collectionUri = UriFactory.CreateDocumentCollectionUri(dbName, collectionName);

                var devices = client.CreateDocumentQuery <DeviceUserBinding>(collectionUri, options)
                              .Where(x => x.AADUserId == aadUserId)
                              .ToList();

                var deviceList = new UserDevices();
                deviceList.Devices = devices;
                return(await Task.FromResult(new OkObjectResult(deviceList)));
            }

            return(await Task.FromResult(new UnauthorizedResult()));
        }
コード例 #2
0
ファイル: CosmosHelper.cs プロジェクト: jplck/serverless-iot
        public UserDevices GetDevicesForUser(string userId)
        {
            Uri collectionUri = UriFactory.CreateDocumentCollectionUri(dbName, collectionName);

            var options = new FeedOptions
            {
                EnableCrossPartitionQuery = true,
                MaxItemCount = 1
            };

            var devices = client.CreateDocumentQuery <DeviceUserBinding>(collectionUri, options)
                          .Where(x => x.AADUserId == userId)
                          .ToList();

            var deviceList = new UserDevices();

            deviceList.Devices = devices;

            return(deviceList);
        }