【发布时间】:2020-05-22 13:03:02
【问题描述】:
SaveAll() 方法
public async Task<bool> SaveAll()
{
return await _context.SaveChangesAsync() > 0;
}
我的控制器中的 UpdateSteps 方法
[HttpPut("{goalId}/steps")]
public async Task<IActionResult> UpdateSteps(int userId, long goalId, IEnumerable<Step> steps)
{
if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
return Unauthorized();
var stepsFromRepo = await _repo.GetStepsById(goalId);
_mapper.Map(steps, stepsFromRepo);
if (await _repo.SaveAll())
return NoContent();
throw new Exception("Updating steps failed");
}
如果条件为假并抛出异常
映射工作正常,这就是为什么我不明白为什么更改无法被识别。
非常感谢您的帮助!
【问题讨论】:
标签: c# database http asp.net-web-api controller