public async Task <ActionResult> RolesEdit(int roldID) { Entity.Roles role = await _userService.GetRolesInfo(roldID); RolesViewModel model = role.ExtensionToViewModel(); return(View(model)); }
public async Task <ActionResult> RolesEdit(RolesViewModel viewModel) { if (!ModelState.IsValid) { return(View()); } Entity.Roles role = viewModel.ExtensionToModel(); //判断是否重名 string sql = "select COUNT(*) from roles where RoleName <>(select rolename from Roles where RoleID = @RoleID) and rolename = @rolename"; int result = await DbHelper.QuerySingleAsync <int>(sql, new { RoleID = role.RoleID, RoleName = role.RoleName }); if (result > 0) { ViewBag.ErrorMessage = "角色名已存在"; return(View(viewModel)); } //更新 bool flag = await _userService.UpdateRoles(role); ViewBag.ErrorMessage = flag ? "更新成功" : "更新失败"; return(View(viewModel)); }