public async Task <IActionResult> Update(long id, [FromBody] TodoItemResource item) { if (item == null || item.Id != id) { return(BadRequest()); } var user = await GetUser(); if (user == null) { return(Unauthorized()); } var todo = await repository.GetTodo(id, user); if (todo == null) { return(NotFound()); } mapper.Map <TodoItemResource, TodoItem>(item, todo); await unit.CompleteAsync(); return(new NoContentResult()); }
public async Task <TodoItemResource> Post([FromBody] TodoItemResource todoItem, [FromServices] api.todoApi.ITodoApiClient apiClient) { _logger.LogInformation("In front-end"); var toSave = new TodoItem { Name = todoItem.Name }; var result = await apiClient.TodoItemsAsync(toSave); return(new TodoItemResource { Id = result.Id, IsComplete = result.IsComplete, Name = result.Name }); }
public IActionResult UpdateItem([FromRoute] int id, [FromBody] TodoItemResource item) { var itemToUpdate = this.itemRepo.FindByCondition(item => item.Id == id).FirstOrDefault(); if (itemToUpdate == null) { return(BadRequest(new { Message = "Item não encontrado!" })); } var mappedItem = this.mapper.Map <TodoItemResource, TodoItem>(item); mappedItem.Id = id; this.itemRepo.Update(mappedItem); return(Ok()); }
public async Task <TodoItemResource> Post([FromBody] TodoItemResource todoItem) { _logger.LogInformation("In front-end"); var httpClient = new HttpClient(); var client = new api.todoApi.TodoApiClient("https://localhost:5005", httpClient); var toSave = new TodoItem { Name = todoItem.Name }; var result = await client.TodoItemsAsync(toSave); return(new TodoItemResource { Id = result.Id, IsComplete = result.IsComplete, Name = result.Name }); }
public async Task <IActionResult> Create([FromBody] TodoItemResource item) { if (item == null) { return(BadRequest()); } var user = await GetUser(); if (user == null) { return(Unauthorized()); } var todoItem = mapper.Map <TodoItem>(item); todoItem.User = user; repository.Add(todoItem); await unit.CompleteAsync(); return(CreatedAtRoute("GetTodo", new { id = item.Id }, item)); }