コード例 #1
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "delete", Route = FunctionConstants.DeleteTodoListFunction + "/{id}")]
            HttpRequest req, string id, ClaimsPrincipal claims)
        {
            var user   = _authService.GetClientPrincipalFromRequest(req);
            var listId = user.UserId;

            if (string.IsNullOrEmpty(id))
            {
                return(new BadRequestObjectResult("Id or listId cannot be empty"));
            }

            var result = await _cloudTable.ExecuteAsync(TableOperation.Retrieve <TodoListEntity>(listId, id));

            if (result?.Result is TodoListEntity entity)
            {
                _cloudTable.Execute(TableOperation.Delete(entity));
                _itemService.DeleteAllItemsWithListId(id);
            }
            else
            {
                return(new NotFoundResult());
            }

            return(new NoContentResult());
        }