/// <summary>
        /// Get a list of all inherited Attributes that should be applied to this entity.
        /// </summary>
        /// <returns>A list of all inherited AttributeCache objects.</returns>
        public override List <AttributeCache> GetInheritedAttributes(Rock.Data.RockContext rockContext)
        {
            var connectionOpportunity = this.ConnectionOpportunity;

            if (connectionOpportunity == null && this.ConnectionOpportunityId > 0)
            {
                connectionOpportunity = new ConnectionOpportunityService(rockContext)
                                        .Queryable().AsNoTracking()
                                        .FirstOrDefault(g => g.Id == this.ConnectionOpportunityId);
            }

            if (connectionOpportunity != null)
            {
                var connectionType = connectionOpportunity.ConnectionType;

                if (connectionType != null)
                {
                    return(connectionType.GetInheritedAttributesForQualifier(rockContext, TypeId, "ConnectionTypeId"));
                }
            }

            return(null);
        }
Exemplo n.º 2
0
            /// <summary>
            /// Called before the save operation is executed.
            /// </summary>
            protected override void PreSave()
            {
                // Get the current person's alias ID from the current context.
                var currentPersonAliasId = DbContext.GetCurrentPersonAlias()?.Id;

                HistoryChangeList       = new History.HistoryChangeList();
                PersonHistoryChangeList = new History.HistoryChangeList();
                var connectionRequest = this.Entity as ConnectionRequest;

                var rockContext           = ( RockContext )this.RockContext;
                var connectionOpportunity = connectionRequest.ConnectionOpportunity;

                if (connectionOpportunity == null)
                {
                    connectionOpportunity = new ConnectionOpportunityService(rockContext).Get(connectionRequest.ConnectionOpportunityId);
                }

                switch (State)
                {
                case EntityContextState.Added:
                {
                    HistoryChangeList.AddChange(History.HistoryVerb.Add, History.HistoryChangeType.Record, "ConnectionRequest");

                    History.EvaluateChange(HistoryChangeList, "Connector", string.Empty, History.GetValue <PersonAlias>(connectionRequest.ConnectorPersonAlias, connectionRequest.ConnectorPersonAliasId, rockContext));
                    History.EvaluateChange(HistoryChangeList, "ConnectionStatus", string.Empty, History.GetValue <ConnectionStatus>(connectionRequest.ConnectionStatus, connectionRequest.ConnectionStatusId, rockContext));
                    History.EvaluateChange(HistoryChangeList, "ConnectionState", null, connectionRequest.ConnectionState);
                    PersonHistoryChangeList.AddChange(History.HistoryVerb.ConnectionRequestAdded, History.HistoryChangeType.Record, connectionOpportunity.Name);
                    if (connectionRequest.ConnectionState == ConnectionState.Connected)
                    {
                        PersonHistoryChangeList.AddChange(History.HistoryVerb.ConnectionRequestConnected, History.HistoryChangeType.Record, connectionOpportunity.Name);
                    }

                    break;
                }

                case EntityContextState.Modified:
                {
                    var    originalConnectorPersonAliasId = Entry.OriginalValues[nameof(ConnectionRequest.ConnectorPersonAliasId)].ToStringSafe().AsIntegerOrNull();
                    string originalConnector = History.GetValue <PersonAlias>(null, Entry.OriginalValues[nameof(ConnectionRequest.ConnectorPersonAliasId)].ToStringSafe().AsIntegerOrNull(), rockContext);
                    string connector         = History.GetValue <PersonAlias>(connectionRequest.ConnectorPersonAlias, connectionRequest.ConnectorPersonAliasId, rockContext);
                    History.EvaluateChange(HistoryChangeList, "Connector", originalConnector, connector);

                    int?originalConnectionStatusId = Entry.OriginalValues[nameof(ConnectionRequest.ConnectionStatusId)].ToStringSafe().AsIntegerOrNull();
                    int?connectionStatusId         = connectionRequest.ConnectionStatus != null ? connectionRequest.ConnectionStatus.Id : connectionRequest.ConnectionStatusId;
                    if (!connectionStatusId.Equals(originalConnectionStatusId))
                    {
                        string origConnectionStatus = History.GetValue <ConnectionStatus>(null, originalConnectionStatusId, rockContext);
                        string connectionStatus     = History.GetValue <ConnectionStatus>(connectionRequest.ConnectionStatus, connectionRequest.ConnectionStatusId, rockContext);
                        History.EvaluateChange(HistoryChangeList, "ConnectionStatus", origConnectionStatus, connectionStatus);
                        PersonHistoryChangeList.AddChange(History.HistoryVerb.ConnectionRequestStatusModify, History.HistoryChangeType.Record, connectionOpportunity.Name);
                    }

                    var originalConnectionState = Entry.OriginalValues[nameof(ConnectionRequest.ConnectionState)].ToStringSafe().ConvertToEnum <ConnectionState>();
                    History.EvaluateChange(HistoryChangeList, "ConnectionState", Entry.OriginalValues[nameof(ConnectionRequest.ConnectionState)].ToStringSafe().ConvertToEnum <ConnectionState>(), connectionRequest.ConnectionState);
                    if (connectionRequest.ConnectionState != originalConnectionState)
                    {
                        if (connectionRequest.ConnectionState == ConnectionState.Connected)
                        {
                            PersonHistoryChangeList.AddChange(History.HistoryVerb.ConnectionRequestConnected, History.HistoryChangeType.Record, connectionOpportunity.Name);
                        }
                        else
                        {
                            PersonHistoryChangeList.AddChange(History.HistoryVerb.ConnectionRequestStateModify, History.HistoryChangeType.Record, connectionOpportunity.Name);
                        }
                    }

                    break;
                }

                case EntityContextState.Deleted:
                {
                    HistoryChangeList.AddChange(History.HistoryVerb.Delete, History.HistoryChangeType.Record, "ConnectionRequest");
                    PersonHistoryChangeList.AddChange(History.HistoryVerb.ConnectionRequestDelete, History.HistoryChangeType.Record, connectionOpportunity.Name);
                    break;
                }
                }

                base.PreSave();
            }