public ActionResult AddOrRemoveMenus(Guid roleId, string addMenuIDs, string removeMenuIDs) { string[] addIDs = addMenuIDs.Split(','); string[] removeIDs = removeMenuIDs.Split(','); const AcElementType subjectType = AcElementType.Role; const AcElementType acObjectType = AcElementType.Menu; foreach (var item in addIDs) { if (!string.IsNullOrEmpty(item) && removeIDs.All(a => a != item)) { var mId = new Guid(item); var entity = AcDomain.PrivilegeSet.FirstOrDefault(a => a.SubjectType == subjectType && a.SubjectInstanceId == roleId && a.ObjectType == acObjectType && a.ObjectInstanceId == mId); if (entity == null) { var createInput = new PrivilegeCreateIo { Id = Guid.NewGuid(), SubjectType = subjectType.ToName(), SubjectInstanceId = roleId, ObjectInstanceId = mId, ObjectType = acObjectType.ToName(), AcContentType = null, AcContent = null }; AcDomain.Handle(createInput.ToCommand(AcSession)); } } } foreach (var item in removeIDs) { if (!string.IsNullOrEmpty(item)) { var mId = new Guid(item); var entity = AcDomain.PrivilegeSet.FirstOrDefault(a => a.SubjectType == subjectType && a.SubjectInstanceId == roleId && a.ObjectType == acObjectType && a.ObjectInstanceId == mId); if (entity != null) { AcDomain.Handle(new RemovePrivilegeCommand(AcSession, entity.Id)); } } } return(this.JsonResult(new ResponseData { success = true })); }
internal PrivilegeState InternalModify(PrivilegeBase privilege) { if (privilege == null) { throw new ArgumentNullException("privilege"); } if (string.IsNullOrEmpty(privilege.SubjectType)) { throw new AnycmdException("必须指定主授权授权类型"); } if (string.IsNullOrEmpty(privilege.ObjectType)) { throw new AnycmdException("必须指定授权授权类型"); } AcElementType subjectType; AcElementType acObjectType; AcRecordType acType; if (!privilege.SubjectType.TryParse(out subjectType)) { throw new AnycmdException("非法的主授权类型" + privilege.SubjectType); } if (!privilege.ObjectType.TryParse(out acObjectType)) { throw new AnycmdException("非法的从授权类型" + privilege.ObjectType); } if (!(privilege.SubjectType + privilege.ObjectType).TryParse(out acType)) { throw new AnycmdException("非法的授权类型" + privilege.ObjectType); } _acType = acType; _subjectType = subjectType; _subjectInstanceId = privilege.SubjectInstanceId; _objectType = acObjectType; _objectInstanceId = privilege.ObjectInstanceId; _acContent = privilege.AcContent; _createBy = privilege.CreateBy; _createUserId = privilege.CreateUserId; _acContentType = privilege.AcContentType; return(this); }