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)); }
public IEnumerable <TodoListResult> Handle() { // Get connection var context = new TodoContext(); // Get the todoitems var todoLists = context.TodoLists.Include(tt => tt.TodoItems); // Create the mapper to convert to JSON var mapper = new TodoListMapper(); mapper.Configure(); var result = todoLists.Select(mapper.Map); return(result); }
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); }