Esempio n. 1
0
        public async Task <IActionResult> RunPost(
            [HttpTrigger(AuthorizationLevel.Function, "Post", Route = "{item}")] HttpRequest req, ExecutionContext context, string item, ILogger log)
        {
            string  requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data        = JsonConvert.DeserializeObject(requestBody);
            string  id          = data.id;

            if (!string.IsNullOrEmpty(id))
            {
                return(new BadRequestObjectResult($"id must be empty for post, call put if id is known"));
            }

            id = Guid.NewGuid().ToString();

            data.id = id;
            var i = JsonConvert.SerializeObject(data);

            var entity = new StoredJsonEntity(item, id)
            {
                Body = i
            };

            var obj = await _tableStorageRepository
                      .OverrideTableName(item)
                      .InsertOrReplaceAsync(entity);

            return(new OkObjectResult(JsonConvert.DeserializeObject(obj.Body)));
        }
Esempio n. 2
0
        public async Task <IActionResult> RunPut(
            [HttpTrigger(AuthorizationLevel.Function, "Put", Route = "{item}/{id}")] HttpRequest req, ExecutionContext context, string item, string id, ILogger log)
        {
            string  requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data        = JsonConvert.DeserializeObject(requestBody);
            string  bodyId      = data.id;

            if (bodyId != id)
            {
                return(new BadRequestObjectResult($"Id mismatch {bodyId},{id}"));
            }

            var entity = new StoredJsonEntity(item, id)
            {
                Body = requestBody
            };

            var obj = await _tableStorageRepository
                      .OverrideTableName(item)
                      .InsertOrReplaceAsync(entity);

            return(new OkObjectResult(JsonConvert.DeserializeObject(obj.Body)));
        }