public IActionResult UpdateTodo(Guid id, [FromBody] TodoUpdateDto todoUpdateDto) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var todoEntity = _todoRepository.GetTodo(id, false); if (todoEntity == null) { return(NotFound()); } _mapper.Map(todoUpdateDto, todoEntity); _todoRepository.Save(); return(NoContent()); } catch (Exception ex) { _logger.LogCritical($"Exception while updating todo {id}", ex); return(StatusCode(500, "A problem occurred while trying to update this todo")); } }
public new TodoDto Update(TodoUpdateDto item) { var updated = base.Update(item); todoCache.SourceCache.AddOrUpdate(updated); return(updated); }
public ActionResult <TodoDto> Update(Guid id, [FromBody] TodoUpdateDto dto) { if (dto == null) { return(BadRequest()); } var entity = _todoRespository.GetById(id); if (entity == null) { return(NotFound()); } _mapper.Map(dto, entity); var updatedEntity = _todoRespository.Update(entity); if (!_todoRespository.Save()) { throw new Exception("Update item failed on save."); } var updatedDto = _mapper.Map <TodoDto>(updatedEntity); return(Ok(updatedDto)); }
public async Task <ActionResult <TodoDto> > UpdateTodo(Guid id, [FromBody] TodoUpdateDto updateDto) { if (updateDto == null) { return(BadRequest()); } TodoEntity singleById = _todoRepository.GetSingle(id); if (singleById == null) { return(NotFound()); } updateDto.Value = updateDto.Value ?? singleById.Value; _mapper.Map(updateDto, singleById); TodoEntity updatedTodo = _todoRepository.Update(id, singleById); if (!_todoRepository.Save()) { throw new Exception("Updating an item failed on save."); } var updatedDto = _mapper.Map <TodoDto>(updatedTodo); await _todoHubContext.Clients.All.SendAsync("todo-updated", updatedDto); return(Ok(updatedDto)); }
public TodoDto Update(int id, TodoUpdateDto item) { if (id != item.Id) { throw new ArgumentException("Invalid Id", nameof(id)); } return(repository.Update(item)); }
public TodoDto Update(TodoUpdateDto item) { logger?.LogInformation("Update DB id:{0}", item.Id); db.Execute(SqlQueries.UpdateTodo, new { Id = item.Id, Description = item.Description, Completed = item.Completed, Updated = DateTime.Now }); return(Get(item.Id)); }
public async Task <bool> UpdateTodo(TodoUpdateDto todo, string email) { var oldTodo = await _context.Todos .FirstOrDefaultAsync(t => t.Id == todo.Id && t.Author.NormalizedEmail == email.ToLower()); if (oldTodo != null) { oldTodo.Header = todo.Header; oldTodo.Priority = todo.Priority; return(true); } return(false); }
public ActionResult UpdateTodo(int id, TodoUpdateDto todoUpdateDto) { var existingTodo = _repository.GetTodoById(id); if (existingTodo == null) { return(NotFound()); } _mapper.Map(todoUpdateDto, existingTodo); _repository.UpdateTodo(todoUpdateDto); _repository.SaveChanges(); return(NoContent()); }
public ActionResult UpdateTodoItem(int id, TodoUpdateDto todoUpdateDto) { var todoItemModelFromRepo = _repository.GetTodoItem(id); if (todoItemModelFromRepo == null) { return(NotFound()); } _mapper.Map(todoUpdateDto, todoItemModelFromRepo); _repository.UpdateTodoItem(todoItemModelFromRepo); var result = _repository.SaveChanges(); return(NoContent()); }
public ActionResult <TodoReadDto> UpdateTodo(int id, TodoUpdateDto todoUpdateDto) { var todoModelFromRepo = _repository.GetTodoById(id); if (todoModelFromRepo == null) { return(NotFound()); } var todoReadDto = _mapper.Map(todoUpdateDto, todoModelFromRepo); _repository.UpdateTodo(todoModelFromRepo); _repository.SaveChanges(); return(Ok(todoReadDto)); }
public TodoDto Update(TodoUpdateDto item) { logger?.LogInformation("Update DB id:{0}", item.Id); var prevItem = Remove(item.Id); if (prevItem != null) { var clone = prevItem with { Description = item.Description, Completed = item.Completed, Updated = DateTimeOffset.Now }; items.Add(clone); return(clone); } return(null); } }
public async Task <IActionResult> Update(TodoUpdateDto todo) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } string email = Helper.GetEmail(HttpContext); var isSuccesful = await _repo.UpdateTodo(todo, email); if (isSuccesful) { return(Ok("Todo updated succesfully")); } return(StatusCode(500)); }
public ActionResult UpdateTodo(int id, TodoUpdateDto t) { var existingTodo = _repo.GetTodoById(id); if (existingTodo == null) { return(NotFound()); } _map.Map(t, existingTodo); _repo.UpdateTodo(existingTodo); _repo.SaveChanges(); return(Ok()); }
public async Task <IActionResult> Update([FromServices] ITodoRepository repository, [FromRoute] int id, [FromBody] TodoUpdateDto todo) { try { var result = await repository.Update(id, todo); if (result == null) { return(BadRequest($"The id {id} was not found.")); } return(Ok(result)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task <Todo> Update(int id, TodoUpdateDto data) { var result = await _dbContext.Todos.FindAsync(id); if (result == null) { return(null); } if (!string.IsNullOrWhiteSpace(data.Name)) { result.Name = data.Name; } result.Completed = data.Completed; _dbContext.Todos.Update(result); await _dbContext.SaveChangesAsync(); return(result); }
public async Task <IActionResult> ToggleIsComplete([FromRoute] int id, [FromBody] TodoUpdateDto request) { var user = await GetUser(); var todo = await _todoService.GetById(id); if (todo == null) { return(BadRequest("Invalid id")); } if (user.Id != todo.User.Id) { return(Forbid()); } todo.UpdateField("IsComplete", request.Value); var result = await _todoService.Update(todo); return(Ok()); }
public async Task <Todo> Update(int id, TodoUpdateDto data) { await using var connection = new NpgsqlConnection(Environment.GetEnvironmentVariable("DATABASE")); await connection.OpenAsync(); int resultingId; if (!string.IsNullOrWhiteSpace(data.Name)) { resultingId = await connection.QueryFirstAsync <int>("UPDATE todos SET name = @name WHERE id = @ID RETURNING id", new { name = data.Name, ID = id }); } resultingId = await connection.QueryFirstAsync <int>("UPDATE todos SET completed = @completed WHERE id = @ID RETURNING id", new { completed = data.Completed, ID = id }); var result = await connection.QueryFirstAsync <Todo>("SELECT * FROM todos WHERE id = @ID", new { ID = resultingId }); await connection.CloseAsync(); return(result); }
public void UpdateTodo(TodoUpdateDto todo) { // nothing }
public void UpdateTodo(TodoUpdateDto todo) { throw new NotImplementedException(); }