Esempio n. 1
0
        public static CPModuleEngine Instance(int curUserId)
        {
            CPModuleEngine iObj = CPAppContext.GetService <CPModuleEngine>();

            iObj.CurUserId = curUserId;
            return(iObj);
        }
Esempio n. 2
0
        public GetChildModuleReturn GetChildModule(int SysId, int ParentModuleId, bool IsLoadChildModule, int CurUserId, string CurUserIden)
        {
            base.SetHeader();
            CurUserIden = CPAppContext.FormatSqlPara(CurUserIden);
            GetChildModuleReturn re = new GetChildModuleReturn();

            if (this.CheckUserIden(CurUserId, CurUserIden) == false)
            {
                re.Result   = false;
                re.ErrorMsg = "系统检测到非法获取数据,请传入正确的用户会话Key与用户Id参数!";
                return(re);
            }
            try
            {
                List <CPPortalModule> moduleCol = CPModuleEngine.Instance(CurUserId).GetModules(CurUserId, SysId, ParentModuleId);
                re.ModuleCol = new List <CPPortalModuleClient>();
                Mapper.Initialize(cfg =>
                {
                    cfg.CreateMap <CPPortalModule, CPPortalModuleClient>();
                });
                moduleCol.ForEach(t =>
                {
                    CPPortalModuleClient c = AutoMapper.Mapper.Map <CPPortalModuleClient>(t);
                    c.ChildModule          = new List <CPPortalModuleClient>();
                    if (IsLoadChildModule)
                    {
                        List <CPPortalModule> cModuleCol = CPModuleEngine.Instance(CurUserId).GetModules(CurUserId, SysId, t.Id);
                        cModuleCol.ForEach(f =>
                        {
                            CPPortalModuleClient tmp = AutoMapper.Mapper.Map <CPPortalModuleClient>(f);
                            c.ChildModule.Add(tmp);
                        });
                    }
                    re.ModuleCol.Add(c);
                });
                re.Result = true;
                return(re);
            }
            catch (Exception ex)
            {
                re.Result   = false;
                re.ErrorMsg = ex.Message.ToString();
                return(re);
            }
        }
Esempio n. 3
0
        public CPWebApiBaseReturnEntity SetRoleModuleIdsToSession(int RoleId, int SysId, int CurUserId, string CurUserIden)
        {
            base.SetHeader();
            CurUserIden = CPAppContext.FormatSqlPara(CurUserIden);
            CPWebApiBaseReturnEntity re = new CPWebApiBaseReturnEntity();

            if (this.CheckUserIden(CurUserId, CurUserIden) == false)
            {
                re.Result   = false;
                re.ErrorMsg = "系统检测到非法获取数据,请传入正确的用户会话Key与用户Id参数!";
                return(re);
            }
            try
            {
                List <CPPortalModule> col = CPModuleEngine.Instance(CurUserId).GetModulesWithRight(new List <int>()
                {
                    RoleId
                }, SysId);
                string ids = "";
                col.ForEach(t =>
                {
                    if (string.IsNullOrEmpty(ids))
                    {
                        ids = t.Id.ToString();
                    }
                    else
                    {
                        ids += "," + t.Id.ToString();
                    }
                });
                CPAppContext.GetHttpContext().Session.SetString("CurUserModuleRightInRole", ids);
                re.Result = true;
                return(re);
            }
            catch (Exception ex)
            {
                re.Result   = false;
                re.ErrorMsg = ex.Message.ToString();
                return(re);
            }
        }
Esempio n. 4
0
        public CPWebApiBaseReturnEntity SetRoleModuleRight([FromBody] SetRoleModuleRightInput input)
        {
            base.SetHeader();
            CPWebApiBaseReturnEntity re = new CPWebApiBaseReturnEntity();

            if (this.CheckUserIden(input.CurUserId, input.CurUserIden) == false)
            {
                re.Result   = false;
                re.ErrorMsg = "系统检测到非法获取数据,请传入正确的用户会话Key与用户Id参数!";
                return(re);
            }
            try
            {
                List <CPPortalModuleRight> col = new List <CPPortalModuleRight>();
                string[] sArray = input.ModuleIds.Split(',');
                sArray.ToList().ForEach(t =>
                {
                    if (string.IsNullOrEmpty(t))
                    {
                        return;
                    }
                    CPPortalModuleRight item = new CPPortalModuleRight();
                    item.RoleId   = input.RoleId;
                    item.ModuleId = int.Parse(t);
                    col.Add(item);
                });
                re.Result = CPModuleEngine.Instance(input.CurUserId).InitRoleModuleRight(input.RoleId, col);

                return(re);
            }
            catch (Exception ex)
            {
                re.Result   = false;
                re.ErrorMsg = ex.Message.ToString();
                return(re);
            }
        }