コード例 #1
0
        /// <summary>
        /// Does a direct Bulk Delete of group history for all groups and group members of the specified group type and commits the changes to the database.
        /// </summary>
        /// <param name="groupTypeId">The group type identifier.</param>
        public void BulkDeleteGroupHistory(int groupTypeId)
        {
            var rockContext = this.Context as RockContext;
            var groupHistoryRecordsToDelete       = new GroupHistoricalService(rockContext).Queryable().Where(a => a.GroupTypeId == groupTypeId);
            var groupMemberHistoryRecordsToDelete = new GroupMemberHistoricalService(rockContext).Queryable().Where(a => a.Group.GroupTypeId == groupTypeId);

            rockContext.BulkDelete(groupHistoryRecordsToDelete);
            rockContext.BulkDelete(groupMemberHistoryRecordsToDelete);
        }
コード例 #2
0
        /// <summary>
        /// Gets the group historical summary of the groupMemberHistoricalQuery
        /// </summary>
        /// <param name="groupMemberHistoricalQuery">The group member historical query.</param>
        /// <returns></returns>
        public List <GroupHistoricalSummary> GetGroupHistoricalSummary(IQueryable <GroupMemberHistorical> groupMemberHistoricalQuery)
        {
            var rockContext = this.Context as RockContext;

            // only fetch the groupMemberHistorical records where they were not archived and not Inactive (only fetch Active or Pending)
            // Also, IsArchive is redundant since they know the StartStop times of when they were in the group
            var groupMemberHistoricalByGroupList = groupMemberHistoricalQuery
                                                   .Where(a => a.IsArchived == false && a.GroupMemberStatus != GroupMemberStatus.Inactive)
                                                   .Select(a => new { a.Group, GroupMemberHistorical = a, a.EffectiveDateTime, GroupMemberDateTimeAdded = a.GroupMember.DateTimeAdded })
                                                   .GroupBy(a => a.Group).ToList();

            var groupNameHistoryLookup = new GroupHistoricalService(rockContext).Queryable()
                                         .Where(a => groupMemberHistoricalQuery.Any(x => x.GroupId == a.GroupId))
                                         .Select(a => new GroupNameHistory
            {
                GroupId           = a.GroupId,
                EffectiveDateTime = a.EffectiveDateTime,
                ExpireDateTime    = a.ExpireDateTime,
                GroupName         = a.GroupName,
            }).GroupBy(a => a.GroupId).ToDictionary(k => k.Key, v => v.ToList());

            var groupMemberHistoricalStartStopHistory = groupMemberHistoricalByGroupList
                                                        .Select(a =>
            {
                var startStopHistoryList = a.OrderBy(x => x.EffectiveDateTime)
                                           .Select(x => new GroupMemberHistoricalSummary(a.Key, x.GroupMemberHistorical, x.GroupMemberDateTimeAdded)).ToList();

                var groupNameHistory = groupNameHistoryLookup.GetValueOrNull(a.Key.Id).ToList();

                // let the first HistoryRecord know that its the first record so it can be smart about reporting StartDateTime
                var firstStopStopHistory = startStopHistoryList.FirstOrDefault();
                if (firstStopStopHistory != null)
                {
                    firstStopStopHistory.IsFirstTimeInGroup = true;
                }

                startStopHistoryList.ForEach(x => x._groupNameHistory = groupNameHistory);

                var groupHistorySummary = new GroupHistoricalSummary
                {
                    Group            = a.Key,
                    StartStopHistory = startStopHistoryList
                };

                return(groupHistorySummary);
            }).OrderBy(a => a.Group.Id);

            return(groupMemberHistoricalStartStopHistory.ToList());
        }