public ActionResult PartialCommandUpdate(int id, JsonPatchDocument <TodoItemUpdateDto> pathDoc) { /* * [ * { * "op": "replace", //replace is the operation, there are other types * "path": "/howto", //path is the attribute thats gonna be updated * "value" :"new field value" // value is the new attribute's content * } * ] * */ //get the object by the id passed in the url var todoItemModelFromRepo = _repository.GetTodoItemById(id); if (todoItemModelFromRepo == null) { return(NotFound()); } //maps the object from the database into a TodoItemUpdateDto model var todoItemToPatch = _mapper.Map <TodoItemUpdateDto>(todoItemModelFromRepo); //attempts to merge the patch with the original object pathDoc.ApplyTo(todoItemToPatch, ModelState); //return validation error if fails to merge if (!TryValidateModel(todoItemToPatch)) { return(ValidationProblem(ModelState)); } //apply the change to the filtered object _mapper.Map(todoItemToPatch, todoItemModelFromRepo); //calls update(but it does do anything since there is no implementation of the method update) _repository.UpdateTodoItem(todoItemModelFromRepo); //commits the object merged with the changes [todoItemModelFromRepo] _repository.SaveChanges(); return(NoContent()); }
public async Task <TodoItem> UpdateTodoItem(TodoItem item) { return(await _repo.UpdateTodoItem(item)); }