Exemple #1
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()));
            });
        }
Exemple #2
0
        GetTodos([FromQuery] int?userId, [FromQuery] bool?isCompleted)
        {
            try {
                IList <Todo> todos = await todosService.GetTodosAsync();

                return(Ok(todos));
            } catch (Exception e) {
                Console.WriteLine(e);
                return(StatusCode(500, e.Message));
            }
        }
Exemple #3
0
        public async Task <IActionResult> GetTodos()
        {
            int _userId = Int32.Parse(HttpContext.GetUserId());

            var todos = await _todosService.GetTodosAsync(_userId);

            if (todos == null)
            {
                return(NotFound(new
                {
                    Error = new[] { "Todos not found." }
                }));
            }
            return(Ok(todos));
        }