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 async Task <CreateTodoListResponseModel> CreateAsync(CreateTodoListModel createTodoListModel) { var todoList = _mapper.Map <TodoList>(createTodoListModel); var addedTodoList = await _todoListRepository.AddAsync(todoList); return(new CreateTodoListResponseModel { Id = addedTodoList.Id }); }
public void Validator_Should_Have_Error_When_Title_Is_Empty() { // Arrange var createTodoListModel = new CreateTodoListModel { Title = string.Empty }; // Act var result = _sut.TestValidate(createTodoListModel); // Assert result.ShouldHaveValidationErrorFor(ctl => ctl.Title); }
public async Task <IActionResult> CreateAsync(CreateTodoListModel createTodoListModel) { return(Ok(ApiResult <CreateTodoListResponseModel> .Success( await _todoListService.CreateAsync(createTodoListModel)))); }
public TodoList Map(CreateTodoListModel model) { return(Mapper.Map <CreateTodoListModel, TodoList>(model)); }