Example #1
0
        public async Task <IActionResult> GetTodo([FromRoute] int id)
        {
            int _userId = Int32.Parse(HttpContext.GetUserId());

            var todo = await _todosService.GetTodoByIdAsync(id, _userId);

            if (todo == null)
            {
                return(NotFound(new
                {
                    Error = new[] { "Todo not found." }
                }));
            }
            return(Ok(todo));
        }
Example #2
0
        public TodosQuery(ITodosService todos)
        {
            Name = "Query";
            Field <ListGraphType <TodoType> >(
                "todos",
                arguments: new QueryArguments(
                    new QueryArgument <StringGraphType> {
                Name = "todoId"
            },
                    new QueryArgument <IntGraphType> {
                Name = "offset"
            },
                    new QueryArgument <IntGraphType> {
                Name = "limit"
            }),
                resolve: context =>
            {
                var todoId = context.GetArgument <string>("todoId");
                var offset = context.GetArgument <int>("offset");
                var limit  = context.GetArgument <int>("limit");

                if (todoId == null)
                {
                    return(todos.GetTodosAsync(offset, limit));
                }

                //TODO: clean this up
                return(Task.FromResult(new List <Todo> {
                    todos.GetTodoByIdAsync(todoId).Result
                }.AsEnumerable()));
            });
        }