コード例 #1
0
ファイル: InGroupFilter.cs プロジェクト: MrUpsideDown/Rock
        /// <summary>
        /// Handles the SelectItem event of the gp control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void gp_SelectItem(object sender, EventArgs e)
        {
            var rockContext = new RockContext();

            int groupId      = gp.SelectedValueAsId() ?? 0;
            var groupService = new GroupService(rockContext);

            var group = groupService.Get(groupId);

            if (group != null)
            {
                var groupTypeRoleService = new GroupTypeRoleService(rockContext);
                var qryGroupTypeRoles    = groupTypeRoleService.Queryable();
                if (cbChildGroups.Checked)
                {
                    var childGroupTypeIds = groupService.GetAllDescendents(group.Id).Select(a => a.GroupTypeId).Distinct().ToList();
                    qryGroupTypeRoles = qryGroupTypeRoles.Where(a => a.GroupTypeId.HasValue && (a.GroupTypeId == group.GroupTypeId || childGroupTypeIds.Contains(a.GroupTypeId.Value)));
                }
                else
                {
                    qryGroupTypeRoles = qryGroupTypeRoles.Where(a => a.GroupTypeId.HasValue && a.GroupTypeId == group.GroupTypeId);
                }

                var list = qryGroupTypeRoles.OrderBy(a => a.GroupType.Order).ThenBy(a => a.GroupType.Name).ThenBy(a => a.Order).ThenBy(a => a.Name).ToList();
                cblRole.Items.Clear();
                foreach (var item in list)
                {
                    cblRole.Items.Add(new ListItem(string.Format("{0} ({1})", item.Name, item.GroupType.Name), item.Guid.ToString()));
                }

                cblRole.Visible       = list.Count > 0;
                cbChildGroups.Visible = true;
            }
            else
            {
                cblRole.Visible       = false;
                cbChildGroups.Visible = false;
            }
        }
コード例 #2
0
        /// <summary>
        /// Handles the SelectItem event of the gp control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void gp_SelectItem(object sender, EventArgs e)
        {
            int groupId      = gp.SelectedValueAsId() ?? 0;
            var groupService = new GroupService();
            var group        = groupService.Get(groupId);

            if (group != null)
            {
                var groupTypeRoleService = new GroupTypeRoleService();
                var list = groupTypeRoleService.Queryable().Where(a => a.GroupTypeId == group.GroupTypeId).OrderBy(a => a.Order).ToList();
                cblRole.Items.Clear();
                foreach (var item in list)
                {
                    cblRole.Items.Add(new ListItem(item.Name, item.Id.ToString()));
                }

                cblRole.Visible = list.Count > 0;
            }
            else
            {
                cblRole.Visible = false;
            }
        }