Пример #1
0
        public QuestionModule()
        {
            IQuestionRepository repo = new QuestionRepository(ConfigurationManager.ConnectionStrings["happyIndex"].ConnectionString);

            Get["/api/questions"] = _ =>
            {
                var category = Request.Query.category;

                //filter the results if a category was supplied
                return(string.IsNullOrEmpty(category) ? repo.GetAllQuestions() : repo.GetByCategory(category));
            };

            Post["/api/questions"] = _ =>
            {
                var q = this.Bind <Question>();
                return(repo.Add(q.Text, q.Category));
            };
        }