public HttpResponseMessage Post(CreateTodoItemModel model) { if (ModelState.IsValid) { // Map the model var mapper = new CreateTodoItemMapper(); mapper.Configure(); var todoItem = mapper.Map(model); // Create the item var createTodoItemHandler = new CreateTodoItemHandler(); createTodoItemHandler.Handle(todoItem); // Map the item to the json var mapperResult = new TodoItemMapper(); mapperResult.Configure(); var todoItemResult = mapperResult.Map(todoItem); // Return the response var response = Request.CreateResponse <TodoItemResult>(HttpStatusCode.Created, todoItemResult); return(response); } return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ModelState)); }
public HttpResponseMessage Get(int id) { // Get the item var getTodoItemHandler = new GetTodoItemHandler(); var result = getTodoItemHandler.Handle(id); // Map the item var mapper = new TodoItemMapper(); mapper.Configure(); var todoItemResult = mapper.Map(result); // Create + return response var response = Request.CreateResponse <TodoItemResult>(HttpStatusCode.OK, todoItemResult); return(response); }