예제 #1
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation($"{nameof(ToDoGetById)} function processed a request.");

            string id = req.Query["id"];

            if (string.IsNullOrWhiteSpace(id))
            {
                throw new ArgumentNullException(nameof(id));
            }


            var toDoEntity =
                await _toDoEntityDataStore.GetByIdAsync(
                    id);

            if (toDoEntity == null)
            {
                return(new NotFoundResult());
            }

            var toDo =
                new ToDo(
                    toDoEntity);

            return(new OkObjectResult(toDo));
        }
예제 #2
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "put", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation($"{nameof(ToDoUpdateById)} function processed a request.");

            string id = req.Query["id"];

            if (string.IsNullOrWhiteSpace(id))
            {
                throw new ArgumentNullException(nameof(id));
            }

            var toDoUpdateOptions =
                await req.Body.DeserializeAsync <ToDoUpdateOptions>();

            var toDoEntity =
                await _toDoEntityDataStore.GetByIdAsync(
                    id);

            if (toDoEntity == null)
            {
                return(new NotFoundResult());
            }

            toDoEntity.Status      = toDoUpdateOptions.Status;
            toDoEntity.Description = toDoUpdateOptions.Description;

            await _toDoEntityDataStore.UpdateAsync(
                toDoEntity);

            var toDo =
                new ToDo(
                    toDoEntity);

            return(new OkObjectResult(toDo));
        }