Beispiel #1
0
        public async Task <IActionResult> PartiallyUpdate(
            [HttpTrigger(AuthorizationLevel.Anonymous, "patch", Route = "SubItemDetailPatch/{id}")] HttpRequest req, ILogger log, int id)
        {
            if (id < 0)
            {
                return(new BadRequestObjectResult("id cannot be smaller than zero"));
            }

            var record = await repo.GetOneAsync <SubItemDetail, SubItemDetailModel>(id);

            if (record == null)
            {
                return(new NotFoundObjectResult("Not found"));
            }

            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();

            var model = JsonConvert.DeserializeObject <JsonPatchDocument <SubItemDetailModel> >(requestBody);

            model.ApplyTo(record);

            await repo.UpdateAsync <SubItemDetail, SubItemDetailModel>(record);

            return(new NoContentResult());
        }
Beispiel #2
0
        public async Task <IActionResult> PartiallyUpdate(int id, [FromBody] JsonPatchDocument <SubItemDetailModel> model)
        {
            if (id == 0)
            {
                return(BadRequest());
            }

            var record = await repo.GetOneAsync <SubItemDetail, SubItemDetailModel>(id);

            if (record.Value.Id == 0)
            {
                return(NotFound());
            }

            model.ApplyTo(record.Value, ModelState);
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var maybe = await repo.UpdateAsync <SubItemDetail, SubItemDetailModel>(record.Value);

            if (maybe.IsSuccess)
            {
                return(NoContent());
            }
            return(BadRequest(maybe.Error));
        }