/// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="eventId">The event identifier.</param>
        public void ShowDetail( int eventId )
        {
            FollowingSuggestionType followingSuggestion = null;

            bool editAllowed = IsUserAuthorized( Authorization.EDIT );

            if ( !eventId.Equals( 0 ) )
            {
                followingSuggestion = new FollowingSuggestionTypeService( new RockContext() ).Get( eventId );
                editAllowed = editAllowed || followingSuggestion.IsAuthorized( Authorization.EDIT, CurrentPerson );
            }

            if ( followingSuggestion == null )
            {
                followingSuggestion = new FollowingSuggestionType { Id = 0, IsActive = true };
            }

            SuggestionId = followingSuggestion.Id;

            bool readOnly = false;

            nbEditModeMessage.Text = string.Empty;
            if ( !editAllowed || !IsUserAuthorized( Authorization.EDIT ) )
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( FollowingSuggestionType.FriendlyTypeName );
            }

            if ( readOnly )
            {
                ShowReadonlyDetails( followingSuggestion );
            }
            else
            {
                ShowEditDetails( followingSuggestion );
            }
        }
Пример #2
0
        /// <summary>
        /// Handles the Click event of the btnSave 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 btnSave_Click(object sender, EventArgs e)
        {
            using (var rockContext = new RockContext())
            {
                FollowingSuggestionType followingSuggestion = null;

                var eventService = new Rock.Model.FollowingSuggestionTypeService(rockContext);

                if (SuggestionId != 0)
                {
                    followingSuggestion = eventService.Get(SuggestionId);
                }

                if (followingSuggestion == null)
                {
                    followingSuggestion = new Rock.Model.FollowingSuggestionType();
                    eventService.Add(followingSuggestion);
                }

                followingSuggestion.Name         = tbName.Text;
                followingSuggestion.IsActive     = cbIsActive.Checked;
                followingSuggestion.Description  = tbDescription.Text;
                followingSuggestion.EntityTypeId = cpSuggestionType.SelectedEntityTypeId;
                followingSuggestion.ReasonNote   = tbReasonNote.Text;
                followingSuggestion.ReminderDays = nbReminderDays.Text.AsIntegerOrNull();
                followingSuggestion.EntityNotificationFormatLava = ceNotificationFormat.Text;

                rockContext.SaveChanges();

                followingSuggestion.LoadAttributes(rockContext);
                Rock.Attribute.Helper.GetEditValues(phAttributes, followingSuggestion);
                followingSuggestion.SaveAttributeValues(rockContext);
            }

            NavigateToParentPage();
        }
Пример #3
0
        /// <summary>
        /// Formats the entity notification.
        /// </summary>
        /// <param name="followingSuggestionType">Type of the following suggestion.</param>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public virtual string FormatEntityNotification( FollowingSuggestionType followingSuggestionType, IEntity entity )
        {
            if ( followingSuggestionType != null )
            {
                var mergeFields = new Dictionary<string, object>();
                mergeFields.Add( "Entity", entity );
                return followingSuggestionType.EntityNotificationFormatLava.ResolveMergeFields( mergeFields );
            }

            return string.Empty;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="FollowingSuggestionNotices"/> class.
 /// </summary>
 /// <param name="suggestionType">Type of the suggestion.</param>
 /// <param name="notices">The notices.</param>
 public FollowingSuggestionNotices(FollowingSuggestionType suggestionType, List <string> notices)
 {
     SuggestionType = suggestionType;
     Notices        = notices;
 }
Пример #5
0
 /// <summary>
 /// Loads the attributes for the following suggestion.
 /// </summary>
 /// <param name="followingSuggestion">The following suggestion.</param>
 public void LoadAttributes(FollowingSuggestionType followingSuggestion)
 {
     followingSuggestion.LoadAttributes();
 }
Пример #6
0
 /// <summary>
 /// Gets the suggestions.
 /// </summary>
 /// <param name="followingSuggestionType">Type of the following suggestion.</param>
 /// <param name="FollowerPersonIds">The follower person ids.</param>
 /// <returns></returns>
 public abstract List <PersonEntitySuggestion> GetSuggestions(FollowingSuggestionType followingSuggestionType, List <int> FollowerPersonIds);
Пример #7
0
 public SuggestionTypeComponent(FollowingSuggestionType followingSuggestionType)
 {
     FollowingSuggestionType = followingSuggestionType;
 }
        protected override void LoadViewState( object savedState )
        {
            base.LoadViewState( savedState );

            SuggestionId = ViewState["SuggestionId"] as int? ?? 0;
            SuggestionEntityTypeId = ViewState["SuggestionEntityTypeId"] as int?;

            var followingSuggestion = new FollowingSuggestionType { Id = SuggestionId, EntityTypeId = SuggestionEntityTypeId };
            BuildDynamicControls( followingSuggestion, false );
        }
Пример #9
0
        /// <summary>
        /// Gets the attribute value for the suggestion 
        /// </summary>
        /// <param name="followingSuggestion">The following suggestion.</param>
        /// <param name="key">The key.</param>
        /// <returns></returns>
        protected string GetAttributeValue( FollowingSuggestionType followingSuggestion, string key )
        {
            if ( followingSuggestion.AttributeValues == null )
            {
                followingSuggestion.LoadAttributes();
            }

            var values = followingSuggestion.AttributeValues;
            if ( values != null && values.ContainsKey( key ) )
            {
                var keyValues = values[key];
                if ( keyValues != null )
                {
                    return keyValues.Value;
                }
            }

            return string.Empty;
        }
Пример #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FollowingSuggestionNotices"/> class.
 /// </summary>
 /// <param name="suggestionType">Type of the suggestion.</param>
 /// <param name="notices">The notices.</param>
 public FollowingSuggestionNotices( FollowingSuggestionType suggestionType, List<string> notices )
 {
     SuggestionType = suggestionType;
     Notices = notices;
 }
Пример #11
0
        /// <summary>
        /// Shows the readonly details.
        /// </summary>
        /// <param name="event">The event.</param>
        private void ShowReadonlyDetails( FollowingSuggestionType followingSuggestion )
        {
            SetEditMode( false );

            lActionTitle.Text = followingSuggestion.Name.FormatAsHtmlTitle();
            hlInactive.Visible = !followingSuggestion.IsActive;
            lSuggestionDescription.Text = followingSuggestion.Description;

            DescriptionList descriptionList = new DescriptionList();

            if ( followingSuggestion.EntityType != null )
            {
                descriptionList.Add( "Suggestion Type", followingSuggestion.EntityType.Name );
            }

            descriptionList.Add( "Reason Note", followingSuggestion.ReasonNote );

            lblMainDetails.Text = descriptionList.Html;
        }
Пример #12
0
        /// <summary>
        /// Shows the edit details.
        /// </summary>
        /// <param name="event">The event.</param>
        private void ShowEditDetails( FollowingSuggestionType followingSuggestion )
        {
            if ( followingSuggestion.Id == 0 )
            {
                lActionTitle.Text = ActionTitle.Add( FollowingSuggestionType.FriendlyTypeName ).FormatAsHtmlTitle();
            }
            else
            {
                lActionTitle.Text = followingSuggestion.Name.FormatAsHtmlTitle();
            }

            hlInactive.Visible = !followingSuggestion.IsActive;

            SetEditMode( true );

            tbName.Text = followingSuggestion.Name;
            cbIsActive.Checked = followingSuggestion.IsActive;
            tbDescription.Text = followingSuggestion.Description;
            cpSuggestionType.SetValue( followingSuggestion.EntityType != null ? followingSuggestion.EntityType.Guid.ToString().ToUpper() : string.Empty );
            tbReasonNote.Text = followingSuggestion.ReasonNote;
            nbReminderDays.Text = followingSuggestion.ReminderDays.HasValue ? followingSuggestion.ReminderDays.Value.ToString() : "";
            ceNotificationFormat.Text = followingSuggestion.EntityNotificationFormatLava;

            BuildDynamicControls( followingSuggestion, true );
        }
Пример #13
0
        private void BuildDynamicControls( FollowingSuggestionType followingSuggestion, bool SetValues )
        {
            if ( SetValues )
            {
                SuggestionEntityTypeId = followingSuggestion.EntityTypeId;
                if ( followingSuggestion.EntityTypeId.HasValue )
                {
                    var SuggestionComponentEntityType = EntityTypeCache.Read( followingSuggestion.EntityTypeId.Value );
                    var SuggestionEntityType = EntityTypeCache.Read( "Rock.Model.FollowingSuggestionType" );
                    if ( SuggestionComponentEntityType != null && SuggestionEntityType != null )
                    {
                        using ( var rockContext = new RockContext() )
                        {
                            Rock.Attribute.Helper.UpdateAttributes( SuggestionComponentEntityType.GetEntityType(), SuggestionEntityType.Id, "EntityTypeId", SuggestionComponentEntityType.Id.ToString(), rockContext );
                        }
                    }
                }
            }

            if ( followingSuggestion.Attributes == null )
            {
                followingSuggestion.LoadAttributes();
            }

            phAttributes.Controls.Clear();
            Rock.Attribute.Helper.AddEditControls( followingSuggestion, phAttributes, SetValues, BlockValidationGroup, new List<string> { "Active", "Order" } );
        }
Пример #14
0
 /// <summary>
 /// Gets the suggestions.
 /// </summary>
 /// <param name="followingSuggestionType">Type of the following suggestion.</param>
 /// <param name="FollowerPersonIds">The follower person ids.</param>
 /// <returns></returns>
 public abstract List<PersonEntitySuggestion> GetSuggestions( FollowingSuggestionType followingSuggestionType, List<int> FollowerPersonIds );
Пример #15
0
        /// <summary>
        /// Gets the suggestions.
        /// </summary>
        /// <param name="followingSuggestionType">Type of the following suggestion.</param>
        /// <param name="followerPersonIds">The follower person ids.</param>
        /// <returns></returns>
        public override List <PersonEntitySuggestion> GetSuggestions(FollowingSuggestionType followingSuggestionType, List <int> followerPersonIds)
        {
            var  suggestions           = new List <PersonEntitySuggestion>();
            var  groupEntityType       = EntityTypeCache.Get(typeof(Rock.Model.Group));
            var  personAliasEntityType = EntityTypeCache.Get(typeof(Rock.Model.PersonAlias));
            bool isAutoFollow          = GetAttributeValue(followingSuggestionType, "AutoFollow").AsBoolean();

            // Get the grouptype guid
            Guid?groupTypeGuid = GetAttributeValue(followingSuggestionType, "GroupType").AsGuidOrNull();

            if (groupTypeGuid.HasValue)
            {
                using (var rockContext = new RockContext())
                {
                    var followingService   = new FollowingService(rockContext);
                    var groupMemberService = new GroupMemberService(rockContext);
                    var personAliasService = new PersonAliasService(rockContext);

                    var followings = followingService.Queryable()
                                     .Where(a => a.EntityTypeId == groupEntityType.Id &&
                                            followerPersonIds.Contains(a.PersonAlias.PersonId))
                                     .Select(f => new
                    {
                        f.PersonAliasId,
                        f.PersonAlias.PersonId,
                        f.EntityId
                    }).Distinct()
                                     .ToList();

                    var followedGroup = followings.Select(a => a.EntityId).Distinct().ToList();
                    // Get all the groupmember records of Followed group
                    var followedGroupMembersQry = groupMemberService.Queryable().AsNoTracking()
                                                  .Where(m =>
                                                         m.GroupMemberStatus == GroupMemberStatus.Active &&
                                                         m.Group != null &&
                                                         m.Group.IsActive && !m.Group.IsArchived &&
                                                         m.Group.GroupType.Guid.Equals(groupTypeGuid.Value) &&
                                                         followedGroup.Contains(m.GroupId));


                    // If a specific role for the people being followed was specified, limit the query to only those with the selected role
                    Guid?groupRoleGuid = GetAttributeValue(followingSuggestionType, "GroupRole").AsGuidOrNull();
                    if (groupRoleGuid.HasValue)
                    {
                        followedGroupMembersQry = followedGroupMembersQry.Where(m => m.GroupRole.Guid.Equals(groupRoleGuid.Value));
                    }

                    var followedGroupMembers = followedGroupMembersQry.ToList();

                    // Run the query to get all the groups that follower is a member of with selected filters
                    var followerPersonGroups = followings
                                               .Select(f => new
                    {
                        GroupMembers = followedGroupMembers.Where(a => a.GroupId == f.EntityId).ToList(),
                        f.PersonAliasId,
                        f.PersonId
                    })
                                               .ToList();

                    var followedMembersList = followedGroupMembers
                                              .Select(a => a.PersonId)
                                              .Distinct()
                                              .ToList();
                    // Build a dictionary of the personid->personaliasid
                    var personAliasIds = new Dictionary <int, int>();
                    personAliasService.Queryable().AsNoTracking()
                    .Where(a =>
                           followedMembersList.Contains(a.PersonId) &&
                           a.PersonId == a.AliasPersonId)
                    .ToList()
                    .ForEach(a => personAliasIds.AddOrIgnore(a.PersonId, a.Id));


                    // Loop through each follower/group combination
                    foreach (var followerPersonGroup in followerPersonGroups)
                    {
                        // Loop through the other people in that group
                        foreach (var member in followerPersonGroup.GroupMembers)
                        {
                            if (!isAutoFollow)
                            {
                                // add them to the list of suggestions
                                suggestions.Add(new PersonEntitySuggestion(followerPersonGroup.PersonId, personAliasIds[member.PersonId]));
                            }
                            else
                            {
                                // auto-add the follow
                                int followeePersonAliasId = personAliasIds[member.PersonId];

                                // if person is not already following the person
                                bool isFollowing = followingService.Queryable().Where(f =>
                                                                                      f.EntityTypeId == personAliasEntityType.Id &&
                                                                                      f.EntityId == followeePersonAliasId &&
                                                                                      f.PersonAliasId == followerPersonGroup.PersonAliasId).Any();
                                if (!isFollowing)
                                {
                                    var following = new Following();
                                    following.EntityTypeId  = personAliasEntityType.Id;
                                    following.EntityId      = followeePersonAliasId;
                                    following.PersonAliasId = followerPersonGroup.PersonAliasId;
                                    followingService.Add(following);
                                    rockContext.SaveChanges();
                                }
                            }
                        }
                    }
                }
            }

            return(suggestions);
        }
Пример #16
0
 /// <summary>
 /// Loads the attributes for the following suggestion.
 /// </summary>
 /// <param name="followingSuggestion">The following suggestion.</param>
 public void LoadAttributes( FollowingSuggestionType followingSuggestion )
 {
     followingSuggestion.LoadAttributes();
 }
Пример #17
0
        /// <summary>
        /// Gets the suggestions.
        /// </summary>
        /// <param name="followingSuggestionType">Type of the following suggestion.</param>
        /// <param name="followerPersonIds">The follower person ids.</param>
        /// <returns></returns>
        public override List<PersonEntitySuggestion> GetSuggestions( FollowingSuggestionType followingSuggestionType, List<int> followerPersonIds )
        {
            var suggestions = new List<PersonEntitySuggestion>();
            var personAliasEntityType = EntityTypeCache.Read( typeof( Rock.Model.PersonAlias ) );

            bool isAutoFollow = GetAttributeValue( followingSuggestionType, "AutoFollow" ).AsBoolean();

            // Get the grouptype guid
            Guid? groupTypeGuid = GetAttributeValue( followingSuggestionType, "GroupType" ).AsGuidOrNull();
            if ( groupTypeGuid.HasValue )
            {
                using ( var rockContext = new RockContext() )
                {
                    var groupMemberService = new GroupMemberService( rockContext );
                    var personAliasService = new PersonAliasService( rockContext );

                    // Get all the groupmember records for any follower and the selected group type
                    var followers = groupMemberService.Queryable().AsNoTracking()
                        .Where( m =>
                            m.GroupMemberStatus == GroupMemberStatus.Active &&
                            m.Group != null &&
                            m.Group.IsActive &&
                            m.Group.GroupType.Guid.Equals( groupTypeGuid.Value ) &&
                            followerPersonIds.Contains( m.PersonId ) );

                    // If a specific group or security role was specifed, limit groupmembers to only those of the selected group
                    Guid? groupGuid = GetAttributeValue( followingSuggestionType, "Group" ).AsGuidOrNull();
                    if ( !groupGuid.HasValue )
                    {
                        groupGuid = GetAttributeValue( followingSuggestionType, "SecurityRole" ).AsGuidOrNull();
                    }
                    if ( groupGuid.HasValue )
                    {
                        followers = followers.Where( m => m.Group.Guid.Equals( groupGuid.Value ) );
                    }

                    // If a specific role for the follower was specified, limit groupmembers to only those with the selected role
                    Guid? followerRoleGuid = GetAttributeValue( followingSuggestionType, "FollowerGroupType" ).AsGuidOrNull();
                    if ( followerRoleGuid.HasValue )
                    {
                        followers = followers.Where( m => m.GroupRole.Guid.Equals( followerRoleGuid.Value ) );
                    }

                    // Run the query to get all the groups that follower is a member of with selected filters
                    var followerPersonGroup = followers
                        .Select( f => new
                        {
                            f.PersonId,
                            f.GroupId
                        } )
                        .ToList();

                    // Get a unique list of any of the groups that followers belong to
                    var followedGroupIds = followerPersonGroup
                        .Select( f => f.GroupId )
                        .Distinct()
                        .ToList();

                    // Start building query to get the people to follow from any group that contains a follower
                    var followed = groupMemberService
                        .Queryable().AsNoTracking()
                        .Where( m => followedGroupIds.Contains( m.GroupId ) );

                    // If a specific role for the people being followed was specified, limit the query to only those with the selected role
                    Guid? followedRoleGuid = GetAttributeValue( followingSuggestionType, "FollowedGroupType" ).AsGuidOrNull();
                    if ( followedRoleGuid.HasValue )
                    {
                        followed = followed.Where( m => m.GroupRole.Guid.Equals( followedRoleGuid.Value ) );
                    }

                    // Get all the people in any of the groups that contain a follower
                    var followedPersonGroup = followed
                        .Select( f => new
                        {
                            f.PersonId,
                            f.GroupId
                        } )
                        .ToList();

                    // Get distinct list of people
                    var followedPersonIds = followedPersonGroup
                        .Select( f => f.PersonId )
                        .Distinct()
                        .ToList();

                    // Build a dictionary of the personid->personaliasid
                    var personAliasIds = new Dictionary<int, int>();
                    personAliasService.Queryable().AsNoTracking()
                        .Where( a =>
                            followedPersonIds.Contains( a.PersonId ) &&
                            a.PersonId == a.AliasPersonId )
                        .ToList()
                        .ForEach( a => personAliasIds.AddOrIgnore( a.PersonId, a.Id ) );

                    // Loop through each follower/group combination
                    foreach ( var followedGroup in followerPersonGroup )
                    {
                        // Loop through the other people in that group
                        foreach ( int followedPersonId in followedPersonGroup
                            .Where( f =>
                                f.GroupId == followedGroup.GroupId &&
                                f.PersonId != followedGroup.PersonId )
                            .Select( f => f.PersonId ) )
                        {
                            // If the person has a valid personalias id
                            if ( personAliasIds.ContainsKey( followedPersonId ) )
                            {
                                if ( !isAutoFollow )
                                {
                                    // add them to the list of suggestions
                                    suggestions.Add( new PersonEntitySuggestion( followedGroup.PersonId, personAliasIds[followedPersonId] ) );
                                }
                                else
                                {
                                    // auto-add the follow

                                    var followingService = new FollowingService( rockContext );

                                    int followerPersonAliasId = personAliasIds[followedGroup.PersonId];
                                    int followeePersonAliasId = personAliasIds[followedPersonId];

                                    // if person is not already following the person
                                    bool isFollowing = followingService.Queryable().Where( f =>
                                                            f.EntityTypeId == personAliasEntityType.Id
                                                            && f.EntityId == followeePersonAliasId
                                                            && f.PersonAliasId == followerPersonAliasId ).Any();
                                    if ( !isFollowing )
                                    {
                                        var following = new Following();
                                        following.EntityTypeId = personAliasEntityType.Id;
                                        following.EntityId = personAliasIds[followedPersonId];
                                        following.PersonAliasId = personAliasIds[followedGroup.PersonId];
                                        followingService.Add( following );
                                        rockContext.SaveChanges();
                                    }
                                }
                            }
                        }

                    }
                }
            }

            return suggestions;
        }
Пример #18
0
        /// <summary>
        /// Gets the suggestions.
        /// </summary>
        /// <param name="followingSuggestionType">Type of the following suggestion.</param>
        /// <param name="followerPersonIds">The follower person ids.</param>
        /// <returns></returns>
        public override List <PersonEntitySuggestion> GetSuggestions(FollowingSuggestionType followingSuggestionType, List <int> followerPersonIds)
        {
            var suggestions           = new List <PersonEntitySuggestion>();
            var personAliasEntityType = EntityTypeCache.Read(typeof(Rock.Model.PersonAlias));

            bool isAutoFollow = GetAttributeValue(followingSuggestionType, "AutoFollow").AsBoolean();

            // Get the grouptype guid
            Guid?groupTypeGuid = GetAttributeValue(followingSuggestionType, "GroupType").AsGuidOrNull();

            if (groupTypeGuid.HasValue)
            {
                using (var rockContext = new RockContext())
                {
                    var groupMemberService = new GroupMemberService(rockContext);
                    var personAliasService = new PersonAliasService(rockContext);

                    // Get all the groupmember records for any follower and the selected group type
                    var followers = groupMemberService.Queryable().AsNoTracking()
                                    .Where(m =>
                                           m.GroupMemberStatus == GroupMemberStatus.Active &&
                                           m.Group != null &&
                                           m.Group.IsActive &&
                                           m.Group.GroupType.Guid.Equals(groupTypeGuid.Value) &&
                                           followerPersonIds.Contains(m.PersonId));

                    // If a specific group or security role was specifed, limit groupmembers to only those of the selected group
                    Guid?groupGuid = GetAttributeValue(followingSuggestionType, "Group").AsGuidOrNull();
                    if (!groupGuid.HasValue)
                    {
                        groupGuid = GetAttributeValue(followingSuggestionType, "SecurityRole").AsGuidOrNull();
                    }
                    if (groupGuid.HasValue)
                    {
                        followers = followers.Where(m => m.Group.Guid.Equals(groupGuid.Value));
                    }

                    // If a specific role for the follower was specified, limit groupmembers to only those with the selected role
                    Guid?followerRoleGuid = GetAttributeValue(followingSuggestionType, "FollowerGroupType").AsGuidOrNull();
                    if (followerRoleGuid.HasValue)
                    {
                        followers = followers.Where(m => m.GroupRole.Guid.Equals(followerRoleGuid.Value));
                    }

                    // Run the query to get all the groups that follower is a member of with selected filters
                    var followerPersonGroup = followers
                                              .Select(f => new
                    {
                        f.PersonId,
                        f.GroupId
                    })
                                              .ToList();

                    // Get a unique list of any of the groups that followers belong to
                    var followedGroupIds = followerPersonGroup
                                           .Select(f => f.GroupId)
                                           .Distinct()
                                           .ToList();

                    // Start building query to get the people to follow from any group that contains a follower
                    var followed = groupMemberService
                                   .Queryable().AsNoTracking()
                                   .Where(m => followedGroupIds.Contains(m.GroupId));

                    // If a specific role for the people being followed was specified, limit the query to only those with the selected role
                    Guid?followedRoleGuid = GetAttributeValue(followingSuggestionType, "FollowedGroupType").AsGuidOrNull();
                    if (followedRoleGuid.HasValue)
                    {
                        followed = followed.Where(m => m.GroupRole.Guid.Equals(followedRoleGuid.Value));
                    }

                    // Get all the people in any of the groups that contain a follower
                    var followedPersonGroup = followed
                                              .Select(f => new
                    {
                        f.PersonId,
                        f.GroupId
                    })
                                              .ToList();

                    // Get distinct list of people
                    var followedPersonIds = followedPersonGroup
                                            .Select(f => f.PersonId)
                                            .Distinct()
                                            .ToList();

                    // Build a dictionary of the personid->personaliasid
                    var personAliasIds = new Dictionary <int, int>();
                    personAliasService.Queryable().AsNoTracking()
                    .Where(a =>
                           followedPersonIds.Contains(a.PersonId) &&
                           a.PersonId == a.AliasPersonId)
                    .ToList()
                    .ForEach(a => personAliasIds.AddOrIgnore(a.PersonId, a.Id));

                    // Loop through each follower/group combination
                    foreach (var followedGroup in followerPersonGroup)
                    {
                        // Loop through the other people in that group
                        foreach (int followedPersonId in followedPersonGroup
                                 .Where(f =>
                                        f.GroupId == followedGroup.GroupId &&
                                        f.PersonId != followedGroup.PersonId)
                                 .Select(f => f.PersonId))
                        {
                            // If the person has a valid personalias id
                            if (personAliasIds.ContainsKey(followedPersonId))
                            {
                                if (!isAutoFollow)
                                {
                                    // add them to the list of suggestions
                                    suggestions.Add(new PersonEntitySuggestion(followedGroup.PersonId, personAliasIds[followedPersonId]));
                                }
                                else
                                {
                                    // auto-add the follow

                                    var followingService = new FollowingService(rockContext);

                                    int followerPersonAliasId = personAliasIds[followedGroup.PersonId];
                                    int followeePersonAliasId = personAliasIds[followedPersonId];

                                    // if person is not already following the person
                                    bool isFollowing = followingService.Queryable().Where(f =>
                                                                                          f.EntityTypeId == personAliasEntityType.Id &&
                                                                                          f.EntityId == followeePersonAliasId &&
                                                                                          f.PersonAliasId == followerPersonAliasId).Any();
                                    if (!isFollowing)
                                    {
                                        var following = new Following();
                                        following.EntityTypeId  = personAliasEntityType.Id;
                                        following.EntityId      = personAliasIds[followedPersonId];
                                        following.PersonAliasId = personAliasIds[followedGroup.PersonId];
                                        followingService.Add(following);
                                        rockContext.SaveChanges();
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(suggestions);
        }
Пример #19
0
 /// <summary>
 /// Handles the SelectedIndexChanged event of the cpSuggestionType 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 cpSuggestionType_SelectedIndexChanged( object sender, EventArgs e )
 {
     var followingSuggestion = new FollowingSuggestionType { Id = SuggestionId, EntityTypeId = cpSuggestionType.SelectedEntityTypeId };
     BuildDynamicControls( followingSuggestion, true );
 }