示例#1
0
        /// <summary>
        /// [MVC] 角色管理-角色编辑界面
        /// </summary>
        /// <param name="id">角色ID</param>
        /// <returns></returns>
        // GET: Roles/Edit/5
        public async Task <IActionResult> Edit(string id)
        {
            Logger.Trace($"[{nameof(Edit)}] 请求参数; 角色({id})");
            // 0. 参数检查
            if (id == null)
            {
                return(NotFound());
            }
            // 2. 业务处理
            try
            {
                // 1. 权限检查 ROOT_ROLE_SAVE_UPDATE_VIEW
                if (!await RoleOrgPerManager.HasPermission <Role>(SignUser.Id, Constants.ROLE_MANAGE, id))
                {
                    Logger.Warn($"[{nameof(Edit)}] 用户[{SignUser.SignName}]({SignUser.Id})没有权限({Constants.ROLE_MANAGE})");
                    ModelState.AddModelError("All", "没有权限");
                    return(RedirectToAction(nameof(Index)));
                }
                var role = await RoleManager.FindById(id);

                Logger.Trace($"[{nameof(Details)}] 响应数据:\r\n{JsonUtil.ToJson(role)}");
                if (role == null)
                {
                    return(NotFound());
                }
                return(View(role));
            }
            catch (Exception e)
            {
                Logger.Error($"[{nameof(Edit)}] 服务器错误: \r\n{e.ToString()}");
                ModelState.AddModelError("All", e.Message);
                return(RedirectToAction(nameof(Index)));
            }
        }
        public async Task <IActionResult> Details(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            try{
                // 1. 权限检查
                if (!await RoleOrgPerManager.HasPermission(SignUser.Id, Constants.ORG_QUERY, id))
                {
                    Logger.Warn($"[{nameof(Details)}] 权限不足 用户[{SignUser.SignName}]({SignUser.Id})没有权限({Constants.ORG_QUERY})操作组织({id})");
                    ModelState.AddModelError("All", "权限不足");
                    return(RedirectToAction(nameof(Index)));
                }
                // 2. 业务处理
                var organization = await OrganizationManager.FindById(id).SingleOrDefaultAsync();

                Logger.Trace($"[{nameof(Details)}] 响应数据:\r\n{JsonUtil.ToJson(organization)}");
                if (organization == null)
                {
                    return(NotFound());
                }
                return(View(organization));
            }
            catch (Exception e)
            {
                Logger.Error($"[{nameof(Details)}] 服务器错误:\r\n{e}");
                return(RedirectToAction(nameof(Index)));
            }
        }