protected static void DefaultCMSContentCreated(object sender, ActiveEventArgs e) { AccessEntity a = new AccessEntity(); a.MenuValue = "url:~/"; a.RoleName = "Everyone"; a.Save(); }
protected void CreateNewRoleMenuMapping(object sender, ActiveEventArgs e) { string roleName = e.Params["RoleName"].Get<string>(); string menuValue = e.Params["MenuValue"].Get<string>(); string pars = e.Params["Params"].Get<string>(); List<Criteria> crit = new List<Criteria> { Criteria.Eq("MenuValue", menuValue), Criteria.Eq("RoleName", roleName) }; if( pars != null) crit.Add(Criteria.Eq("Params", pars)); if (string.IsNullOrEmpty(menuValue)) { Node node = new Node(); node["Message"].Value = Language.Instance["RoleYouCanNotInfo", null, @"You cannot change the accessibility of that item since it has no 'Value' property"]; node["Duration"].Value = 2000; ActiveEvents.Instance.RaiseActiveEvent( this, "ShowInformationMessage", node); } else if (ActiveType<AccessEntity>.CountWhere(crit.ToArray()) > 0) { Node node = new Node(); node["Message"].Value = String.Format(Language.Instance["RoleAlreadyAssociatedInfo", null, @"Role; '{0}' already associated with item..."], roleName); node["Duration"].Value = 2000; ActiveEvents.Instance.RaiseActiveEvent( this, "ShowInformationMessage", node); } else { AccessEntity a = new AccessEntity { MenuValue = menuValue, RoleName = roleName, Params = pars }; a.Save(); // Running upwards in the hierarchy and creating new access objects for all // parents recursively, since otherwise there's no point at all in adding // the access to the menu item... Node parent = e.Params["Parents", false]; while (parent != null) { string parentRoleName = parent["RoleName"].Get<string>(); string parentMenuValue = parent["MenuValue"].Get<string>(); if (parentMenuValue == null) break; if (ActiveType<AccessEntity>.CountWhere( Criteria.Eq("RoleName", parentRoleName), Criteria.Eq("MenuValue", parentMenuValue)) == 0) { AccessEntity aParent = new AccessEntity { RoleName = parentRoleName, MenuValue = parentMenuValue }; aParent.Save(); } parent = parent["Parents", false]; } // Sending back updates... int idxNo = 0; foreach (AccessEntity idx in ActiveType<AccessEntity>.Select()) { e.Params["Access"]["Access" + idxNo]["MenuValue"].Value = idx.MenuValue; e.Params["Access"]["Access" + idxNo]["RoleName"].Value = idx.RoleName; e.Params["Access"]["Access" + idxNo]["Params"].Value = idx.Params; idxNo += 1; } } }