public async Task <ActionResult> AddItem([FromBody] TodoInputModel input) { try { _userService.AddTodo(input.Description, false, input.Name, input.UserId, DateTime.Now, input.TargetDate); return(Ok()); } catch (Exception ex) { return(ValidationProblem()); } }
public IActionResult Create([FromBody] TodoInputModel item) { if (item == null) { return(BadRequest()); } // replace with command pattern or builder pattern or mediatR var newItem = Todo.Create( item.Description); _todoService.Store(newItem); return(Ok()); }
public async Task TestUpdateTodo_ShouldReturnNotFound( int id, string description ) { TodoInputModel inputModel = new TodoInputModel { Description = description }; var json = JsonConvert.SerializeObject(inputModel); var stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json"); var response = await _client.PutAsync($"/api/todos/{id}", stringContent); var stringResponse = await response.Content.ReadAsStringAsync(); // Assert response.StatusCode.Should().Be(HttpStatusCode.NotFound); }
public async Task TestPostTodo_ShouldReturnNoContentResult( int id, string description) { // Arrange TodoInputModel inputModel = new TodoInputModel { Description = description }; var json = JsonConvert.SerializeObject(inputModel); var stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json"); // Act var response = await _client.PostAsync($"/api/todos/", stringContent); response.EnsureSuccessStatusCode(); // Assert response.StatusCode.Should().Be(HttpStatusCode.OK); await TestGetTodo_ById_ShouldReturnTodo(id, description, false, false); }
public async Task <IActionResult> Update(int id, [FromBody] TodoInputModel item) { // Guards if (item == null) { return(BadRequest()); } var existingItem = await _todoService.GetByIdAsync(id); if (existingItem == null) { return(NotFound()); } var mappedItem = _mapper.Map <Todo>(item); mappedItem.Id = id; // Update logic _todoService.Update(mappedItem); // Return update ok result return(NoContent()); }