/// <summary>
        /// Handles the Click event of the DeleteConnectionOpportunity control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Rock.Web.UI.Controls.RowEventArgs" /> instance containing the event data.</param>
        protected void DeleteConnectionOpportunity_Click(object sender, Rock.Web.UI.Controls.RowEventArgs e)
        {
            using (RockContext rockContext = new RockContext())
            {
                ConnectionOpportunityService connectionOpportunityService = new ConnectionOpportunityService(rockContext);
                ConnectionOpportunity        connectionOpportunity        = connectionOpportunityService.Get(e.RowKeyId);
                if (connectionOpportunity != null)
                {
                    if (_canEdit)
                    {
                        string errorMessage;
                        if (!connectionOpportunityService.CanDelete(connectionOpportunity, out errorMessage))
                        {
                            mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                            return;
                        }

                        int connectionTypeId = connectionOpportunity.ConnectionTypeId;
                        connectionOpportunityService.Delete(connectionOpportunity);
                        rockContext.SaveChanges();

                        ConnectionWorkflowService.FlushCachedTriggers();
                    }
                    else
                    {
                        mdGridWarning.Show("You are not authorized to delete this calendar item", ModalAlertType.Warning);
                    }
                }
            }
            BindConnectionOpportunitiesGrid();
        }
        /// <summary>
        /// Handles the Delete event of the gConnectionType 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 gConnectionType_Delete(object sender, RowEventArgs e)
        {
            using (var rockContext = new RockContext())
            {
                ConnectionWorkflowService connectionWorkflowService = new ConnectionWorkflowService(rockContext);
                ConnectionTypeService     connectionTypeService     = new ConnectionTypeService(rockContext);
                AuthService    authService    = new AuthService(rockContext);
                ConnectionType connectionType = connectionTypeService.Get(e.RowKeyId);

                if (connectionType != null)
                {
                    if (!connectionType.IsAuthorized(Authorization.ADMINISTRATE, this.CurrentPerson))
                    {
                        mdGridWarning.Show("You are not authorized to delete this connection type.", ModalAlertType.Information);
                        return;
                    }

                    // var connectionOppotunityies = new Service<ConnectionOpportunity>( rockContext ).Queryable().All( a => a.ConnectionTypeId == connectionType.Id );
                    var connectionOpportunities = connectionType.ConnectionOpportunities.ToList();
                    ConnectionOpportunityService     connectionOpportunityService     = new ConnectionOpportunityService(rockContext);
                    ConnectionRequestActivityService connectionRequestActivityService = new ConnectionRequestActivityService(rockContext);
                    foreach (var connectionOpportunity in connectionOpportunities)
                    {
                        var connectionRequestActivities = new Service <ConnectionRequestActivity>(rockContext).Queryable().Where(a => a.ConnectionOpportunityId == connectionOpportunity.Id).ToList();
                        foreach (var connectionRequestActivity in connectionRequestActivities)
                        {
                            connectionRequestActivityService.Delete(connectionRequestActivity);
                        }

                        rockContext.SaveChanges();
                        string errorMessageConnectionOpportunity;
                        if (!connectionOpportunityService.CanDelete(connectionOpportunity, out errorMessageConnectionOpportunity))
                        {
                            mdGridWarning.Show(errorMessageConnectionOpportunity, ModalAlertType.Information);
                            return;
                        }

                        connectionOpportunityService.Delete(connectionOpportunity);
                    }

                    rockContext.SaveChanges();
                    string errorMessage;
                    if (!connectionTypeService.CanDelete(connectionType, out errorMessage))
                    {
                        mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                        return;
                    }

                    connectionTypeService.Delete(connectionType);
                    rockContext.SaveChanges();

                    ConnectionWorkflowService.RemoveCachedTriggers();
                }
            }

            BindGrid();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Execute method to check for any workflows to launch.
        /// </summary>
        public void Execute()
        {
            // Verify that valid ids were saved
            if (ConnectionRequestId.HasValue)
            {
                // Get all the connectionWorkflows from cache
                var cachedWorkflows = ConnectionWorkflowService.GetCachedTriggers();

                // If any connectionWorkflows exist
                if (cachedWorkflows != null && cachedWorkflows.Any())
                {
                    // Get the connectionWorkflows associated to the connection
                    var workflows = cachedWorkflows
                                    .Where(w =>
                                           w.TriggerType == ConnectionWorkflowTriggerType.ActivityAdded &&
                                           (
                                               (w.ConnectionOpportunityId.HasValue && w.ConnectionOpportunityId.Value == ConnectionOpportunityId.Value) ||
                                               (w.ConnectionTypeId.HasValue)
                                           )
                                           )
                                    .ToList();

                    if (workflows.Any())
                    {
                        using (var rockContext = new RockContext())
                        {
                            // Get the current txn's connection type id
                            var ConnectionTypeId = new ConnectionOpportunityService(rockContext)
                                                   .Queryable().AsNoTracking()
                                                   .Where(o => o.Id == ConnectionOpportunityId.Value)
                                                   .Select(o => o.ConnectionTypeId)
                                                   .FirstOrDefault();

                            // Further filter the connection type connectionWorkflows by the connection type id
                            workflows = workflows
                                        .Where(w =>
                                               (w.ConnectionOpportunityId.HasValue && w.ConnectionOpportunityId.Value == ConnectionOpportunityId.Value) ||
                                               (w.ConnectionTypeId.HasValue && w.ConnectionTypeId.Value == ConnectionTypeId))
                                        .ToList();

                            // Loop through connectionWorkflows and lauch appropriate workflow
                            foreach (var connectionWorkflow in workflows)
                            {
                                if (QualifiersMatch(rockContext, connectionWorkflow, ConnectionActivityTypeId))
                                {
                                    LaunchWorkflow(rockContext, connectionWorkflow, "Activity Added");
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Job that will run quick SQL queries on a schedule.
        ///
        /// Called by the <see cref="IScheduler" /> when a
        /// <see cref="ITrigger" /> fires that is associated with
        /// the <see cref="IJob" />.
        /// </summary>
        public virtual void Execute(IJobExecutionContext context)
        {
            _httpContext = HttpContext.Current;
            // Get all the workflows from cache
            var cachedWorkflows = ConnectionWorkflowService.GetCachedTriggers();

            var futureFollowupDateWorkflows = new List <ConnectionWorkflow>();

            if (cachedWorkflows != null && cachedWorkflows.Any())
            {
                futureFollowupDateWorkflows = cachedWorkflows
                                              .Where(w =>
                                                     w.TriggerType == ConnectionWorkflowTriggerType.FutureFollowupDateReached
                                                     )
                                              .ToList();
            }
            var futureFollowupWorkflowResult = TriggerFutureFollowupWorkFlow(context, futureFollowupDateWorkflows);

            context.UpdateLastStatusMessage($@"Future follow-up Workflow Triggered: {futureFollowupWorkflowResult}");
        }
Exemplo n.º 5
0
        /// <summary>
        /// Executes this instance.
        /// </summary>
        /// <param name="message"></param>
        public override void Execute(Message message)
        {
            if (!(message.ConnectionOpportunityId.HasValue && message.PersonId.HasValue))
            {
                return;
            }

            // Get all the workflows from cache
            var cachedWorkflows = ConnectionWorkflowService.GetCachedTriggers();

            if (cachedWorkflows == null || !cachedWorkflows.Any())
            {
                return;
            }

            var workflows = cachedWorkflows
                            .Where(w =>
                                   w.TriggerType != ConnectionWorkflowTriggerType.ActivityAdded &&
                                   w.TriggerType != ConnectionWorkflowTriggerType.Manual &&
                                   (
                                       (w.ConnectionOpportunityId.HasValue && w.ConnectionOpportunityId.Value == message.ConnectionOpportunityId.Value) ||
                                       w.ConnectionTypeId.HasValue
                                   ))
                            .ToList();

            if (workflows.Any())
            {
                using (var rockContext = new RockContext())
                {
                    // Get the current txn's connection type id
                    if (!message.ConnectionTypeId.HasValue)
                    {
                        message.ConnectionTypeId = new ConnectionOpportunityService(rockContext)
                                                   .Queryable().AsNoTracking()
                                                   .Where(o => o.Id == message.ConnectionOpportunityId.Value)
                                                   .Select(o => o.ConnectionTypeId)
                                                   .FirstOrDefault();
                    }

                    // Further filter the connection type workflows by the connection type id
                    workflows = workflows
                                .Where(w =>
                                       (w.ConnectionOpportunityId.HasValue && w.ConnectionOpportunityId.Value == message.ConnectionOpportunityId.Value) ||
                                       (message.ConnectionTypeId.HasValue && w.ConnectionTypeId.HasValue && w.ConnectionTypeId.Value == message.ConnectionTypeId.Value))
                                .ToList();

                    // Loop through connectionWorkflows and launch appropriate workflow
                    foreach (var connectionWorkflow in workflows)
                    {
                        switch (connectionWorkflow.TriggerType)
                        {
                        case ConnectionWorkflowTriggerType.RequestStarted:
                        {
                            if (message.State == EntityContextState.Added)
                            {
                                LaunchWorkflow(rockContext, connectionWorkflow, "Request Started", message);
                            }

                            break;
                        }

                        case ConnectionWorkflowTriggerType.RequestAssigned:
                        {
                            if (message.ConnectorPersonAliasId.HasValue &&
                                !message.ConnectorPersonAliasId.Equals(message.PreviousConnectorPersonAliasId))
                            {
                                LaunchWorkflow(rockContext, connectionWorkflow, "Request Assigned", message);
                            }

                            break;
                        }

                        case ConnectionWorkflowTriggerType.RequestConnected:
                        {
                            if (message.State == EntityContextState.Modified &&
                                message.PreviousConnectionState != ConnectionState.Connected &&
                                message.ConnectionState == ConnectionState.Connected)
                            {
                                LaunchWorkflow(rockContext, connectionWorkflow, "Request Completed", message);
                            }

                            break;
                        }

                        case ConnectionWorkflowTriggerType.RequestTransferred:
                        {
                            if (message.State == EntityContextState.Modified &&
                                !message.PreviousConnectionOpportunityId.Equals(message.ConnectionOpportunityId))
                            {
                                LaunchWorkflow(rockContext, connectionWorkflow, "Request Transferred", message);
                            }

                            break;
                        }

                        case ConnectionWorkflowTriggerType.PlacementGroupAssigned:
                        {
                            if (message.State == EntityContextState.Modified &&
                                !message.PreviousAssignedGroupId.HasValue &&
                                message.AssignedGroupId.HasValue)
                            {
                                LaunchWorkflow(rockContext, connectionWorkflow, "Group Assigned", message);
                            }

                            break;
                        }

                        case ConnectionWorkflowTriggerType.StatusChanged:
                        {
                            if (message.State == EntityContextState.Modified && QualifiersMatch(rockContext, connectionWorkflow, message.PreviousConnectionStatusId, message.ConnectionStatusId))
                            {
                                LaunchWorkflow(rockContext, connectionWorkflow, "Status Changed", message);
                            }

                            break;
                        }

                        case ConnectionWorkflowTriggerType.StateChanged:
                        {
                            if (message.State == EntityContextState.Modified && QualifiersMatch(rockContext, connectionWorkflow, message.PreviousConnectionState, message.ConnectionState))
                            {
                                LaunchWorkflow(rockContext, connectionWorkflow, "State Changed", message);
                            }

                            break;
                        }
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Execute method to check for any workflows to launch.
        /// </summary>
        public void Execute()
        {
            // Verify that valid ids were saved
            if (ConnectionOpportunityId.HasValue && PersonId.HasValue)
            {
                // Get all the workflows from cache
                var cachedWorkflows = ConnectionWorkflowService.GetCachedTriggers();

                // If any workflows exist
                if (cachedWorkflows != null && cachedWorkflows.Any())
                {
                    // Get the workflows associated to the connection
                    var connectionOpportunityWorkflows = cachedWorkflows
                                                         .Where(w =>
                                                                w.TriggerType != ConnectionWorkflowTriggerType.ActivityAdded &&
                                                                w.ConnectionOpportunityId.HasValue &&
                                                                w.ConnectionOpportunityId.Value == ConnectionOpportunityId.Value)
                                                         .ToList();

                    // Get any workflows associated to a connection type ( if any are found, will then filter by connection type )
                    var connectionTypeWorkflows = cachedWorkflows
                                                  .Where(w =>
                                                         w.TriggerType != ConnectionWorkflowTriggerType.ActivityAdded &&
                                                         w.ConnectionTypeId.HasValue)
                                                  .ToList();

                    if (connectionOpportunityWorkflows.Any() || connectionTypeWorkflows.Any())
                    {
                        using (var rockContext = new RockContext())
                        {
                            // If there were any connection type workflows, will now need to read the opportunity's connection type id
                            // and then further filter these workflows by the current txn's connection type
                            if (connectionTypeWorkflows.Any())
                            {
                                // Get the current txn's connection type id
                                if (!ConnectionTypeId.HasValue)
                                {
                                    ConnectionTypeId = new ConnectionOpportunityService(rockContext)
                                                       .Queryable().AsNoTracking()
                                                       .Where(o => o.Id == ConnectionOpportunityId.Value)
                                                       .Select(o => o.ConnectionTypeId)
                                                       .FirstOrDefault();
                                }

                                // Further filter the connection type workflows by the connection type id
                                connectionTypeWorkflows = connectionTypeWorkflows
                                                          .Where(t =>
                                                                 t.ConnectionTypeId.HasValue &&
                                                                 t.ConnectionTypeId.Equals(ConnectionTypeId))
                                                          .ToList();
                            }

                            // Combine connection opportunity and connection type trigers
                            var connectionWorkflows = connectionOpportunityWorkflows.Union(connectionTypeWorkflows).ToList();

                            // If any connectionWorkflows were found
                            if (connectionWorkflows.Any())
                            {
                                // Loop through connectionWorkflows and lauch appropriate workflow
                                foreach (var connectionWorkflow in connectionWorkflows)
                                {
                                    switch (connectionWorkflow.TriggerType)
                                    {
                                    case ConnectionWorkflowTriggerType.RequestStarted:
                                    {
                                        if (State == EntityState.Added && QualifiersMatch(rockContext, connectionWorkflow, ConnectionState, ConnectionState, ConnectionStatusId, ConnectionStatusId, AssignedGroupId))
                                        {
                                            LaunchWorkflow(rockContext, connectionWorkflow, "Request Started");
                                        }
                                        break;
                                    }

                                    case ConnectionWorkflowTriggerType.RequestConnected:
                                    {
                                        if (State == EntityState.Modified && ConnectionState == global::ConnectionState.Inactive)
                                        {
                                            LaunchWorkflow(rockContext, connectionWorkflow, "Request Completed");
                                        }
                                        break;
                                    }

                                    case ConnectionWorkflowTriggerType.StatusChanged:
                                    {
                                        if (State == EntityState.Modified && QualifiersMatch(rockContext, connectionWorkflow, PreviousConnectionStatusId, ConnectionStatusId))
                                        {
                                            LaunchWorkflow(rockContext, connectionWorkflow, "Status Changed");
                                        }
                                        break;
                                    }

                                    case ConnectionWorkflowTriggerType.StateChanged:
                                    {
                                        if (State == EntityState.Modified && QualifiersMatch(rockContext, connectionWorkflow, PreviousConnectionState, ConnectionState))
                                        {
                                            LaunchWorkflow(rockContext, connectionWorkflow, "State Changed");
                                        }
                                        break;
                                    }

                                    case ConnectionWorkflowTriggerType.PlacementGroupAssigned:
                                    {
                                        if (State == EntityState.Modified && QualifiersMatch(rockContext, connectionWorkflow, AssignedGroupId))
                                        {
                                            LaunchWorkflow(rockContext, connectionWorkflow, "Group Assigned");
                                        }
                                        break;
                                    }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Execute method to check for any workflows to launch.
        /// </summary>
        public void Execute()
        {
            // Verify that valid ids were saved
            if (ConnectionRequestId.HasValue)
            {
                // Get all the connectionWorkflows from cache
                var cachedWorkflows = ConnectionWorkflowService.GetCachedTriggers();

                // If any connectionWorkflows exist
                if (cachedWorkflows != null && cachedWorkflows.Any())
                {
                    // Get the connectionWorkflows associated to the connection
                    var connectionOpportunityWorkflows = cachedWorkflows
                                                         .Where(w =>
                                                                w.TriggerType == ConnectionWorkflowTriggerType.ActivityAdded &&
                                                                w.ConnectionOpportunityId.HasValue &&
                                                                w.ConnectionOpportunityId.Value == ConnectionOpportunityId.Value)
                                                         .ToList();

                    // Get any connectionWorkflows associated to a connection type ( if any are found, will then filter by connection type )
                    var connectionTypeWorkflows = cachedWorkflows
                                                  .Where(w =>
                                                         w.TriggerType == ConnectionWorkflowTriggerType.ActivityAdded &&
                                                         w.ConnectionTypeId.HasValue)
                                                  .ToList();

                    if (connectionOpportunityWorkflows.Any() || connectionTypeWorkflows.Any())
                    {
                        using (var rockContext = new RockContext())
                        {
                            // If there were any connection type connectionWorkflows, will now need to read the opportunity's connection type id
                            // and then further filter these connectionWorkflows by the current txn's connection type
                            if (connectionTypeWorkflows.Any())
                            {
                                // Get the current txn's connection type id
                                var ConnectionTypeId = new ConnectionOpportunityService(rockContext)
                                                       .Queryable().AsNoTracking()
                                                       .Where(o => o.Id == ConnectionOpportunityId.Value)
                                                       .Select(o => o.ConnectionTypeId)
                                                       .FirstOrDefault();

                                // Further filter the connection type connectionWorkflows by the connection type id
                                connectionTypeWorkflows = connectionTypeWorkflows
                                                          .Where(t =>
                                                                 t.ConnectionTypeId.HasValue &&
                                                                 t.ConnectionTypeId.Equals(ConnectionTypeId))
                                                          .ToList();
                            }

                            // Combine connection opportunity and connection type trigers
                            var connectionWorkflows = connectionOpportunityWorkflows.Union(connectionTypeWorkflows).ToList();

                            // If any connectionWorkflows were found
                            if (connectionWorkflows.Any())
                            {
                                // Loop through connectionWorkflows and lauch appropriate workflow
                                foreach (var connectionWorkflow in connectionWorkflows)
                                {
                                    if (QualifiersMatch(rockContext, connectionWorkflow, ConnectionActivityTypeId))
                                    {
                                        LaunchWorkflow(rockContext, connectionWorkflow, "Activity Added");
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }