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("修改角色时出错!"); } }
public void DeleteRole(AdminRole ar) { //判断角色是否正在使用(管理员) //SystemAdmin admin= _sysAdminRepository.GetByCondition(new DirectSpecification<SystemAdmin>(x => x.AdminRoles.Any(y => y.ARID == arid))); if (CheckAdmin(ar.ARID)) { throw new InvalidOperationException("删除失败:当前角色下存在管理员!"); } using (TransactionScope scope = new TransactionScope()) { //删从表 _adminR_MRepository.Remove(new DirectSpecification <AdminRole_Module>(am => am.ARID == ar.ARID)); //删主表 _repository.Remove(ar); scope.Complete(); } }