Beispiel #1
0
        public async Task <ApiResult <string> > Put(string Id, EditSysRoleDto Params)
        {
            ApiResult <string> res   = new ApiResult <string>();
            TokenModelBeta     token = JwtToken.ParsingJwtToken(HttpContext);

            try
            {
                SysRole sysRoleInfo = _mapper.Map <SysRole>(Params);
                sysRoleInfo.Id = Id;
                var IsSuccess = await _sysRoleService.UpdateAsync(sysRoleInfo);

                if (!IsSuccess)
                {
                    res.code    = (int)ApiEnum.Failure;
                    res.message = "错误:修改角色失败";
                }
                else
                {
                    //添加权限
                    //Params.treeModels
                    res = await _sysRoleAuthorizeService.AddSysModuleActionsAsync(Id, token.Id, Params.treeModels);
                }
            }
            catch (Exception ex)
            {
                res.code    = (int)ApiEnum.Error;
                res.message = "异常:" + ex.Message;
            }

            return(await Task.Run(() => res));
        }
Beispiel #2
0
        public async Task <ApiResult <string> > Post(EditSysRoleDto Params)
        {
            ApiResult <string> res   = new ApiResult <string>();
            TokenModelBeta     token = JwtToken.ParsingJwtToken(HttpContext);

            try
            {
                string roleId = Guid.NewGuid().ToString();

                SysRole sysRoleInfo = _mapper.Map <SysRole>(Params);
                sysRoleInfo.CreatorTime   = DateTime.Now;
                sysRoleInfo.CreatorUserId = token.Id;
                sysRoleInfo.Id            = roleId;
                sysRoleInfo.DeleteMark    = false;
                var IsSuccess = await _sysRoleService.AddAsync(sysRoleInfo);

                if (!IsSuccess)
                {
                    res.code    = (int)ApiEnum.Failure;
                    res.message = "错误:添加角色失败";
                }
                else
                {
                    //添加权限
                    //Params.treeModels
                    res = await _sysRoleAuthorizeService.AddSysModuleActionsAsync(roleId, token.Id, Params.treeModels);
                }
            }
            catch (Exception ex)
            {
                res.code    = (int)ApiEnum.Error;
                res.message = "异常:" + ex.Message;
            }

            return(await Task.Run(() => res));
        }