Ejemplo n.º 1
0
        /// <summary>
        /// Sorts the groups for group member.
        /// </summary>
        /// <param name="eventParam">The event parameter.</param>
        /// <param name="values">The values.</param>
        private void SortGroupsForGroupMember(string eventParam, string[] values)
        {
            string panelWidgetClientId = values[0];
            int    newIndex            = int.Parse(values[1]);

            if (Person != null && Person.Id > 0)
            {
                Panel       pnlWidget = this.ControlsOfTypeRecursive <Panel>().FirstOrDefault(a => a.ClientID == panelWidgetClientId);
                HiddenField hfGroupId = pnlWidget.FindControl("hfGroupId") as HiddenField;
                var         groupId   = hfGroupId.Value.AsInteger();

                using (_bindGroupsRockContext = new RockContext())
                {
                    var memberService     = new GroupMemberService(_bindGroupsRockContext);
                    var groupMemberGroups = memberService.Queryable(true)
                                            .Where(m =>
                                                   m.PersonId == Person.Id &&
                                                   m.Group.GroupTypeId == _groupType.Id)
                                            .OrderBy(m => m.GroupOrder ?? int.MaxValue).ThenBy(m => m.Id)
                                            .ToList();

                    var groupMember = groupMemberGroups.FirstOrDefault(a => a.GroupId == groupId);
                    if (groupMember != null)
                    {
                        memberService.ReorderGroupMemberGroup(groupMemberGroups, groupMemberGroups.IndexOf(groupMember), newIndex);
                        _bindGroupsRockContext.SaveChanges();
                    }

                    BindGroups();
                }
            }
        }