public GetTodoDto UpdateTodo(UpdateTodoDto input) { var todo = (from a in _context.TodoItem where a.Id == input.Id select a).FirstOrDefault(); var data = _mapper.Map <TodoItem>(todo); data.Name = input.Name; data.isComplete = Convert.ToInt32(input.isComplete); data.Date = Convert.ToString(input.Date.Date); _context.TodoItem.Update(data); _context.SaveChanges(); var getDataId = data.Id; var getData = (from a in _context.TodoItem where a.Id == getDataId select new GetTodoDto { Id = a.Id, Date = a.Date, Name = a.Name, isComplete = a.isComplete }).FirstOrDefault(); return(getData); }
public async Task <TodoDto> UpdateAsync(long id, UpdateTodoDto model) { TodoEntity entity = await _repository.GetByIdAsync(id); _mapper.Map(model, entity); TodoEntity user = await _repository.UpdateAsync(entity); return(_mapper.Map <TodoDto>(user)); }
/// <summary> /// 编辑代办事项 /// </summary> /// <param name="todo"></param> /// <returns></returns> public bool EditTodoList(UpdateTodoDto todo) { var entity = todoListDbContext.Todos.Where(o => o.Id == todo.Id).FirstOrDefault(); if (entity == null) { throw new Exception(); } entity.Content = todo.Content; entity.Priority = todo.Priority; entity.StartDate = todo.StartDate; entity.FinishDate = todo.FinishDate; return(todoListDbContext.SaveChanges() > 0); }
public async Task <ActionResult> UpdateTodo([FromBody] UpdateTodoDto viewRequest) { if (!TryValidateModel(viewRequest)) { return(BadRequest(ValidationHelper.GetModelErrors(ModelState))); } var request = this._mapper.Map <UpdateTodoRequest>(viewRequest); request.UserName = HttpContext.User.Identity.Name; var command = new UpdateTodoCommand { Data = request }; return(await Go(command)); }
public Todo UpdateTodo(UpdateTodoDto updateTodoDto) { var todos = _todoContext.Todos.Where(x => x.Id == updateTodoDto.Id); if (todos.Any()) { var todo = todos.First(); todo.Name = updateTodoDto.Name; if (updateTodoDto.IsCompleted.HasValue) { todo.IsCompleted = updateTodoDto.IsCompleted.Value; } _todoContext.Update(todo); return(todo); } return(null); }
public async Task <ActionResult <TodoDto> > UpdateAsync(long id, [FromBody] UpdateTodoDto model) { try { TodoDto result = await _service.UpdateAsync(id, model); _logger.LogInformation("'Todo' getted."); return(Ok(result)); } catch (ArgumentNullException ex) { _logger.LogWarning(ex, "'Todo' not found."); return(NotFound("Not found.")); } catch (Exception ex) { _logger.LogError(ex, "Error when try get selected 'Todo'."); throw; } }
public ActionResult <ReadTodoDto> UpdateTodoItem(int id, UpdateTodoDto updateTodoDto) { if (id != updateTodoDto.Id) { return(BadRequest()); } var todo = _todoRepository.UpdateTodo(updateTodoDto); if (todo == null) { return(NotFound()); } if (_todoRepository.SaveChanges()) { return(NoContent()); //return Ok(MapTodoToReadTodoDto(todo)); } return(BadRequest()); }
public bool EditTodoList([FromServices] ITodoListService todoListService, [FromBody] UpdateTodoDto todo) { return(todoListService.EditTodoList(todo)); }
public Task PutTodo(Guid id, Guid todoId, [FromBody] UpdateTodoDto payload) { return(CommandBus.SendAsync(new UpdateTodoCommand(id, todoId, payload.IsComplete, payload.Text))); }
public UpdateTodoAction(int id, UpdateTodoDto todo) => (Id, Todo) = (id, todo);