public async Task <IHttpActionResult> Put(int id, [FromBody] TodoViewModel viewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } viewModel.UpdateUser = User.Identity.Name; viewModel.UpdateTime = Now; viewModel.LastAction = "更新"; var model = Mapper.Map <TodoViewModel, Todo>(viewModel); _todoRepository.AttachAsModified(model); await UnitOfWork.SaveChangesAsync(); return(Ok(viewModel)); }