Beispiel #1
0
 public List <AdminModule> GetRoleModules(int arid)
 {
     try
     {
         //读取角色表中的功能表
         IEnumerable <AdminRole_Module> listarm = _adminR_MRepository.GetMany(new DirectSpecification <AdminRole_Module>(arm => arm.ARID == arid), false);
         //封装amid到list
         // var listint = listarm.Select(item => item.AMID).ToList();
         //读取FID=0的功能表数据(一级菜单)
         //IEnumerable<AdminModule> listam = _adminModuleRepository.GetMany(new DirectSpecification<AdminModule>(am => listint.Contains(am.AMID) && am.IsEnable));
         return(listarm.Select(x => x.adminModule).ToList());
     }
     catch
     {
         throw new InvalidOperationException("获取一级菜单时出错!");
     }
 }
        public void UpdateList(string[] moduleids, int arid)
        {
            //对比老数据 无改动的数据 权值不变 改动的才先删后增加
            //使用角色id找到功能ids
            List <AdminRole_Module> listarm = _repository.GetMany(new DirectSpecification <AdminRole_Module>(arm => arm.ARID == arid)).ToList();
            string addids = string.Empty;
            List <AdminRole_Module> tarm = null;

            foreach (var checkid in moduleids)
            {
                int         mmid = int.Parse(checkid);
                AdminModule admd = _adminModuleRepository.GetByCondition(new DirectSpecification <AdminModule>(a => a.AMID == mmid));
                if (admd.FID == 0)//if顶级菜单
                {
                    IEnumerable <AdminModule> listf = _adminModuleRepository.GetMany(new DirectSpecification <AdminModule>(m => m.FID == admd.AMID));
                    if (listf.Count() == 0)//if不存在子级菜单
                    {
                        throw new InvalidOperationException("您选择的顶级功能菜单有不包含子级的数据,请取消那些项的选择!");
                    }
                }
                tarm = listarm.Where(ami => ami.AMID == mmid && ami.ARID == arid).ToList();
                if (tarm.Count() == 0)//if 不存在功能关联数据
                {
                    addids += checkid + "|";
                }
                else //存在关联数据 移除该项
                {
                    listarm.Remove(tarm[0]);
                }
            }
            try
            {
                //对比功能ids的差异
                if (listarm.Count > 0)//修改后不包含的以前数据删除掉
                {
                    foreach (var rarm in listarm)
                    {
                        _repository.Remove(rarm);
                    }
                }
                if (addids.Length > 0)//添加修改后多出的数据
                {
                    string   newids = addids.Substring(0, addids.Length - 1);
                    string[] add    = newids.Split('|');
                    AddList(add, arid);
                }
            }
            catch
            {
                throw new InvalidOperationException("修改角色时出错!");
            }
        }