Пример #1
0
        public HttpResponseMessage Post(CreateTodoListModel model)
        {
            if (ModelState.IsValid)
            {
                // Bind the model to a TodoList object
                var mapper = new CreateTodoListMapper();
                mapper.Configure();

                var todoList = mapper.Map(model);

                // Create the todoList
                var createTodoListHandler = new CreateTodoListHandler();
                createTodoListHandler.Handle(todoList);

                // Map the todoList to the todoList result
                var mapperResult = new TodoListMapper();
                mapperResult.Configure();
                var todoListResult = mapperResult.Map(todoList);

                // Return the todoListResult
                var response = Request.CreateResponse <TodoListResult>(HttpStatusCode.Created, todoListResult);
                return(response);
            }

            return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ModelState));
        }
Пример #2
0
        public TodoListResult Handle(int id)
        {
            // Get connection
            var context = new TodoContext();

            // Get the todoitems
            var todoList = context.TodoLists.Include(tt => tt.TodoItems).Single(tl => tl.Id == id);

            // Create the mapper to convert to JSON
            var mapper = new TodoListMapper();

            mapper.Configure();

            var result = mapper.Map(todoList);

            return(result);
        }