Пример #1
0
        public static async Task <IActionResult> AddDog([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, TraceWriter log)
        {
            sw.Restart();

            string dogName  = req.Query["Name"];
            string dogBreed = req.Query["Breed"];
            string userId   = req.Query["UserId"];

            string resourceToken = req.Headers["ResourceToken"];

            if (string.IsNullOrEmpty(resourceToken))
            {
                new BadRequestObjectResult("ResourceToken is required");
            }

            // Set the resource token, to demonstrate usage from a 'Client'.
            repo.AuthKeyOrResourceToken(resourceToken);
            // Set the partition key, so the user has access to their documents, based on the permission that was setup
            // by using the userid as a permission key.  A client could just set this once initially.
            repo.PartitionKey(userId);

            Dog dog = await repo.UpsertItemAsync <Dog>(new Dog { Breed = dogBreed, Name = dogName });

            sw.Stop();

            log.Info($"Execution took: {sw.ElapsedMilliseconds}ms.");

            return(dog != null
                ? (ActionResult) new OkObjectResult(dog)
                : new BadRequestObjectResult("Unable to add the dog."));
        }
        public static async Task <HttpResponseMessage> AddDog(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req,
            TraceWriter log)
        {
            var queryValues = req.GetQueryNameValuePairs();

            string dogName  = queryValues.FirstOrDefault(p => p.Key == "Name").Value;
            string dogBreed = queryValues.FirstOrDefault(p => p.Key == "Breed").Value;
            string userId   = queryValues.FirstOrDefault(p => p.Key == "UserId").Value;

            string resourceToken = req.Headers?.GetValues("ResourceToken").FirstOrDefault();

            if (string.IsNullOrEmpty(resourceToken))
            {
                return(req.CreateErrorResponse(HttpStatusCode.Unauthorized, "ResourceToken is a required"));
            }

            // Set the resource token, to demonstrate usage from a 'Client'.
            repo.AuthKeyOrResourceToken(resourceToken);
            // Set the partition key, so the user has access to their documents, based on the permission that was setup
            // by using the userid as a permission key.  A client could just set this once initially.
            repo.PartitionKey(userId);

            Dog dog = await repo.UpsertItemAsync <Dog>(new Dog { Breed = dogBreed, Name = dogName });

            return(dog == null
                ? req.CreateResponse(HttpStatusCode.BadRequest, "Unable to add the dog.")
                : req.CreateResponse(HttpStatusCode.OK, dog));
        }
        public static async Task <IActionResult> TryGetAllGalleryTiles([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, TraceWriter log)
        {
            // sw.Restart();

            // As a client, you would already have your userId when calling typically.
            string userId = req.Query["UserId"];

            string resourceToken = req.Headers["x-zumo-auth"];

            if (string.IsNullOrEmpty(resourceToken))
            {
                new BadRequestObjectResult("ResourceToken is required");
            }

            // Set the resource token, to demonstrate usage from a 'Client'.
            repo2.AuthKeyOrResourceToken(resourceToken);
            // Set the parition key, since our resource token is limited by partition key.  A client could just set this once initially.
            repo2.PartitionKey(userId);

            // BUG: This seems to fail on Azure Functions V2 due to the following:
            // https://github.com/Azure/azure-documentdb-dotnet/issues/202
            // https://github.com/Azure/azure-documentdb-dotnet/issues/312
            var results = await repo2.GetAllItemsAsync <GalleryTile>(new FeedOptions { EnableCrossPartitionQuery = true });

            // sw.Stop();
            // log.Info($"Execution took: {sw.ElapsedMilliseconds}ms.");

            return(results != null
                ? (ActionResult) new OkObjectResult(results)
                : new BadRequestObjectResult("Unable to find document(s) with the given type."));
        }
        public static async Task <IActionResult> AddGalleryTile([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, TraceWriter log)
        {
            // sw.Restart();

            string TitleTMP                = req.Query["Title"];
            string Display_tabsTMP         = req.Query["display_tabs"];
            string TableauIDTMP            = req.Query["TableauID"];
            string UserNameTMP             = req.Query["UserName"];
            string ChartSourceLinkTMP      = req.Query["ChartSourceLink"];
            string ChartThumbLinkTMP       = req.Query["ChartThumbLink"];
            string FavoritedTMP            = req.Query["favorited"];
            string FilterContentTypeTMP    = req.Query["filterContentType"];
            string ChartDescriptionTextTMP = req.Query["chartDescriptionText"];
            string FilterContentGroupTMP   = req.Query["filterContentGroup"];
            string ViewCountTMP            = req.Query["viewCount"];
            string NviewsTMP               = req.Query["nviews"];
            string SelfServiceTMP          = req.Query["SelfService"];
            string ChartPreviewStatusTMP   = req.Query["ChartPreviewStatus"];
            string ChartInfoTMP            = req.Query["chartInfo"];
            string ChartUseTMP             = req.Query["chartUse"];

            string resourceToken = req.Headers["ResourceToken"];

            if (string.IsNullOrEmpty(resourceToken))
            {
                new BadRequestObjectResult("ResourceToken is required");
            }

            // Set the resource token, to demonstrate usage from a 'Client'.
            repo.AuthKeyOrResourceToken(resourceToken);
            // Set the partition key, so the user has access to their documents, based on the permission that was setup
            // by using the userid as a permission key.  A client could just set this once initially.
            repo.PartitionKey(UserNameTMP);

            GalleryTile galleryTile = await repo.UpsertItemAsync <GalleryTile>(new GalleryTile {
                Title                = TitleTMP,
                Display_tabs         = Display_tabsTMP,
                TableauID            = TableauIDTMP,
                UserName             = UserNameTMP,
                ChartSourceLink      = ChartSourceLinkTMP,
                ChartThumbLink       = ChartThumbLinkTMP,
                Favorited            = FavoritedTMP,
                FilterContentType    = FilterContentTypeTMP,
                ChartDescriptionText = ChartDescriptionTextTMP,
                FilterContentGroup   = FilterContentGroupTMP,
                ViewCount            = ViewCountTMP,
                Nviews               = NviewsTMP,
                SelfService          = SelfServiceTMP,
                ChartPreviewStatus   = ChartPreviewStatusTMP,
                ChartInfo            = ChartInfoTMP,
                ChartUse             = ChartUseTMP
            });

            // sw.Stop();

            // log.Info($"Execution took: {sw.ElapsedMilliseconds}ms.");

            return(galleryTile != null
                ? (ActionResult) new OkObjectResult(galleryTile)
                : new BadRequestObjectResult("Unable to add the GalleryTile."));
        }