Ejemplo n.º 1
0
        public TodoModule(ITodoRepository repository)
        {
            _todoRepository = repository;

            Get["/todo"] = _ =>
            {
                var response = Response.AsJson(_todoRepository.GetAll().ToList());
                return(CrossOrigin(response));
            };

            Post["/todo"] = _ =>
            {
                var x = this.Bind <Todo>();
                _todoRepository.AddOrUpdateTodo(x);
                var response = Response.AsJson(_todoRepository.GetAll().ToList().Take(10));
                return(CrossOrigin(response));
            };

            Delete["/todo/{id}"] = parameters =>
            {
                _todoRepository.DeleteTodo(parameters.id);
                var response = Response.AsJson(_todoRepository.GetAll().ToList().Take(10));
                return(CrossOrigin(response));
            };

            Get["/todo/{id}"] = parameters =>
            {
                Todo todo     = _todoRepository.GetById(parameters.id);
                var  response = Response.AsJson(todo);
                return(CrossOrigin(response));
            };
        }