public ActionResult GrantOrDenyRoles() { String json = Request["data"]; var rows = (ArrayList)MiniJSON.Decode(json); foreach (Hashtable row in rows) { var id = new Guid(row["Id"].ToString()); //根据记录状态,进行不同的增加、删除、修改操作 String state = row["_state"] != null ? row["_state"].ToString() : ""; //更新:_state为空或modified if (state == "modified" || state == "") { bool isAssigned = bool.Parse(row["IsAssigned"].ToString()); var entity = GetRequiredService <IRepository <Privilege, Guid> >().GetByKey(id); if (entity != null) { if (!isAssigned) { AcDomain.Handle(new RemovePrivilegeCommand(AcSession, entity.Id)); } else { if (row.ContainsKey("AcContent")) { AcDomain.Handle(new PrivilegeUpdateIo { Id = id, AcContent = row["AcContent"].ToString() }.ToCommand(AcSession)); } } } else if (isAssigned) { var createInput = new PrivilegeCreateIo() { Id = new Guid(row["Id"].ToString()), SubjectType = UserAcSubjectType.Role.ToName(), SubjectInstanceId = new Guid(row["RoleId"].ToString()), ObjectInstanceId = new Guid(row["GroupId"].ToString()), ObjectType = AcElementType.Group.ToName(), AcContent = null, AcContentType = null }; if (row.ContainsKey("AcContent")) { createInput.AcContent = row["AcContent"].ToString(); } AcDomain.Handle(createInput.ToCommand(AcSession)); } } } return(this.JsonResult(new ResponseData { success = true })); }
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 })); }
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 }); }
public ActionResult GrantOrDenyRoles() { String json = Request["data"]; var rows = (ArrayList)MiniJSON.Decode(json); foreach (Hashtable row in rows) { var id = new Guid(row["Id"].ToString()); //根据记录状态,进行不同的增加、删除、修改操作 String state = row["_state"] != null ? row["_state"].ToString() : ""; //更新:_state为空或modified if (state == "modified" || state == "") { bool isAssigned = bool.Parse(row["IsAssigned"].ToString()); var entity = GetRequiredService<IRepository<Privilege>>().GetByKey(id); if (entity != null) { if (!isAssigned) { AcDomain.Handle(new RemovePrivilegeCommand(AcSession, id)); } else { if (row.ContainsKey("AcContent")) { AcDomain.Handle(new PrivilegeUpdateIo { Id = id, AcContent = row["AcContent"].ToString() }.ToCommand(AcSession)); } } } else if (isAssigned) { var createInput = new PrivilegeCreateIo { Id = new Guid(row["Id"].ToString()), ObjectType = AcElementType.Role.ToName(), ObjectInstanceId = new Guid(row["RoleId"].ToString()), SubjectInstanceId = new Guid(row["AccountId"].ToString()), SubjectType = UserAcSubjectType.Account.ToName(), AcContent = null, AcContentType = null }; if (row.ContainsKey("AcContent")) { createInput.AcContent = row["AcContent"].ToString(); } AcDomain.Handle(createInput.ToCommand(AcSession)); } } } return this.JsonResult(new ResponseData { success = true }); }