public async Task <IActionResult> DeleteConfirmed(string id) { Logger.Trace($"[{nameof(DeleteConfirmed)}] 用户[{SignUser.SignName}]()删除出用户({id})"); try { // 1. 权限验证 if (!await RoleOrgPerManager.HasPermission <User>(SignUser.Id, Constants.USER_DELETE, id)) { Logger.Warn($"[{nameof(Edit)}] 用户[{SignUser.SignName}]({SignUser.Id})没有权限({Constants.USER_DELETE})"); ViewData["ErrMsg"] = "没有权限"; return(RedirectToAction(nameof(Index))); } // 2. 业务处理 await UserManager.DeleteByUserId(SignUser.Id, id); // 删除成功 -跳转到用户列表 return(RedirectToAction(nameof(Index))); } catch (Exception e) { Logger.Error($"[{nameof(DeleteConfirmed)}] 用户删除失败:\r\n" + e); // 跳转回删除界面 -需要在界面说明发生了错误 --不清楚routeValues式怎么匹配的需要了解一下 return(RedirectToAction(nameof(Delete), new { id, errMsg = e.Message })); } }
/// <summary> /// 列表 -跳转到列表界面 /// </summary> /// <returns></returns> // GET: UserBaseJsons public async Task <IActionResult> Index(int pageIndex = 0, int pageSize = 10) { Logger.Trace($"[{nameof(Index)}] 用户[{SignUser.SignName}]({SignUser.Id})查询可见用户列表, 请求参数: pageIndex: {pageIndex}, pageSize: {pageSize}"); ViewData[Constants.SIGNUSER] = SignUser; try { // 1. 权限验证 -在自己组织有没权限 if (!await RoleOrgPerManager.HasPermission(SignUser.Id, Constants.USER_QUERY)) { Logger.Warn($"[{nameof(Index)}] 用户[{SignUser.SignName}]({SignUser.Id})没有权限({Constants.USER_QUERY})"); ModelState.AddModelError("All", "没有权限"); return(RedirectToAction(nameof(HomeController.Index), HomeController.Name)); } // 2. 业务处理 var users = await UserManager.FindByUserId(SignUser.Id); // 分页查询用户列表 var data = users.AsQueryable().Page(pageIndex, pageSize).ToList(); Logger.Trace($"[{nameof(Index)}] 响应数据:\r\n{JsonUtil.ToJson(data)}"); return(View(data)); } catch (Exception e) { Logger.Error($"[{nameof(Index)}] 服务器错误:\r\n{e.ToString()}"); return(RedirectToAction(nameof(HomeController.Index), HomeController.Name)); } }
/// <summary> /// [MVC] 跳转到用户新建界面 /// 在组织(orgId)下创建用户 /// </summary> /// <param name="orgId">组织ID</param> /// <returns></returns> // GET: UserBaseJsons/Create public async Task <IActionResult> Create(string orgId) { Logger.Trace($"[{nameof(Create)}] 用户[{SignUser.SignName}]({SignUser.Id})跳转到用户新建界面, 请求参数:{nameof(orgId)}({orgId})"); try { // 1. 权限验证 if (orgId == null) { if (!await RoleOrgPerManager.HasPermissionInSelfOrg(SignUser.Id, Constants.USER_CREATE)) { return(RedirectToAction(nameof(Index))); } } else { if (!await RoleOrgPerManager.HasPermission(SignUser.Id, Constants.USER_CREATE, orgId)) { return(RedirectToAction(nameof(Index))); } } // 查询有权限添加用户的组织 var organizations = await RoleOrgPerManager.FindOrgByUserIdPerName(SignUser.Id, Constants.USER_CREATE); ViewData["OrgId"] = new SelectList(organizations, nameof(Organization.Id), nameof(Organization.Name), orgId); return(View()); } catch (Exception e) { Logger.Error($"[{nameof(Details)}] 用户[{SignUser.SignName}]({SignUser.Id})跳转界面(在组织({orgId})下创建用户)失败, 服务器错误:\r\n{e}"); ViewData["ErrMsg"] = e.Message; return(RedirectToAction(nameof(Index))); } }