Esempio n. 1
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            int personEntityTypeId = EntityTypeCache.Read("Rock.Model.Person").Id;

            if (ContextTypesRequired.Any(e => e.Id == personEntityTypeId) && ContextEntity <Person>() == null)
            {
                return;
            }

            var qry = new UserLoginService(new RockContext()).Queryable()
                      .Where(l => !_personId.HasValue || l.PersonId == _personId.Value);

            // username filter
            string usernameFilter = gfSettings.GetUserPreference("Username");

            if (!string.IsNullOrWhiteSpace(usernameFilter))
            {
                qry = qry.Where(l => l.UserName.StartsWith(usernameFilter));
            }

            // provider filter
            Guid guid = Guid.Empty;

            if (Guid.TryParse(gfSettings.GetUserPreference("Authentication Provider"), out guid))
            {
                qry = qry.Where(l => l.EntityType.Guid.Equals(guid));
            }

            // created filter
            var drp = new DateRangePicker();

            drp.DelimitedValues = gfSettings.GetUserPreference("Created");
            if (drp.LowerValue.HasValue)
            {
                qry = qry.Where(l => l.CreatedDateTime.HasValue && l.CreatedDateTime.Value >= drp.LowerValue.Value);
            }

            if (drp.UpperValue.HasValue)
            {
                DateTime upperDate = drp.UpperValue.Value.Date.AddDays(1);
                qry = qry.Where(l => l.CreatedDateTime.HasValue && l.CreatedDateTime < upperDate);
            }

            // last login filter
            var drp2 = new DateRangePicker();

            drp2.DelimitedValues = gfSettings.GetUserPreference("Last Login");
            if (drp2.LowerValue.HasValue)
            {
                qry = qry.Where(l => l.LastLoginDateTime >= drp2.LowerValue.Value);
            }

            if (drp2.UpperValue.HasValue)
            {
                DateTime upperDate = drp2.UpperValue.Value.Date.AddDays(1);
                qry = qry.Where(l => l.LastLoginDateTime < upperDate);
            }

            // Is Confirmed filter
            bool isConfirmed = false;

            if (bool.TryParse(gfSettings.GetUserPreference("Is Confirmed"), out isConfirmed))
            {
                qry = qry.Where(l => l.IsConfirmed == isConfirmed || (!isConfirmed && l.IsConfirmed == null));
            }

            // is locked out filter
            bool isLockedOut = false;

            if (bool.TryParse(gfSettings.GetUserPreference("Is Locked Out"), out isLockedOut))
            {
                qry = qry.Where(l => l.IsLockedOut == isLockedOut || (!isLockedOut && l.IsLockedOut == null));
            }

            // Sort
            SortProperty sortProperty = gUserLogins.SortProperty;

            if (sortProperty == null)
            {
                sortProperty = new SortProperty(new GridViewSortEventArgs("UserName", SortDirection.Ascending));
            }

            gUserLogins.DataSource = qry.Sort(sortProperty)
                                     .Select(l => new
            {
                Id                = l.Id,
                UserName          = l.UserName,
                PersonId          = l.PersonId,
                PersonName        = l.Person.LastName + ", " + l.Person.NickName,
                ProviderName      = l.EntityType.FriendlyName,
                CreatedDateTime   = l.CreatedDateTime,
                LastLoginDateTime = l.LastLoginDateTime,
                IsConfirmed       = l.IsConfirmed,
                IsLockedOut       = l.IsLockedOut
            }).ToList();
            gUserLogins.DataBind();
        }
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            // If configured for a person and person is null, return
            int personEntityTypeId = EntityTypeCache.Get <Person>().Id;

            if (ContextTypesRequired.Any(e => e.Id == personEntityTypeId) && _person == null)
            {
                return;
            }

            var rockContext = new RockContext();

            var qryCommunications = new CommunicationService(rockContext).Queryable().Where(c => c.Status != CommunicationStatus.Transient);

            string subject = tbSubject.Text;

            if (!string.IsNullOrWhiteSpace(subject))
            {
                qryCommunications = qryCommunications.Where(c => (string.IsNullOrEmpty(c.Subject) && c.Name.Contains(subject)) || c.Subject.Contains(subject));
            }

            var communicationType = ddlType.SelectedValueAsEnumOrNull <CommunicationType>();

            if (communicationType != null)
            {
                qryCommunications = qryCommunications.Where(c => c.CommunicationType == communicationType);
            }

            var communicationStatus = ddlStatus.SelectedValue.ConvertToEnumOrNull <CommunicationStatus>();

            if (communicationStatus.HasValue)
            {
                qryCommunications = qryCommunications.Where(c => c.Status == communicationStatus.Value);
            }

            // only communications for the selected recipient (_person)
            if (_person != null)
            {
                qryCommunications = qryCommunications
                                    .Where(c =>
                                           c.Recipients.Any(a =>
                                                            a.PersonAlias.PersonId == _person.Id &&
                                                            (a.Status == CommunicationRecipientStatus.Delivered || a.Status == CommunicationRecipientStatus.Opened)));
            }

            if (drpDates.LowerValue.HasValue)
            {
                qryCommunications = qryCommunications.Where(a => a.CreatedDateTime >= drpDates.LowerValue.Value);
            }

            if (drpDates.UpperValue.HasValue)
            {
                DateTime upperDate = drpDates.UpperValue.Value.Date.AddDays(1);
                qryCommunications = qryCommunications.Where(a => a.CreatedDateTime < upperDate);
            }

            string content = tbContent.Text;

            if (!string.IsNullOrWhiteSpace(content))
            {
                qryCommunications = qryCommunications.Where(c =>
                                                            c.Message.Contains(content) ||
                                                            c.SMSMessage.Contains(content) ||
                                                            c.PushMessage.Contains(content));
            }

            var queryable = qryCommunications
                            .Select(c => new CommunicationItem
            {
                Id = c.Id,
                CommunicationType = c.CommunicationType,
                // Subject = string.IsNullOrEmpty( c.Subject ) ? c.Name : c.Subject,
                Subject                = string.IsNullOrEmpty(c.Name) ? (string.IsNullOrEmpty(c.Subject) ? c.PushTitle : c.Subject) : c.Name,
                CreatedDateTime        = c.CreatedDateTime,
                Sender                 = c.SenderPersonAlias != null ? c.SenderPersonAlias.Person : null,
                Status                 = c.Status,
                CreatedByPersonAliasId = c.CreatedByPersonAliasId
            });


            var sortProperty = gCommunication.SortProperty;

            if (sortProperty != null)
            {
                queryable = queryable.Sort(sortProperty);
            }
            else
            {
                queryable = queryable.OrderByDescending(c => c.CreatedDateTime);
            }

            gCommunication.EntityTypeId = EntityTypeCache.Get <Rock.Model.Communication>().Id;
            gCommunication.SetLinqDataSource(queryable.AsNoTracking());
            gCommunication.DataBind();
        }
Esempio n. 3
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            // Find all the Group Types
            var groupTypeIds = GetAvailableGroupTypes();

            if (GetAttributeValue("DisplayFilter").AsBooleanOrNull() ?? false)
            {
                int?groupTypeFilter = gfSettings.GetUserPreference("Group Type").AsIntegerOrNull();
                if (groupTypeFilter.HasValue)
                {
                    groupTypeIds = groupTypeIds.Where(g => g == groupTypeFilter.Value).ToList();
                }
            }

            // filter to a specific group type if provided in the query string
            if (!string.IsNullOrWhiteSpace(RockPage.PageParameter("GroupTypeId")))
            {
                int?groupTypeId = RockPage.PageParameter("GroupTypeId").AsIntegerOrNull();

                if (groupTypeId.HasValue)
                {
                    groupTypeIds.Clear();
                    groupTypeIds.Add(groupTypeId.Value);
                }
            }

            var rockContext  = new RockContext();
            var groupService = new GroupService(rockContext);

            SortProperty sortProperty = gGroups.SortProperty;

            if (sortProperty == null)
            {
                sortProperty = new SortProperty(new GridViewSortEventArgs("Name", SortDirection.Ascending));
            }

            bool onlySecurityGroups = GetAttributeValue("LimittoSecurityRoleGroups").AsBoolean();

            var qryGroups = groupService.Queryable()
                            .Where(g => groupTypeIds.Contains(g.GroupTypeId) && (!onlySecurityGroups || g.IsSecurityRole));

            string limitToActiveStatus = GetAttributeValue("LimittoActiveStatus");

            bool showActive   = true;
            bool showInactive = true;

            if (limitToActiveStatus == "all" && gfSettings.Visible)
            {
                // Filter by active/inactive unless the block settings restrict it
                if (ddlActiveFilter.SelectedIndex > -1)
                {
                    switch (ddlActiveFilter.SelectedValue)
                    {
                    case "active":
                        showInactive = false;
                        break;

                    case "inactive":
                        showActive = false;
                        break;
                    }
                }
            }
            else if (limitToActiveStatus != "all")
            {
                // filter by the block setting for Active Status
                if (limitToActiveStatus == "active")
                {
                    showInactive = false;
                }
            }


            var groupTypePurposeValue = gfSettings.GetUserPreference("Group Type Purpose").AsIntegerOrNull();

            var groupList = new List <GroupListRowInfo>();

            // Person context will exist if used on a person detail page
            int personEntityTypeId = EntityTypeCache.Read("Rock.Model.Person").Id;

            if (ContextTypesRequired.Any(e => e.Id == personEntityTypeId))
            {
                var personContext = ContextEntity <Person>();
                if (personContext != null)
                {
                    // limit to Groups that the person is a member of
                    var qry = new GroupMemberService(rockContext).Queryable(true)
                              .Where(m => m.PersonId == personContext.Id)
                              .Join(qryGroups, gm => gm.GroupId, g => g.Id, (gm, g) => new { Group = g, GroupMember = gm });

                    // Filter by Active Status of Group and Group Membership.
                    if (showActive && !showInactive)
                    {
                        // Show only active Groups and active Memberships.
                        qry = qry.Where(gmg => gmg.Group.IsActive && gmg.GroupMember.GroupMemberStatus == GroupMemberStatus.Active);
                    }
                    else if (!showActive)
                    {
                        // Show only inactive Groups or inactive Memberships.
                        qry = qry.Where(gmg => !gmg.Group.IsActive || gmg.GroupMember.GroupMemberStatus == GroupMemberStatus.Inactive);
                    }

                    if (groupTypePurposeValue.HasValue && gfSettings.Visible)
                    {
                        qry = qry.Where(t => t.Group.GroupType.GroupTypePurposeValueId == groupTypePurposeValue);
                    }

                    groupList = qry
                                .AsEnumerable()
                                .Where(gm => gm.Group.IsAuthorized(Rock.Security.Authorization.VIEW, CurrentPerson))
                                .Select(m => new GroupListRowInfo
                    {
                        Id             = m.Group.Id,
                        Path           = string.Empty,
                        Name           = m.Group.Name,
                        GroupTypeName  = m.Group.GroupType.Name,
                        GroupOrder     = m.Group.Order,
                        GroupTypeOrder = m.Group.GroupType.Order,
                        Description    = m.Group.Description,
                        IsSystem       = m.Group.IsSystem,
                        GroupRole      = m.GroupMember.GroupRole.Name,
                        DateAdded      = m.GroupMember.DateTimeAdded ?? m.GroupMember.CreatedDateTime,
                        IsActive       = m.Group.IsActive && (m.GroupMember.GroupMemberStatus == GroupMemberStatus.Active),
                        IsActiveOrder  = (m.Group.IsActive && (m.GroupMember.GroupMemberStatus == GroupMemberStatus.Active) ? 1 : 2),
                        IsSynced       = m.Group.SyncDataViewId.HasValue,
                        MemberCount    = 0
                    })
                                .AsQueryable()
                                .Sort(sortProperty)
                                .ToList();
                }
            }
            else
            {
                var  roleGroupType   = GroupTypeCache.Read(Rock.SystemGuid.GroupType.GROUPTYPE_SECURITY_ROLE.AsGuid());
                int  roleGroupTypeId = roleGroupType != null ? roleGroupType.Id : 0;
                bool useRolePrefix   = onlySecurityGroups || groupTypeIds.Contains(roleGroupTypeId);

                if (!showInactive)
                {
                    qryGroups = qryGroups.Where(x => x.IsActive);
                }
                else if (!showActive)
                {
                    qryGroups = qryGroups.Where(x => !x.IsActive);
                }

                if (groupTypePurposeValue.HasValue && gfSettings.Visible)
                {
                    qryGroups = qryGroups.Where(t => t.GroupType.GroupTypePurposeValueId == groupTypePurposeValue);
                }

                groupList = qryGroups
                            .AsEnumerable()
                            .Where(g => g.IsAuthorized(Rock.Security.Authorization.VIEW, CurrentPerson))
                            .Select(g => new GroupListRowInfo
                {
                    Id             = g.Id,
                    Path           = string.Empty,
                    Name           = ((useRolePrefix && g.GroupType.Id != roleGroupTypeId) ? "GROUP - " : "") + g.Name,
                    GroupTypeName  = g.GroupType.Name,
                    GroupOrder     = g.Order,
                    GroupTypeOrder = g.GroupType.Order,
                    Description    = g.Description,
                    IsSystem       = g.IsSystem,
                    IsActive       = g.IsActive,
                    IsActiveOrder  = g.IsActive ? 1 : 2,
                    GroupRole      = string.Empty,
                    DateAdded      = DateTime.MinValue,
                    IsSynced       = g.SyncDataViewId.HasValue,
                    MemberCount    = g.Members.Count()
                })
                            .AsQueryable()
                            .Sort(sortProperty)
                            .ToList();
            }

            if (_showGroupPath)
            {
                foreach (var groupRow in groupList)
                {
                    groupRow.Path = groupService.GroupAncestorPathName(groupRow.Id);
                }
            }

            gGroups.DataSource   = groupList;
            gGroups.EntityTypeId = EntityTypeCache.Read <Group>().Id;
            gGroups.DataBind();

            // hide the group type column if there's only one type; must come after DataBind()
            if (_groupTypesCount == 1)
            {
                var groupTypeColumn = this.gGroups.ColumnsOfType <RockBoundField>().FirstOrDefault(a => a.DataField == "GroupTypeName");
                groupTypeColumn.Visible = false;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Applies the block settings.
        /// </summary>
        private void ApplyBlockSettings()
        {
            gfSettings.Visible           = GetAttributeValue("DisplayFilter").AsBooleanOrNull() ?? false;
            gfSettings.ApplyFilterClick += gfSettings_ApplyFilterClick;

            // only show the user active filter if the block setting doesn't already restrict it
            ddlActiveFilter.Visible = GetAttributeValue("LimittoActiveStatus") == "all";

            gGroups.DataKeyNames      = new string[] { "Id" };
            gGroups.Actions.ShowAdd   = true;
            gGroups.Actions.AddClick += gGroups_Add;
            gGroups.GridRebind       += gGroups_GridRebind;
            gGroups.RowDataBound     += gGroups_RowDataBound;
            gGroups.ExportSource      = ExcelExportSource.DataSource;

            // set up Grid based on Block Settings and Context
            bool showDescriptionColumn  = GetAttributeValue("DisplayDescriptionColumn").AsBoolean();
            bool showActiveStatusColumn = GetAttributeValue("DisplayActiveStatusColumn").AsBoolean();
            bool showSystemColumn       = GetAttributeValue("DisplaySystemColumn").AsBoolean();
            bool showSecurityColumn     = GetAttributeValue("DisplaySecurityColumn").AsBoolean();

            if (!showDescriptionColumn)
            {
                gGroups.TooltipField = "Description";
            }

            _showGroupPath = GetAttributeValue("DisplayGroupPath").AsBoolean();

            Dictionary <string, BoundField> boundFields = gGroups.Columns.OfType <BoundField>().ToDictionary(a => a.DataField);

            boundFields["Name"].Visible = !_showGroupPath;

            // The GroupPathName field is the RockTemplateField that has a headertext of "Name"
            var groupPathNameField = gGroups.ColumnsOfType <RockTemplateField>().FirstOrDefault(a => a.HeaderText == "Name");

            groupPathNameField.Visible = _showGroupPath;

            boundFields["GroupTypeName"].Visible = GetAttributeValue("DisplayGroupTypeColumn").AsBoolean();
            boundFields["Description"].Visible   = showDescriptionColumn;

            Dictionary <string, BoolField> boolFields = gGroups.Columns.OfType <BoolField>().ToDictionary(a => a.DataField);

            boolFields["IsActive"].Visible = showActiveStatusColumn;
            boolFields["IsSystem"].Visible = showSystemColumn;

            var securityField = gGroups.ColumnsOfType <SecurityField>().FirstOrDefault();

            if (securityField != null)
            {
                securityField.Visible = showSecurityColumn;
            }

            int personEntityTypeId = EntityTypeCache.Read("Rock.Model.Person").Id;

            if (ContextTypesRequired.Any(a => a.Id == personEntityTypeId))
            {
                var personContext = ContextEntity <Person>();
                if (personContext != null)
                {
                    boundFields["GroupRole"].Visible    = true;
                    boundFields["DateAdded"].Visible    = true;
                    boundFields["MemberCount"].Visible  = false;
                    gGroups.IsDeleteEnabled             = true;
                    gGroups.HideDeleteButtonForIsSystem = false;
                }
            }
            else
            {
                bool canEdit = IsUserAuthorized(Authorization.EDIT);
                gGroups.Actions.ShowAdd = canEdit;
                gGroups.IsDeleteEnabled = canEdit;

                boundFields["GroupRole"].Visible   = false;
                boundFields["DateAdded"].Visible   = false;
                boundFields["MemberCount"].Visible = GetAttributeValue("DisplayMemberCountColumn").AsBoolean();
            }

            SetPanelTitleAndIcon();
        }
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid(bool isExporting = false)
        {
            int?personId      = null;
            int?givingGroupId = null;

            bool validRequest = false;

            if (TargetPerson != null)
            {
                personId      = TargetPerson.Id;
                givingGroupId = TargetPerson.GivingGroupId;
                validRequest  = true;
            }
            else
            {
                int personEntityTypeId = EntityTypeCache.Read("Rock.Model.Person").Id;
                if (!ContextTypesRequired.Any(e => e.Id == personEntityTypeId))
                {
                    validRequest = true;
                }
            }

            if (validRequest)
            {
                var rockContext = new RockContext();
                var qry         = new FinancialScheduledTransactionService(rockContext)
                                  .Queryable("ScheduledTransactionDetails,FinancialPaymentDetail.CurrencyTypeValue,FinancialPaymentDetail.CreditCardTypeValue")
                                  .AsNoTracking();

                // Valid Accounts
                var accountGuids = GetAttributeValue("Accounts").SplitDelimitedValues().AsGuidList();
                if (accountGuids.Any())
                {
                    qry = qry.Where(t => t.ScheduledTransactionDetails.Any(d => accountGuids.Contains(d.Account.Guid)));
                }

                // Amount Range
                var nre = new NumberRangeEditor();
                nre.DelimitedValues = gfSettings.GetUserPreference("Amount");
                if (nre.LowerValue.HasValue)
                {
                    qry = qry.Where(t => t.ScheduledTransactionDetails.Sum(d => d.Amount) >= nre.LowerValue.Value);
                }

                if (nre.UpperValue.HasValue)
                {
                    qry = qry.Where(t => t.ScheduledTransactionDetails.Sum(d => d.Amount) <= nre.UpperValue.Value);
                }

                // Frequency
                int?frequencyTypeId = gfSettings.GetUserPreference("Frequency").AsIntegerOrNull();
                if (frequencyTypeId.HasValue)
                {
                    qry = qry.Where(t => t.TransactionFrequencyValueId == frequencyTypeId.Value);
                }

                // Date Range
                var drp = new DateRangePicker();
                drp.DelimitedValues = gfSettings.GetUserPreference("Created");
                if (drp.LowerValue.HasValue)
                {
                    qry = qry.Where(t => t.CreatedDateTime >= drp.LowerValue.Value);
                }

                if (drp.UpperValue.HasValue)
                {
                    DateTime upperDate = drp.UpperValue.Value.Date.AddDays(1);
                    qry = qry.Where(t => t.CreatedDateTime < upperDate);
                }

                // Account Id
                int accountId = int.MinValue;
                if (int.TryParse(gfSettings.GetUserPreference("Account"), out accountId) && ddlAccount.Visible)
                {
                    qry = qry.Where(t => t.ScheduledTransactionDetails.Any(d => d.AccountId == accountId));
                }

                // Active only (no filter)
                if (string.IsNullOrWhiteSpace(gfSettings.GetUserPreference("Include Inactive")))
                {
                    qry = qry.Where(t => t.IsActive);
                }

                if (givingGroupId.HasValue)
                {
                    //  Person contributes with family
                    qry = qry.Where(t => t.AuthorizedPersonAlias.Person.GivingGroupId == givingGroupId);
                }
                else if (personId.HasValue)
                {
                    // Person contributes individually
                    qry = qry.Where(t => t.AuthorizedPersonAlias.PersonId == personId);
                }

                SortProperty sortProperty = gList.SortProperty;
                if (sortProperty != null)
                {
                    if (sortProperty.Property == "Amount")
                    {
                        if (sortProperty.Direction == SortDirection.Ascending)
                        {
                            qry = qry.OrderBy(t => t.ScheduledTransactionDetails.Sum(d => (decimal?)d.Amount) ?? 0.00M);
                        }
                        else
                        {
                            qry = qry.OrderByDescending(t => t.ScheduledTransactionDetails.Sum(d => (decimal?)d.Amount) ?? 0.0M);
                        }
                    }
                    else
                    {
                        qry = qry.Sort(sortProperty);
                    }
                }
                else
                {
                    qry = qry
                          .OrderBy(t => t.AuthorizedPersonAlias.Person.LastName)
                          .ThenBy(t => t.AuthorizedPersonAlias.Person.NickName)
                          .ThenByDescending(t => t.IsActive)
                          .ThenByDescending(t => t.StartDate);
                }

                _isExporting = isExporting;

                gList.SetLinqDataSource <FinancialScheduledTransaction>(qry);
                gList.DataBind();

                _isExporting = false;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Handles the Delete event of the gGroups control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param>
        protected void gGroups_Delete(object sender, RowEventArgs e)
        {
            var          rockContext  = new RockContext();
            GroupService groupService = new GroupService(rockContext);
            AuthService  authService  = new AuthService(rockContext);
            Group        group        = groupService.Get(e.RowKeyId);

            if (group != null)
            {
                string errorMessage;
                bool   isSecurityRoleGroup = group.IsSecurityRole || group.GroupType.Guid.Equals(Rock.SystemGuid.GroupType.GROUPTYPE_SECURITY_ROLE.AsGuid());
                int    personEntityTypeId  = EntityTypeCache.Read("Rock.Model.Person").Id;

                if (ContextTypesRequired.Any(a => a.Id == personEntityTypeId))
                {
                    var personContext = ContextEntity <Person>();
                    GroupMemberService            groupMemberService = new GroupMemberService(rockContext);
                    RegistrationRegistrantService registrantService  = new RegistrationRegistrantService(rockContext);
                    GroupMember groupMember = group.Members.SingleOrDefault(a => a.PersonId == personContext.Id);

                    if (!(group.IsAuthorized(Authorization.EDIT, this.CurrentPerson) || group.IsAuthorized(Authorization.MANAGE_MEMBERS, this.CurrentPerson)))
                    {
                        mdGridWarning.Show("You are not authorized to delete members from this group", ModalAlertType.Information);
                        return;
                    }

                    if (!groupMemberService.CanDelete(groupMember, out errorMessage))
                    {
                        mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                        return;
                    }

                    foreach (var registrant in registrantService.Queryable().Where(r => r.GroupMemberId == groupMember.Id))
                    {
                        registrant.GroupMemberId = null;
                    }

                    if (group.IsSecurityRole || group.GroupType.Guid.Equals(Rock.SystemGuid.GroupType.GROUPTYPE_SECURITY_ROLE.AsGuid()))
                    {
                        // person removed from SecurityRole, Flush
                        Rock.Security.Role.Flush(group.Id);
                    }

                    groupMemberService.Delete(groupMember);
                }
                else
                {
                    if (!group.IsAuthorized(Authorization.EDIT, this.CurrentPerson))
                    {
                        mdGridWarning.Show("You are not authorized to delete this group", ModalAlertType.Information);
                        return;
                    }


                    if (!groupService.CanDelete(group, out errorMessage))
                    {
                        mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                        return;
                    }


                    if (isSecurityRoleGroup)
                    {
                        Rock.Security.Role.Flush(group.Id);
                        foreach (var auth in authService.Queryable().Where(a => a.GroupId == group.Id).ToList())
                        {
                            authService.Delete(auth);
                        }
                    }

                    groupService.Delete(group);
                }

                rockContext.SaveChanges();

                if (isSecurityRoleGroup)
                {
                    Rock.Security.Authorization.Flush();
                }
            }

            BindGrid();
        }
Esempio n. 7
0
        /// <summary>
        /// Applies the block settings.
        /// </summary>
        private void ApplyBlockSettings()
        {
            gfSettings.Visible           = GetAttributeValue("DisplayFilter").AsBooleanOrNull() ?? false;
            gfSettings.ApplyFilterClick += gfSettings_ApplyFilterClick;

            // only show the user active filter if the block setting doesn't already restrict it
            ddlActiveFilter.Visible = GetAttributeValue("LimittoActiveStatus") == "all";

            gGroups.DataKeyNames      = new string[] { "Id" };
            gGroups.Actions.ShowAdd   = true;
            gGroups.Actions.AddClick += gGroups_Add;
            gGroups.GridRebind       += gGroups_GridRebind;

            gGroups.RowDataBound += gGroups_RowDataBound;

            // set up Grid based on Block Settings and Context
            bool showDescriptionColumn  = GetAttributeValue("DisplayDescriptionColumn").AsBoolean();
            bool showActiveStatusColumn = GetAttributeValue("DisplayActiveStatusColumn").AsBoolean();
            bool showSystemColumn       = GetAttributeValue("DisplaySystemColumn").AsBoolean();

            if (!showDescriptionColumn)
            {
                gGroups.TooltipField = "Description";
            }

            Dictionary <string, BoundField> boundFields = gGroups.Columns.OfType <BoundField>().ToDictionary(a => a.DataField);

            boundFields["GroupTypeName"].Visible = GetAttributeValue("DisplayGroupTypeColumn").AsBoolean();
            boundFields["Description"].Visible   = showDescriptionColumn;

            Dictionary <string, BoolField> boolFields = gGroups.Columns.OfType <BoolField>().ToDictionary(a => a.DataField);

            boolFields["IsActive"].Visible = showActiveStatusColumn;
            boolFields["IsSystem"].Visible = showSystemColumn;

            int personEntityTypeId = EntityTypeCache.Read("Rock.Model.Person").Id;

            if (ContextTypesRequired.Any(a => a.Id == personEntityTypeId))
            {
                var personContext = ContextEntity <Person>();
                if (personContext != null)
                {
                    boundFields["GroupRole"].Visible   = true;
                    boundFields["DateAdded"].Visible   = true;
                    boundFields["MemberCount"].Visible = false;

                    gGroups.Actions.ShowAdd = false;
                    gGroups.IsDeleteEnabled = false;
                    gGroups.Columns.OfType <DeleteField>().ToList().ForEach(f => f.Visible = false);
                }
            }
            else
            {
                bool canEdit = IsUserAuthorized(Authorization.EDIT);
                gGroups.Actions.ShowAdd = canEdit;
                gGroups.IsDeleteEnabled = canEdit;

                boundFields["GroupRole"].Visible   = false;
                boundFields["DateAdded"].Visible   = false;
                boundFields["MemberCount"].Visible = GetAttributeValue("DisplayMemberCountColumn").AsBoolean();
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            _currencyTypes   = new Dictionary <int, string>();
            _creditCardTypes = new Dictionary <int, string>();

            // If configured for a registration and registration is null, return
            int registrationEntityTypeId = EntityTypeCache.Read(typeof(Rock.Model.Registration)).Id;

            if (ContextTypesRequired.Any(e => e.Id == registrationEntityTypeId) && _registration == null)
            {
                return;
            }

            // If configured for a person and person is null, return
            int personEntityTypeId = EntityTypeCache.Read("Rock.Model.Person").Id;

            if (ContextTypesRequired.Any(e => e.Id == personEntityTypeId) && _person == null)
            {
                return;
            }

            // If configured for a batch and batch is null, return
            int batchEntityTypeId = EntityTypeCache.Read("Rock.Model.FinancialBatch").Id;

            if (ContextTypesRequired.Any(e => e.Id == batchEntityTypeId) && _batch == null)
            {
                return;
            }

            // If configured for a batch and batch is null, return
            int scheduledTxnEntityTypeId = EntityTypeCache.Read("Rock.Model.FinancialScheduledTransaction").Id;

            if (ContextTypesRequired.Any(e => e.Id == scheduledTxnEntityTypeId) && _scheduledTxn == null)
            {
                return;
            }

            // Qry
            var rockContext = new RockContext();
            var qry         = new FinancialTransactionService(rockContext).Queryable();

            // Transaction Types
            var txnTypes = GetAttributeValue("TransactionTypes").SplitDelimitedValues().AsGuidList();

            if (txnTypes.Any())
            {
                qry = qry.Where(t => txnTypes.Contains(t.TransactionTypeValue.Guid));
            }

            // Set up the selection filter
            if (_batch != null)
            {
                // If transactions are for a batch, the filter is hidden so only check the batch id
                qry = qry.Where(t => t.BatchId.HasValue && t.BatchId.Value == _batch.Id);

                // If the batch is closed, do not allow any editing of the transactions
                if (_batch.Status != BatchStatus.Closed && _canEdit)
                {
                    gTransactions.IsDeleteEnabled = true;
                }
                else
                {
                    gTransactions.IsDeleteEnabled = false;
                }
            }
            else if (_scheduledTxn != null)
            {
                // If transactions are for a batch, the filter is hidden so only check the batch id
                qry = qry.Where(t => t.ScheduledTransactionId.HasValue && t.ScheduledTransactionId.Value == _scheduledTxn.Id);

                gTransactions.IsDeleteEnabled = false;
            }
            else if (_registration != null)
            {
                qry = qry
                      .Where(t => t.TransactionDetails
                             .Any(d =>
                                  d.EntityTypeId.HasValue &&
                                  d.EntityTypeId.Value == registrationEntityTypeId &&
                                  d.EntityId.HasValue &&
                                  d.EntityId.Value == _registration.Id));

                gTransactions.IsDeleteEnabled = false;
            }
            else    // Person
            {
                // otherwise set the selection based on filter settings
                if (_person != null)
                {
                    // get the transactions for the person or all the members in the person's giving group (Family)
                    qry = qry.Where(t => t.AuthorizedPersonAlias.Person.GivingId == _person.GivingId);
                }

                // Date Range
                var drp = new DateRangePicker();
                drp.DelimitedValues = gfTransactions.GetUserPreference("Date Range");
                if (drp.LowerValue.HasValue)
                {
                    qry = qry.Where(t => t.TransactionDateTime >= drp.LowerValue.Value);
                }

                if (drp.UpperValue.HasValue)
                {
                    DateTime upperDate = drp.UpperValue.Value.Date.AddDays(1);
                    qry = qry.Where(t => t.TransactionDateTime < upperDate);
                }

                // Amount Range
                var nre = new NumberRangeEditor();
                nre.DelimitedValues = gfTransactions.GetUserPreference("Amount Range");
                if (nre.LowerValue.HasValue)
                {
                    qry = qry.Where(t => t.TransactionDetails.Sum(d => d.Amount) >= nre.LowerValue.Value);
                }

                if (nre.UpperValue.HasValue)
                {
                    qry = qry.Where(t => t.TransactionDetails.Sum(d => d.Amount) <= nre.UpperValue.Value);
                }

                // Transaction Code
                string transactionCode = gfTransactions.GetUserPreference("Transaction Code");
                if (!string.IsNullOrWhiteSpace(transactionCode))
                {
                    qry = qry.Where(t => t.TransactionCode == transactionCode.Trim());
                }

                // Account Id
                var accountIds = (gfTransactions.GetUserPreference("Account") ?? "").SplitDelimitedValues().AsIntegerList().Where(a => a > 0).ToList();
                {
                    if (accountIds.Any())
                    {
                        qry = qry.Where(t => t.TransactionDetails.Any(d => accountIds.Contains(d.AccountId) || (d.Account.ParentAccountId.HasValue && accountIds.Contains(d.Account.ParentAccountId.Value))));
                    }
                }

                // Transaction Type
                int transactionTypeId = int.MinValue;
                if (int.TryParse(gfTransactions.GetUserPreference("Transaction Type"), out transactionTypeId))
                {
                    qry = qry.Where(t => t.TransactionTypeValueId == transactionTypeId);
                }

                // Currency Type
                int currencyTypeId = int.MinValue;
                if (int.TryParse(gfTransactions.GetUserPreference("Currency Type"), out currencyTypeId))
                {
                    qry = qry.Where(t => t.FinancialPaymentDetail != null && t.FinancialPaymentDetail.CurrencyTypeValueId == currencyTypeId);
                }

                // Credit Card Type
                int creditCardTypeId = int.MinValue;
                if (int.TryParse(gfTransactions.GetUserPreference("Credit Card Type"), out creditCardTypeId))
                {
                    qry = qry.Where(t => t.FinancialPaymentDetail != null && t.FinancialPaymentDetail.CreditCardTypeValueId == creditCardTypeId);
                }

                // Source Type
                int sourceTypeId = int.MinValue;
                if (int.TryParse(gfTransactions.GetUserPreference("Source Type"), out sourceTypeId))
                {
                    qry = qry.Where(t => t.SourceTypeValueId == sourceTypeId);
                }
            }

            SortProperty sortProperty = gTransactions.SortProperty;

            if (sortProperty != null)
            {
                if (sortProperty.Property == "TotalAmount")
                {
                    if (sortProperty.Direction == SortDirection.Ascending)
                    {
                        qry = qry.OrderBy(t => t.TransactionDetails.Sum(d => (decimal?)d.Amount) ?? 0.00M);
                    }
                    else
                    {
                        qry = qry.OrderByDescending(t => t.TransactionDetails.Sum(d => (decimal?)d.Amount) ?? 0.0M);
                    }
                }
                else
                {
                    qry = qry.Sort(sortProperty);
                }
            }
            else
            {
                // Default sort by Id if the transations are seen via the batch,
                // otherwise sort by descending date time.
                if (ContextTypesRequired.Any(e => e.Id == batchEntityTypeId))
                {
                    qry = qry.OrderBy(t => t.Id);
                }
                else
                {
                    qry = qry.OrderByDescending(t => t.TransactionDateTime).ThenByDescending(t => t.Id);
                }
            }

            gTransactions.SetLinqDataSource(qry.AsNoTracking());
            gTransactions.DataBind();

            if (_batch == null &&
                _scheduledTxn == null &&
                _registration == null &&
                _person == null)
            {
                pnlSummary.Visible = true;

                // No context - show account summary
                var qryTransactionDetails = qry.SelectMany(a => a.TransactionDetails);
                var accountSummaryQry     = qryTransactionDetails.GroupBy(a => a.Account).Select(a => new
                {
                    a.Key.Name,
                    a.Key.Order,
                    TotalAmount = (decimal?)a.Sum(d => d.Amount)
                }).OrderBy(a => a.Order);

                var    summaryList      = accountSummaryQry.ToList();
                var    grandTotalAmount = (summaryList.Count > 0) ? summaryList.Sum(a => a.TotalAmount ?? 0) : 0;
                string currencyFormat   = GlobalAttributesCache.Value("CurrencySymbol") + "{0:n}";
                lGrandTotal.Text             = string.Format(currencyFormat, grandTotalAmount);
                rptAccountSummary.DataSource = summaryList.Select(a => new { a.Name, TotalAmount = string.Format(currencyFormat, a.TotalAmount) }).ToList();
                rptAccountSummary.DataBind();
            }
            else
            {
                pnlSummary.Visible = false;
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            // If configured for a person and person is null, return
            int personEntityTypeId = EntityTypeCache.Read <Person>().Id;

            if (ContextTypesRequired.Any(e => e.Id == personEntityTypeId) && _person == null)
            {
                return;
            }

            var rockContext = new RockContext();

            var qryCommunications = new CommunicationService(rockContext).Queryable().Where(c => c.Status != CommunicationStatus.Transient);

            string subject = tbSubject.Text;

            if (!string.IsNullOrWhiteSpace(subject))
            {
                qryCommunications = qryCommunications.Where(c => c.Subject.Contains(subject));
            }

            Guid?entityTypeGuid = cpMedium.SelectedValue.AsGuidOrNull();

            if (entityTypeGuid.HasValue)
            {
                qryCommunications = qryCommunications.Where(c => c.MediumEntityType != null && c.MediumEntityType.Guid.Equals(entityTypeGuid.Value));
            }

            var communicationStatus = ddlStatus.SelectedValue.ConvertToEnumOrNull <CommunicationStatus>();

            if (communicationStatus.HasValue)
            {
                qryCommunications = qryCommunications.Where(c => c.Status == communicationStatus.Value);
            }

            // only communications for the selected recipient (_person)
            if (_person != null)
            {
                qryCommunications = qryCommunications.Where(c => c.Recipients.Any(a => a.PersonAlias.PersonId == _person.Id));
            }

            if (drpDates.LowerValue.HasValue)
            {
                qryCommunications = qryCommunications.Where(a => a.CreatedDateTime >= drpDates.LowerValue.Value);
            }

            if (drpDates.UpperValue.HasValue)
            {
                DateTime upperDate = drpDates.UpperValue.Value.Date.AddDays(1);
                qryCommunications = qryCommunications.Where(a => a.CreatedDateTime < upperDate);
            }

            string content = tbContent.Text;

            if (!string.IsNullOrWhiteSpace(content))
            {
                qryCommunications = qryCommunications.Where(c => c.MediumDataJson.Contains(content));
            }

            var sortProperty = gCommunication.SortProperty;

            if (sortProperty != null)
            {
                qryCommunications = qryCommunications.Sort(sortProperty);
            }
            else
            {
                qryCommunications = qryCommunications.OrderByDescending(c => c.CreatedDateTime);
            }

            gCommunication.EntityTypeId = EntityTypeCache.Read <Rock.Model.Communication>().Id;
            gCommunication.SetLinqDataSource(qryCommunications.Include(a => a.MediumEntityType).AsNoTracking());
            gCommunication.DataBind();
        }
Esempio n. 10
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            _currencyTypes   = new Dictionary <int, string>();
            _creditCardTypes = new Dictionary <int, string>();

            // If configured for a person and person is null, return
            int personEntityTypeId = EntityTypeCache.Read("Rock.Model.Person").Id;

            if (ContextTypesRequired.Any(e => e.Id == personEntityTypeId) && _person == null)
            {
                return;
            }

            // If configured for a batch and batch is null, return
            int batchEntityTypeId = EntityTypeCache.Read("Rock.Model.FinancialBatch").Id;

            if (ContextTypesRequired.Any(e => e.Id == batchEntityTypeId) && _batch == null)
            {
                return;
            }

            // If configured for a batch and batch is null, return
            int scheduledTxnEntityTypeId = EntityTypeCache.Read("Rock.Model.FinancialScheduledTransaction").Id;

            if (ContextTypesRequired.Any(e => e.Id == scheduledTxnEntityTypeId) && _scheduledTxn == null)
            {
                return;
            }

            // Qry
            var qry = new FinancialTransactionService(new RockContext())
                      .Queryable("AuthorizedPersonAlias.Person,ProcessedByPersonAlias.Person");

            // Set up the selection filter
            if (_batch != null)
            {
                // If transactions are for a batch, the filter is hidden so only check the batch id
                qry = qry.Where(t => t.BatchId.HasValue && t.BatchId.Value == _batch.Id);

                // If the batch is closed, do not allow any editing of the transactions
                if (_batch.Status != BatchStatus.Closed && _canEdit)
                {
                    gTransactions.IsDeleteEnabled = true;
                }
                else
                {
                    gTransactions.IsDeleteEnabled = false;
                }
            }
            else if (_scheduledTxn != null)
            {
                // If transactions are for a batch, the filter is hidden so only check the batch id
                qry = qry.Where(t => t.ScheduledTransactionId.HasValue && t.ScheduledTransactionId.Value == _scheduledTxn.Id);

                gTransactions.IsDeleteEnabled = false;
            }
            else    // Person
            {
                // otherwise set the selection based on filter settings
                if (_person != null)
                {
                    qry = qry.Where(t => t.AuthorizedPersonAlias.PersonId == _person.Id);
                }

                // Date Range
                var drp = new DateRangePicker();
                drp.DelimitedValues = gfTransactions.GetUserPreference("Date Range");
                if (drp.LowerValue.HasValue)
                {
                    qry = qry.Where(t => t.TransactionDateTime >= drp.LowerValue.Value);
                }

                if (drp.UpperValue.HasValue)
                {
                    DateTime upperDate = drp.UpperValue.Value.Date.AddDays(1);
                    qry = qry.Where(t => t.TransactionDateTime < upperDate);
                }



                // Amount Range
                var nre = new NumberRangeEditor();
                nre.DelimitedValues = gfTransactions.GetUserPreference("Amount Range");
                if (nre.LowerValue.HasValue)
                {
                    qry = qry.Where(t => t.TransactionDetails.Sum(d => d.Amount) >= nre.LowerValue.Value);
                }

                if (nre.UpperValue.HasValue)
                {
                    qry = qry.Where(t => t.TransactionDetails.Sum(d => d.Amount) <= nre.UpperValue.Value);
                }

                // Transaction Code
                string transactionCode = gfTransactions.GetUserPreference("Transaction Code");
                if (!string.IsNullOrWhiteSpace(transactionCode))
                {
                    qry = qry.Where(t => t.TransactionCode == transactionCode.Trim());
                }

                // Account Id
                int accountId = int.MinValue;
                if (int.TryParse(gfTransactions.GetUserPreference("Account"), out accountId))
                {
                    qry = qry.Where(t => t.TransactionDetails.Any(d => d.AccountId == accountId));
                }

                // Transaction Type
                int transactionTypeId = int.MinValue;
                if (int.TryParse(gfTransactions.GetUserPreference("Transaction Type"), out transactionTypeId))
                {
                    qry = qry.Where(t => t.TransactionTypeValueId == transactionTypeId);
                }

                // Currency Type
                int currencyTypeId = int.MinValue;
                if (int.TryParse(gfTransactions.GetUserPreference("Currency Type"), out currencyTypeId))
                {
                    qry = qry.Where(t => t.CurrencyTypeValueId == currencyTypeId);
                }

                // Credit Card Type
                int creditCardTypeId = int.MinValue;
                if (int.TryParse(gfTransactions.GetUserPreference("Credit Card Type"), out creditCardTypeId))
                {
                    qry = qry.Where(t => t.CreditCardTypeValueId == creditCardTypeId);
                }

                // Source Type
                int sourceTypeId = int.MinValue;
                if (int.TryParse(gfTransactions.GetUserPreference("Source Type"), out sourceTypeId))
                {
                    qry = qry.Where(t => t.SourceTypeValueId == sourceTypeId);
                }
            }

            SortProperty sortProperty = gTransactions.SortProperty;

            if (sortProperty != null)
            {
                if (sortProperty.Property == "TotalAmount")
                {
                    if (sortProperty.Direction == SortDirection.Ascending)
                    {
                        qry = qry.OrderBy(t => t.TransactionDetails.Sum(d => (decimal?)d.Amount) ?? 0.00M);
                    }
                    else
                    {
                        qry = qry.OrderByDescending(t => t.TransactionDetails.Sum(d => (decimal?)d.Amount) ?? 0.0M);
                    }
                }
                else
                {
                    qry = qry.Sort(sortProperty);
                }
            }
            else
            {
                // Default sort by Id if the transations are seen via the batch,
                // otherwise sort by descending date time.
                if (ContextTypesRequired.Any(e => e.Id == batchEntityTypeId))
                {
                    qry = qry.OrderBy(t => t.Id);
                }
                else
                {
                    qry = qry.OrderByDescending(t => t.TransactionDateTime).ThenByDescending(t => t.Id);
                }
            }

            // Row Limit
            int?rowLimit = gfTransactions.GetUserPreference("Row Limit").AsIntegerOrNull();

            if (rowLimit.HasValue)
            {
                qry = qry.Take(rowLimit.Value);
            }

            gTransactions.DataSource = qry.AsNoTracking().ToList();
            gTransactions.DataBind();
        }
Esempio n. 11
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            // Find all the Group Types
            var groupTypeIds = GetAvailableGroupTypes();

            if (GetAttributeValue("DisplayFilter").AsBooleanOrNull() ?? false)
            {
                int?groupTypeFilter = gfSettings.GetUserPreference("Group Type").AsIntegerOrNull();
                if (groupTypeFilter.HasValue)
                {
                    groupTypeIds = groupTypeIds.Where(g => g == groupTypeFilter.Value).ToList();
                }
            }

            var rockContext = new RockContext();

            SortProperty sortProperty = gGroups.SortProperty;

            if (sortProperty == null)
            {
                sortProperty = new SortProperty(new GridViewSortEventArgs("GroupTypeOrder, GroupTypeName, GroupOrder, Name", SortDirection.Ascending));
            }

            bool onlySecurityGroups = GetAttributeValue("LimittoSecurityRoleGroups").AsBoolean();

            var qryGroups = new GroupService(rockContext).Queryable().Where(g => groupTypeIds.Contains(g.GroupTypeId) && (!onlySecurityGroups || g.IsSecurityRole));

            string limitToActiveStatus = GetAttributeValue("LimittoActiveStatus");

            if (limitToActiveStatus == "all" && gfSettings.Visible)
            {
                // Filter by active/inactive unless the block settings restrict it
                if (ddlActiveFilter.SelectedIndex > -1)
                {
                    if (ddlActiveFilter.SelectedValue == "inactive")
                    {
                        qryGroups = qryGroups.Where(a => a.IsActive == false);
                    }
                    else if (ddlActiveFilter.SelectedValue == "active")
                    {
                        qryGroups = qryGroups.Where(a => a.IsActive == true);
                    }
                }
            }
            else if (limitToActiveStatus != "all")
            {
                // filter by the block settinf for Active Status
                if (limitToActiveStatus == "inactive")
                {
                    qryGroups = qryGroups.Where(a => a.IsActive == false);
                }
                else if (limitToActiveStatus == "active")
                {
                    qryGroups = qryGroups.Where(a => a.IsActive == true);
                }
            }

            // Person context will exist if used on a person detail page
            int personEntityTypeId = EntityTypeCache.Read("Rock.Model.Person").Id;

            if (ContextTypesRequired.Any(e => e.Id == personEntityTypeId))
            {
                var personContext = ContextEntity <Person>();
                if (personContext != null)
                {
                    // limit to Groups that the person is a member of
                    var qry = new GroupMemberService(rockContext).Queryable(true)
                              .Where(m => m.PersonId == personContext.Id)
                              .Join(qryGroups, gm => gm.GroupId, g => g.Id, (gm, g) => new { Group = g, GroupMember = gm });

                    gGroups.DataSource = qry
                                         .Select(m => new
                    {
                        Id             = m.Group.Id,
                        Name           = m.Group.Name,
                        GroupTypeName  = m.Group.GroupType.Name,
                        GroupOrder     = m.Group.Order,
                        GroupTypeOrder = m.Group.GroupType.Order,
                        Description    = m.Group.Description,
                        IsSystem       = m.Group.IsSystem,
                        GroupRole      = m.GroupMember.GroupRole.Name,
                        DateAdded      = m.GroupMember.CreatedDateTime,
                        IsActive       = m.Group.IsActive,
                        MemberCount    = 0
                    })
                                         .Sort(sortProperty)
                                         .ToList();
                }
            }
            else
            {
                var  roleGroupType   = GroupTypeCache.Read(Rock.SystemGuid.GroupType.GROUPTYPE_SECURITY_ROLE.AsGuid());
                int  roleGroupTypeId = roleGroupType != null ? roleGroupType.Id : 0;
                bool useRolePrefix   = onlySecurityGroups || groupTypeIds.Contains(roleGroupTypeId);

                gGroups.DataSource = qryGroups.Select(g => new
                {
                    Id             = g.Id,
                    Name           = ((useRolePrefix && g.GroupType.Id != roleGroupTypeId) ? "GROUP - " : "") + g.Name,
                    GroupTypeName  = g.GroupType.Name,
                    GroupOrder     = g.Order,
                    GroupTypeOrder = g.GroupType.Order,
                    Description    = g.Description,
                    IsSystem       = g.IsSystem,
                    IsActive       = g.IsActive,
                    GroupRole      = string.Empty,
                    DateAdded      = DateTime.MinValue,
                    MemberCount    = g.Members.Count()
                })
                                     .Sort(sortProperty)
                                     .ToList();
            }

            gGroups.DataBind();

            // hide the group type column if there's only one type; must come after DataBind()
            if (_groupTypesCount == 1)
            {
                this.gGroups.Columns[1].Visible = false;
            }
        }