Exemplo n.º 1
0
        public OperationResult FindByRolesWithSimpleInfo(int[] roleIds)
        {
            OperationResult result = new OperationResult();

            if (roleIds == null || roleIds.Length < 1)
            {
                result.ResultType = OperationResultType.ParamError;
                result.Message    = Msg_FindByRolesWithSimpleInfo + ",参数错误,角色不能为空";
                return(result);
            }
            try
            {
                var perType = PermissionType.Operation.ToInt();
                var query   = from opt in _optRepository.Entities
                              join per in _rolePerRepository.Find(per => per.PerType == perType) on opt.Id equals per.PermissionId
                              join role in _roleRepository.Entities on per.RoleId equals role.Id
                              where roleIds.Contains(per.RoleId) && opt.Enabled && role.Enabled
                              select new
                {
                    Id       = opt.Id,
                    OptCode  = opt.OptCode,
                    OptName  = opt.OptName,
                    ModuleId = opt.ModuleId
                };
                result.ResultType = OperationResultType.Success;
                result.AppendData = query.ToList();
            }
            catch (Exception ex)
            {
                base.ProcessException(ref result, Msg_FindByRolesWithSimpleInfo + "错误", ex);
            }
            return(result);
        }
Exemplo n.º 2
0
        public OperationResult FindByRolesWithSimpleInfo(int[] roleIds)
        {
            OperationResult result = new OperationResult();

            if (roleIds == null || roleIds.Length < 1)
            {
                result.ResultType = OperationResultType.ParamError;
                result.Message    = Msg_SearchSimpleInfoByRoles + "参数错误,角色不能为空";
                return(result);
            }
            var perType = PermissionType.Module.ToInt();
            var query   = from module in _moduleRepository.Entities
                          join per in _rolePermissionRep.Find(per => per.PerType == perType) on module.Id equals per.PermissionId
                          join role in _roleRep.Entities on per.RoleId equals role.Id
                          where roleIds.Contains(per.RoleId) &&
                          module.Enabled == true &&
                          role.Enabled == true
                          select new ModuleSimpleViewModel
            {
                Id        = module.Id,
                Code      = module.Code,
                Name      = module.Name,
                LinkUrl   = module.LinkUrl,
                Icon      = module.Icon,
                SortOrder = module.SortOrder,
                ParentId  = module.ParentId,
            };

            try
            {
                result.ResultType = OperationResultType.Success;
                result.AppendData = query.Distinct().ToList();//去重
            }
            catch (Exception ex)
            {
                base.ProcessException(ref result, string.Format(Msg_SearchSimpleInfoByRoles + ",失败"), ex);
            }
            return(result);
        }