Skip to content

Commit

Permalink
禁止EF强制删除。
Browse files Browse the repository at this point in the history
  • Loading branch information
ltm0203 committed Oct 25, 2019
1 parent 802e725 commit f743774
Show file tree
Hide file tree
Showing 6 changed files with 493 additions and 10 deletions.
31 changes: 31 additions & 0 deletions StudentManagement/StudentManagement/Controllers/AdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,37 @@ public async Task<IActionResult> EditUsersInRole(List<UserRoleViewModel> model,
return RedirectToAction("EditRole", new { id = roleId });
}




[HttpPost]
public async Task<IActionResult> DeleteRole(string id)
{
var role = await roleManager.FindByIdAsync(id);

if (role == null)
{
ViewBag.ErrorMessage = $"角色id为{id}的信息不存在,请重试。";
return View("NotFound");
}
else
{
var result = await roleManager.DeleteAsync(role);

if (result.Succeeded)
{
return RedirectToAction("ListRoles");
}

foreach (var error in result.Errors)
{
ModelState.AddModelError("", error.Description);
}
}

return View("ListRoles");
}

#endregion 角色管理

#region 用户管理
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f743774

Please sign in to comment.