Exemple #1
0
        public override void PreSaveChanges(Rock.Data.DbContext dbContext, EntityState state)
        {
            base.PreSaveChanges(dbContext, state);
            base.PostSaveChanges(dbContext);

            var entityTypeCache = EntityTypeCache.Get(EntityTypeId);
            var entityType      = entityTypeCache.GetEntityType();
            var entityService   = Reflection.GetServiceForEntityType(entityType, dbContext);

            System.Reflection.MethodInfo getMethod = entityService.GetType().GetMethod("Get", new Type[] { typeof(int) });
            var mergeObjectEntity = getMethod.Invoke(entityService, new object[] { EntityId }) as Rock.Data.IEntity;

            this.Name = mergeObjectEntity != null?mergeObjectEntity.ToString() : "Unknown Entity";

            //If this is a family group save the head of household in case of family merge
            if (FamilyGroupOfPersonAliasId == null &&
                mergeObjectEntity != null &&
                mergeObjectEntity is Group &&
                (( Group )mergeObjectEntity).GroupTypeId == GroupTypeCache.GetId(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid())
                )
            {
                var headOfHousehold = GroupServiceExtensions.HeadOfHousehold((( Group )mergeObjectEntity).Members.AsQueryable());
                if (headOfHousehold != null)
                {
                    FamilyGroupOfPersonAliasId = headOfHousehold.PrimaryAliasId;
                }
            }
        }
        /// <summary>
        /// Gets the campuses.
        /// </summary>
        /// <returns></returns>
        private List <CampusCache> GetCampuses()
        {
            var campuses                = new List <CampusCache>();
            var allowedCampuses         = GetAttributeValue(AttributeKey.Campuses).SplitDelimitedValues().AsGuidList();
            var limitCampusByCampusTeam = GetAttributeValue(AttributeKey.LimitCampusByCampusTeam).AsBoolean();
            var selectedCampusTypes     = GetAttributeValue(AttributeKey.CampusTypes).SplitDelimitedValues().AsGuidList();
            var selectedCampusStatuses  = GetAttributeValue(AttributeKey.CampusStatus).SplitDelimitedValues().AsGuidList();

            var campusQuery = CampusCache.All().Where(c => c.IsActive.HasValue && c.IsActive.Value);

            // If specific campuses are selected, filter by those campuses.
            if (allowedCampuses.Any())
            {
                campusQuery = campusQuery.Where(c => allowedCampuses.Contains(c.Guid));
            }

            if (limitCampusByCampusTeam)
            {
                var campusTeamGroupTypeId = GroupTypeCache.GetId(Rock.SystemGuid.GroupType.GROUPTYPE_CAMPUS_TEAM.AsGuid());
                var teamGroupIds          = new GroupService(new RockContext()).Queryable().AsNoTracking()
                                            .Where(g => g.GroupTypeId == campusTeamGroupTypeId)
                                            .Where(g => g.Members.Where(gm => gm.PersonId == CurrentPersonId).Any())
                                            .Select(g => g.Id).ToList();

                campusQuery = campusQuery.Where(c => c.TeamGroupId.HasValue && teamGroupIds.Contains(c.TeamGroupId.Value));
            }

            // If campus types are selected, filter by those.
            if (selectedCampusTypes.Any())
            {
                var campusTypes = DefinedValueCache.All().Where(d => selectedCampusTypes.Contains(d.Guid)).Select(d => d.Id).ToList();
                campusQuery = campusQuery.Where(c => c.CampusTypeValueId.HasValue && campusTypes.Contains(c.CampusTypeValueId.Value));
            }

            // If campus statuses are selected, filter by those.
            if (selectedCampusStatuses.Any())
            {
                var campusStatuses = DefinedValueCache.All().Where(d => selectedCampusStatuses.Contains(d.Guid)).Select(d => d.Id).ToList();
                campusQuery = campusQuery.Where(c => c.CampusStatusValueId.HasValue && campusStatuses.Contains(c.CampusStatusValueId.Value));
            }

            // Sort by name.
            campusQuery = campusQuery.OrderBy(c => c.Name);

            foreach (var campus in campusQuery)
            {
                campuses.Add(campus);
            }

            return(campuses);
        }
Exemple #3
0
        /// <summary>
        /// Method that will be called on an entity immediately before the item is saved by context
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="state">The state of the entity.</param>
        public override void PreSaveChanges(Data.DbContext dbContext, EntityState state)
        {
            var rockContext = ( RockContext )dbContext;

            /*
             * 1/15/2020 - JPH
             * Upon saving a Campus, ensure it has a TeamGroup defined (GroupType = 'Team Group',
             * IsSystem = true). We are creating this Campus-to-Group relationship behind the scenes
             * so that we can assign GroupRoles to a Campus, and place people into those roles.
             *
             * Reason: Campus Team Feature
             */
            var campusTeamGroupTypeId = GroupTypeCache.GetId(Rock.SystemGuid.GroupType.GROUPTYPE_CAMPUS_TEAM.AsGuid());

            if (state != EntityState.Deleted && campusTeamGroupTypeId.HasValue)
            {
                if (this.TeamGroup == null || this.TeamGroup.GroupTypeId != campusTeamGroupTypeId.Value)
                {
                    // this Campus does not yet have a Group of the correct GroupType: create one and assign it
                    var teamGroup = new Group
                    {
                        IsSystem    = true,
                        GroupTypeId = campusTeamGroupTypeId.Value,
                        Name        = string.Format("{0} Team", this.Name),
                        Description = "Are responsible for leading and administering the Campus."
                    };

                    new GroupService(rockContext).Add(teamGroup);

                    this.TeamGroup = teamGroup;
                }

                if (!this.TeamGroup.IsSystem)
                {
                    // this Campus already had a Group of the correct GroupType, but the IsSystem value was incorrect
                    this.TeamGroup.IsSystem = true;
                }
            }

            base.PreSaveChanges(dbContext, state);
        }
        /// <summary>
        /// Updates the configuration from block settings.
        /// </summary>
        private void UpdateConfigurationFromBlockSettings()
        {
            var configuredCheckinTypeGuid = this.GetAttributeValue(AttributeKey.CheckinConfiguration_GroupTypeGuid).AsGuid();

            var configuredCheckinTypeId = GroupTypeCache.GetId(configuredCheckinTypeGuid);

            LocalDeviceConfig.CurrentCheckinTypeId = configuredCheckinTypeId;
            LocalDeviceConfig.CurrentGroupTypeIds  = this.GetAttributeValue(AttributeKey.ConfiguredAreas_GroupTypeIds).SplitDelimitedValues().AsIntegerList();

            LocalDeviceConfig.CurrentTheme = this.GetAttributeValue(AttributeKey.CheckinTheme);

            // override the HomePage block setting to the mobile home page
            LocalDeviceConfig.HomePageOverride = this.PageCache.Guid;
            LocalDeviceConfig.BlockedPageIds   = null;

            LocalDeviceConfig.AllowCheckout = false;

            var blockedPageIds = new List <int?>();

            blockedPageIds.Add(PageCache.GetId(Rock.SystemGuid.Page.CHECKIN_ADMIN.AsGuid()));
            blockedPageIds.Add(PageCache.GetId(Rock.SystemGuid.Page.CHECKIN_WELCOME.AsGuid()));
            blockedPageIds.Add(PageCache.GetId(Rock.SystemGuid.Page.CHECKIN_SEARCH.AsGuid()));
            blockedPageIds.Add(PageCache.GetId(Rock.SystemGuid.Page.CHECKIN_FAMILY_SELECT.AsGuid()));

            LocalDeviceConfig.BlockedPageIds = blockedPageIds.Where(a => a.HasValue).Select(a => a.Value).ToArray();

            // turn off the idle redirect blocks since we don't a person's mobile device to do that
            LocalDeviceConfig.DisableIdleRedirect = true;

            // we want the SuccessBlock to generate a QR Code that contains the AttendanceSession(s)
            LocalDeviceConfig.GenerateQRCodeForAttendanceSessions = true;

            LocalDeviceConfig.SaveToCookie(this.Page);

            // create new checkin state since we are starting a new checkin sessions
            this.CurrentCheckInState = new CheckInState(this.LocalDeviceConfig);
            SaveState();
        }
Exemple #5
0
        private static List <BreakoutGroupItem> GetBreakoutGroupItems(Person person)
        {
            List <BreakoutGroupItem> allBreakoutGroupItems = RockCache.Get(cacheKey) as List <BreakoutGroupItem>;

            if (allBreakoutGroupItems == null || !allBreakoutGroupItems.Any())
            {
                allBreakoutGroupItems = new List <BreakoutGroupItem>();
                RockContext rockContext = new RockContext();

                var attributeService      = new AttributeService(rockContext);
                var attributeValueService = new AttributeValueService(rockContext);

                var groupEntityTypeId        = EntityTypeCache.GetId(typeof(Rock.Model.Group));
                var breakoutGroupGroupTypeId = GroupTypeCache.GetId(Constants.GROUP_TYPE_BREAKOUT_GROUPS.AsGuid());

                if (groupEntityTypeId == null || breakoutGroupGroupTypeId == null)
                {
                    ExceptionLogService.LogException(new Exception("Could not load breakout groups due to missing breakoutgroup type"));
                    return(new List <BreakoutGroupItem>());
                }

                var letterAttribute = attributeService.GetByEntityTypeQualifier(groupEntityTypeId, "GroupTypeId", breakoutGroupGroupTypeId.Value.ToString(), false)
                                      .Where(a => a.Key == Constants.GROUP_ATTRIBUTE_KEY_LETTER)
                                      .FirstOrDefault();

                if (letterAttribute == null)
                {
                    ExceptionLogService.LogException(new Exception("Could not load breakout group letter attribute."));
                    return(new List <BreakoutGroupItem>());
                }

                var attributeQueryable = attributeValueService.Queryable().AsNoTracking()
                                         .Where(av => letterAttribute.Id == av.AttributeId);

                //Get all the data in one go
                var breakoutData = new GroupService(rockContext)
                                   .Queryable()
                                   .AsNoTracking()
                                   .Where(g => g.GroupTypeId == breakoutGroupGroupTypeId && g.IsActive && !g.IsArchived)
                                   .Join(attributeQueryable,
                                         g => g.Id,
                                         av => av.EntityId,
                                         (g, av) => new
                {
                    ScheduleId = g.ScheduleId ?? 0,
                    PersonIds  = g.Members.Where(gm => gm.IsArchived == false && gm.GroupMemberStatus == GroupMemberStatus.Active).Select(gm => gm.PersonId),
                    Letter     = av.Value
                })
                                   .ToList();

                foreach (var item in breakoutData)
                {
                    foreach (var personId in item.PersonIds)
                    {
                        allBreakoutGroupItems.Add(new BreakoutGroupItem
                        {
                            Letter     = item.Letter,
                            PersonId   = personId,
                            ScheduleId = item.ScheduleId
                        });
                    }
                }

                RockCache.AddOrUpdate(cacheKey, null, allBreakoutGroupItems, RockDateTime.Now.AddMinutes(10), Constants.CACHE_TAG);
            }

            return(allBreakoutGroupItems.Where(i => i.PersonId == person.Id).ToList());
        }