/// <summary>
        /// Creates the HTML controls required to configure this type of field.
        /// </summary>
        /// <returns></returns>
        public override List <Control> ConfigurationControls()
        {
            var controls = base.ConfigurationControls();

            // Add checkbox for deciding if the list should include inactive items.
            var cbIncludeInactive = new RockCheckBox();

            controls.Add(cbIncludeInactive);
            cbIncludeInactive.AutoPostBack    = true;
            cbIncludeInactive.CheckedChanged += OnQualifierUpdated;
            cbIncludeInactive.Label           = "Include Inactive";
            cbIncludeInactive.Text            = "Yes";
            cbIncludeInactive.Help            = HELP_TEXT_INCLUDE_INACTIVE;

            // Add ConnectionType Filter drop-down list.
            var ddlConnectionTypeFilter = new RockDropDownList();

            controls.Add(ddlConnectionTypeFilter);
            ddlConnectionTypeFilter.Label = "Connection Type";
            ddlConnectionTypeFilter.Help  = HELP_TEXT_CONNECTION_TYPE;
            ddlConnectionTypeFilter.SelectedIndexChanged += OnQualifierUpdated;
            ddlConnectionTypeFilter.AutoPostBack          = true;

            var connectionTypeService = new ConnectionTypeService(new RockContext());

            ddlConnectionTypeFilter.Items.Add(new ListItem());
            ddlConnectionTypeFilter.Items.AddRange(connectionTypeService.Queryable().Select(x => new ListItem {
                Text = x.Name, Value = x.Id.ToString()
            }).ToArray());

            return(controls);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates the control(s) necessary for prompting user for a new value
        /// </summary>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="id"></param>
        /// <returns>
        /// The control
        /// </returns>
        public override Control EditControl(Dictionary <string, ConfigurationValue> configurationValues, string id)
        {
            var editControl = new RockDropDownList {
                ID = id
            };

            editControl.Items.Add(new ListItem());

            var types = new ConnectionTypeService(new RockContext())
                        .Queryable().AsNoTracking()
                        .OrderBy(o => o.Name)
                        .Select(o => new
            {
                o.Guid,
                o.Name,
            })
                        .ToList();

            if (types.Any())
            {
                foreach (var type in types)
                {
                    var listItem = new ListItem(type.Name, type.Guid.ToString().ToUpper());
                    editControl.Items.Add(listItem);
                }

                return(editControl);
            }

            return(null);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates the control(s) necessary for prompting user for a new value
        /// </summary>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="id"></param>
        /// <returns>
        /// The control
        /// </returns>
        public override Control EditControl( Dictionary<string, ConfigurationValue> configurationValues, string id )
        {
            var editControl = new RockDropDownList { ID = id };
            editControl.Items.Add( new ListItem() );

            var types = new ConnectionTypeService( new RockContext() )
                .Queryable().AsNoTracking()
                .OrderBy( o => o.Name )
                .Select( o => new
                {
                    o.Guid,
                    o.Name,
                } )
                .ToList();

            if ( types.Any() )
            {
                foreach ( var type in types )
                {
                    var listItem = new ListItem( type.Name, type.Guid.ToString().ToUpper() );
                    editControl.Items.Add( listItem );
                }

                return editControl;
            }

            return null;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Binds the data.
        /// </summary>
        private void BindData()
        {
            if (Person != null && Person.Id > 0)
            {
                bool hideInactive          = GetAttributeValue(AttributeKey.HideInactiveConnectionRequests).AsBoolean();
                var  rockContext           = new RockContext();
                var  connectionTypeService = new ConnectionTypeService(rockContext);
                var  connectionTypesQry    = connectionTypeService
                                             .Queryable();

                if (hideInactive)
                {
                    connectionTypesQry = connectionTypesQry
                                         .Where(t => t.ConnectionOpportunities.Any(o => o.IsActive == true))
                                         .Where(t => t.ConnectionOpportunities
                                                .Any(o => o.ConnectionRequests
                                                     .Any(r => r.PersonAlias.PersonId == Person.Id && (r.ConnectionState == ConnectionState.Active ||
                                                                                                       (r.ConnectionState == ConnectionState.FutureFollowUp && r.FollowupDate.HasValue && r.FollowupDate.Value <= _midnightTomorrow)))));
                }
                else
                {
                    connectionTypesQry = connectionTypesQry.Where(t => t.ConnectionOpportunities.Any(o => o.ConnectionRequests.Any(r => r.PersonAlias.PersonId == Person.Id)));
                }

                var connectionTypesList = connectionTypesQry.OrderBy(a => a.Name).AsNoTracking().ToList();

                rConnectionTypes.DataSource = connectionTypesList.Where(a => a.IsAuthorized(Rock.Security.Authorization.VIEW, this.CurrentPerson)).ToList();
                rConnectionTypes.DataBind();
            }
        }
        /// <summary>
        /// Creates the child controls.
        /// </summary>
        /// <returns></returns>
        public override Control[] CreateChildControls(Type entityType, FilterField filterControl)
        {
            var connectionTypePicker = new RockDropDownList();

            connectionTypePicker.ID    = filterControl.ID + "_connectionTypePicker";
            connectionTypePicker.Label = "Connection Type";
            connectionTypePicker.SelectedIndexChanged += connectionTypePicker_SelectedIndexChanged;
            connectionTypePicker.AutoPostBack          = true;
            connectionTypePicker.CssClass              = "js-connectiontype-picker";
            connectionTypePicker.Items.Clear();
            connectionTypePicker.Items.Insert(0, new ListItem());
            var connectionTypeList = new ConnectionTypeService(new RockContext()).Queryable()
                                     .OrderBy(a => a.Order)
                                     .ThenBy(a => a.Name)
                                     .ToList();

            foreach (var connectionType in connectionTypeList)
            {
                connectionTypePicker.Items.Add(new ListItem(connectionType.Name, connectionType.Id.ToString()));
            }

            filterControl.Controls.Add(connectionTypePicker);

            var connectionOpportunityPicker = new RockDropDownList();

            connectionOpportunityPicker.CssClass = "js-connectionopportunity-picker";
            connectionOpportunityPicker.ID       = filterControl.ID + "_connectionOpportunityPicker";
            connectionOpportunityPicker.Label    = "Connection Opportunity";
            filterControl.Controls.Add(connectionOpportunityPicker);
            PopulateConnectionOpportunityDropdownList(filterControl);

            return(new Control[2] {
                connectionTypePicker, connectionOpportunityPicker
            });
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Binds the data source to the selection control.
        /// </summary>
        private void BindControl()
        {
            rblAlertType.BindToEnum <AlertType>();

            var rockContext           = new RockContext();
            var connectionTypeService = new ConnectionTypeService(rockContext);

            ddlConnectionType.Items.Clear();
            ddlConnectionType.Items.Add(new ListItem());
            ddlConnectionType.Items.AddRange(connectionTypeService.Queryable().Select(x => new ListItem {
                Text = x.Name, Value = x.Id.ToString()
            }).ToArray());

            dvpPersonDataView.EntityTypeId = EntityTypeCache.Get(typeof(Rock.Model.Person)).Id;

            var systemCommunications = new SystemCommunicationService(rockContext).Queryable().OrderBy(e => e.Title);

            ddlDonorSystemCommunication.Items.Clear();
            ddlDonorSystemCommunication.Items.Add(new ListItem());
            ddlAccountParticipantSystemCommunication.Items.Clear();
            ddlAccountParticipantSystemCommunication.Items.Add(new ListItem());
            if (systemCommunications.Any())
            {
                ddlDonorSystemCommunication.Items.AddRange(systemCommunications.Select(x => new ListItem {
                    Text = x.Title, Value = x.Id.ToString()
                }).ToArray());
                ddlAccountParticipantSystemCommunication.Items.AddRange(systemCommunications.Select(x => new ListItem {
                    Text = x.Title, Value = x.Id.ToString()
                }).ToArray());
            }
        }
        /// <summary>
        /// Sets the selection.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="controls">The controls.</param>
        /// <param name="selection">The selection.</param>
        public override void SetSelection(Type entityType, Control[] controls, string selection)
        {
            if (!string.IsNullOrWhiteSpace(selection))
            {
                SelectionConfig selectionConfig = SelectionConfig.Parse(selection);
                if (controls.Length > 0 && selectionConfig.ConnectionOpportunityGuid.HasValue)
                {
                    var connectionTypePicker = controls[0] as RockDropDownList;
                    var connectionType       = new ConnectionTypeService(new RockContext()).Get(selectionConfig.ConnectionTypeGuid.Value);
                    if (connectionType != null)
                    {
                        connectionTypePicker.SetValue(connectionType.Id);
                    }

                    connectionTypePicker_SelectedIndexChanged(connectionTypePicker, new EventArgs());

                    var connectionOpportunityGuid   = selectionConfig.ConnectionOpportunityGuid.Value;
                    var connectionOpportunityPicker = controls[1] as RockDropDownList;
                    var connectionOpportunity       = new ConnectionOpportunityService(new RockContext()).Get(connectionOpportunityGuid);
                    if (connectionOpportunity != null)
                    {
                        connectionOpportunityPicker.SetValue(connectionOpportunity.Id);
                    }
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates the HTML controls required to configure this type of field
        /// </summary>
        /// <returns></returns>
        public override List <Control> ConfigurationControls()
        {
            var controls = base.ConfigurationControls();

            // Add checkbox for deciding if the list should include inactive items
            var cbIncludeInactive = new RockCheckBox();

            controls.Add(cbIncludeInactive);
            cbIncludeInactive.AutoPostBack    = true;
            cbIncludeInactive.CheckedChanged += OnQualifierUpdated;
            cbIncludeInactive.Label           = "Include Inactive";
            cbIncludeInactive.Text            = "Yes";
            cbIncludeInactive.Help            = "When set, inactive connection opportunities will be included in the list.";

            // Add ConnectionType Filter ddl
            var ddlConnectionTypeFilter = new RockDropDownList();

            controls.Add(ddlConnectionTypeFilter);
            ddlConnectionTypeFilter.Label = "Connection Type";
            ddlConnectionTypeFilter.Help  = "Select a Connection Type to limit selection to a specific connection type.  Leave blank to allow selection of connections from any connection type";
            ddlConnectionTypeFilter.SelectedIndexChanged += OnQualifierUpdated;
            ddlConnectionTypeFilter.AutoPostBack          = true;

            var connectionTypeService = new ConnectionTypeService(new RockContext());

            ddlConnectionTypeFilter.Items.Add(new ListItem());
            ddlConnectionTypeFilter.Items.AddRange(connectionTypeService.Queryable().Select(x => new ListItem {
                Text = x.Name, Value = x.Id.ToString()
            }).ToArray());

            return(controls);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Gets the edit value as the IEntity.Id
        /// </summary>
        /// <param name="control">The control.</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <returns></returns>
        public int?GetEditValueAsEntityId(System.Web.UI.Control control, Dictionary <string, ConfigurationValue> configurationValues)
        {
            Guid guid = GetEditValue(control, configurationValues).AsGuid();
            var  item = new ConnectionTypeService(new RockContext()).Get(guid);

            return(item != null ? item.Id : (int?)null);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Sets the edit value from IEntity.Id value
        /// </summary>
        /// <param name="control">The control.</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="id">The identifier.</param>
        public void SetEditValueFromEntityId(System.Web.UI.Control control, Dictionary <string, ConfigurationValue> configurationValues, int?id)
        {
            var    item      = new ConnectionTypeService(new RockContext()).Get(id ?? 0);
            string guidValue = item != null?item.Guid.ToString() : string.Empty;

            SetEditValue(control, configurationValues, guidValue);
        }
Ejemplo n.º 11
0
        /// <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();
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Gets the connection types view model that can be sent to the client.
        /// </summary>
        /// <returns>The <see cref="GetContentViewModel"/> that contains the information about the response.</returns>
        private GetContentViewModel GetConnectionTypes(GetConnectionTypesFilterViewModel filterViewModel)
        {
            using (var rockContext = new RockContext())
            {
                var connectionTypeService = new ConnectionTypeService(rockContext);
                var clientTypeService     = new ConnectionTypeClientService(rockContext, RequestContext.CurrentPerson);
                var filterOptions         = new ConnectionTypeQueryOptions
                {
                    IncludeInactive = true
                };

                // If requesting to only have my connections returned then specify
                // the current person identifier. If they are not logged in then
                // use an invalid identifier value so that no matches will be returned.
                if (filterViewModel.OnlyMyConnections)
                {
                    filterOptions.ConnectorPersonIds = new List <int> {
                        RequestContext.CurrentPerson?.Id ?? 0
                    };
                }

                // Get the connection types.
                var qry   = connectionTypeService.GetConnectionTypesQuery(filterOptions);
                var types = connectionTypeService.GetViewAuthorizedConnectionTypes(qry, RequestContext.CurrentPerson);

                // Get the various counts to make available to the Lava template.
                // The conversion of the value to a dictionary is a temporary work-around
                // until we have a way to mark external types as lava safe.
                var connectionTypeIds = types.Select(t => t.Id).ToList();
                var requestCounts     = clientTypeService.GetConnectionTypeCounts(connectionTypeIds)
                                        .ToDictionary(k => k.Key, k => k.Value
                                                      .GetType()
                                                      .GetProperties(BindingFlags.Instance | BindingFlags.Public)
                                                      .ToDictionary(prop => prop.Name, prop => prop.GetValue(k.Value, null)));

                // Process the connection opportunities with the template.
                var mergeFields = RequestContext.GetCommonMergeFields();
                mergeFields.AddOrReplace("ConnectionTypes", types);
                mergeFields.AddOrReplace("DetailPage", DetailPageGuid);
                mergeFields.AddOrReplace("ConnectionRequestCounts", requestCounts);

                var content = TypeTemplate.ResolveMergeFields(mergeFields);

                // If we found a connection opportunity then process the header
                // template.
                mergeFields = RequestContext.GetCommonMergeFields();

                var headerContent = HeaderTemplate.ResolveMergeFields(mergeFields);

                return(new GetContentViewModel
                {
                    HeaderContent = headerContent,
                    Content = content
                });
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Binds the control
        /// </summary>
        private void BindControl()
        {
            rblFamilyLimits.BindToEnum <FamilyLimits>();
            rblCreateConnectionRequests.BindToEnum <CreateConnectionRequestOptions>();

            var connectionTypeService = new ConnectionTypeService(new RockContext());

            ddlConnectionType.Items.Add(new ListItem());
            ddlConnectionType.Items.AddRange(connectionTypeService.Queryable().Select(x => new ListItem {
                Text = x.Name, Value = x.Guid.ToString()
            }).ToArray());
        }
        /// <summary>
        /// Gets the connection types view model that can be sent to the client.
        /// </summary>
        private void GetConnectionTypes()
        {
            using (var rockContext = new RockContext())
            {
                // Get the connection types.
                var connectionTypeService = new ConnectionTypeService(rockContext);
                var clientTypeService     = new ConnectionTypeClientService(rockContext, CurrentPerson);
                var filterOptions         = new ConnectionTypeQueryOptions
                {
                    IncludeInactive = true
                };
                var connectionTypesQuery = connectionTypeService.GetConnectionTypesQuery();

                var connectionTypes = connectionTypeService.GetViewAuthorizedConnectionTypes(connectionTypesQuery, CurrentPerson);

                // Get the various counts to make available to the Lava template.
                // The conversion of the value to a dictionary is a temporary work-around
                // until we have a way to mark external types as lava safe.
                var connectionTypeIds          = connectionTypes.Select(t => t.Id).ToList();
                var requestCounts              = clientTypeService.GetConnectionTypeCounts(connectionTypeIds);
                var connectionRequestCounts    = new Dictionary <string, string>();
                var sumTotalConnectionRequests = 0;

                foreach (var typeId in connectionTypeIds)
                {
                    // For now, show TotalCount since there is no way to toggle between the two.
                    // In the future, an options control should be added to allow seeing all vs "only my"
                    //if ( CurrentPerson != null )
                    //{
                    //    sumTotalConnectionRequests += requestCounts[typeId].AssignedToYouCount;
                    //    connectionRequestCounts.Add( typeId.ToString(), requestCounts[typeId].AssignedToYouCount.ToString() );
                    //}
                    //else
                    //{
                    sumTotalConnectionRequests += requestCounts[typeId].TotalCount;
                    connectionRequestCounts.Add(typeId.ToString(), requestCounts[typeId].TotalCount.ToString());
                    //}
                }

                var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(this.RockPage, this.CurrentPerson);

                mergeFields.AddOrReplace("ConnectionTypes", connectionTypes);
                mergeFields.AddOrReplace("DetailPage", DetailPageGuid.ToString());
                mergeFields.AddOrReplace("ConnectionRequestCounts", connectionRequestCounts);
                mergeFields.AddOrReplace("SumTotalConnectionRequests", sumTotalConnectionRequests);

                var content = TypeTemplate
                              .ResolveMergeFields(mergeFields)
                              .ResolveClientIds(upConnectionSelectLava.ClientID);

                lContent.Text = content;
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Gets the data.
        /// </summary>
        private void GetData()
        {
            using (var rockContext = new RockContext())
            {
                // Get all of the event calendars
                var allConnectionTypes = new ConnectionTypeService(rockContext).Queryable()
                                         .OrderBy(w => w.Name)
                                         .ToList();

                rptConnectionTypes.DataSource = allConnectionTypes.ToList();
                rptConnectionTypes.DataBind();
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Gets the selection.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="controls">The controls.</param>
        /// <returns></returns>
        public override string GetSelection(Type entityType, Control[] controls)
        {
            var selectionConfig  = new SelectionConfig();
            var connectionTypeId = (controls[0] as RockDropDownList).SelectedValueAsId();
            var connectionType   = new ConnectionTypeService(new RockContext()).Get(connectionTypeId ?? 0);

            if (connectionType != null)
            {
                selectionConfig.ConnectionTypeGuid = connectionType.Guid;
            }

            return(selectionConfig.ToJson());
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Binds the data.
        /// </summary>
        private void BindData()
        {
            if (Person != null && Person.Id > 0)
            {
                var rockContext           = new RockContext();
                var connectionTypeService = new ConnectionTypeService(rockContext);
                var connectionTypesQry    = connectionTypeService.Queryable().Where(a => a.ConnectionOpportunities.Any(b => b.ConnectionRequests.Any(r => r.PersonAlias.PersonId == this.Person.Id))).OrderBy(a => a.Name);

                var connectionTypesList = connectionTypesQry.AsNoTracking().ToList();

                rConnectionTypes.DataSource = connectionTypesList.Where(a => a.IsAuthorized(Rock.Security.Authorization.VIEW, this.CurrentPerson)).ToList();
                rConnectionTypes.DataBind();
            }
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Sets the selection.
 /// </summary>
 /// <param name="entityType">Type of the entity.</param>
 /// <param name="controls">The controls.</param>
 /// <param name="selection">The selection.</param>
 public override void SetSelection(Type entityType, Control[] controls, string selection)
 {
     if (!string.IsNullOrWhiteSpace(selection))
     {
         SelectionConfig selectionConfig = SelectionConfig.Parse(selection);
         if (controls.Length > 0 && selectionConfig.ConnectionTypeGuid.HasValue)
         {
             var connectionType = new ConnectionTypeService(new RockContext()).Get(selectionConfig.ConnectionTypeGuid.Value);
             if (connectionType != null)
             {
                 (controls[0] as RockDropDownList).SetValue(connectionType.Id);
             }
         }
     }
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Binds the data.
        /// </summary>
        private void BindData()
        {
            if (Person != null && Person.Id > 0)
            {
                var hideRequestStates = GetAttributeValue(AttributeKey.HideRequestStates).SplitDelimitedValues().ToList().Select(x => Enum.Parse(typeof(ConnectionState), x));
                using (var rockContext = new RockContext())
                {
                    var connectionTypeService = new ConnectionTypeService(rockContext);
                    var connectionTypesQry    = connectionTypeService.Queryable();

                    var connectionTypesList = connectionTypesQry
                                              .SelectMany(ct => ct.ConnectionOpportunities)
                                              .SelectMany(co => co.ConnectionRequests)
                                              .Select(cr => new ConnectionRequestViewModel
                    {
                        ConnectionType      = cr.ConnectionOpportunity.ConnectionType,
                        CampusId            = cr.CampusId,
                        ConnectionRequestId = cr.Id,
                        ConnectionRequestConnectionState   = cr.ConnectionState,
                        ConnectionOpportunity              = cr.ConnectionOpportunity,
                        ConnectionRequestDetailPageId      = cr.ConnectionOpportunity.ConnectionType.ConnectionRequestDetailPageId,
                        ConnectionRequestDetailPageRouteId = cr.ConnectionOpportunity.ConnectionType.ConnectionRequestDetailPageRouteId,
                        ConnectionStatus = cr.ConnectionStatus,
                        ConnectionState  = cr.ConnectionState,
                        PersonId         = cr.PersonAlias.PersonId,
                        IsActive         = cr.ConnectionOpportunity.IsActive,
                        FollowupDate     = cr.FollowupDate,
                    })
                                              .Where(crvm => crvm.PersonId == Person.Id);

                    // If hiding inactive ConnectionRequest.ConnectionStatus also filter out inactive ConnectionOpportunity instances (ConnectionOpportunity.IsActive).
                    if (hideRequestStates.Contains(ConnectionState.Inactive))
                    {
                        connectionTypesList = connectionTypesList.Where(t => t.IsActive);
                    }

                    rConnectionTypes.DataSource = connectionTypesList
                                                  .ToList()
                                                  .Where(crm => !hideRequestStates.Contains(crm.ConnectionState))
                                                  .Where(crm => crm.ConnectionType.IsAuthorized(Authorization.VIEW, CurrentPerson))
                                                  .Where(crm => crm.ConnectionOpportunity.IsAuthorized(Authorization.VIEW, CurrentPerson))
                                                  .OrderBy(a => a.ConnectionType.Order)
                                                  .ThenBy(a => a.ConnectionType.Name);
                    rConnectionTypes.DataBind();
                }
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Formats the selection.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override string FormatSelection(Type entityType, string selection)
        {
            string result          = "Connection Type";
            var    selectionConfig = SelectionConfig.Parse(selection);

            if (selectionConfig != null && selectionConfig.ConnectionTypeGuid.HasValue)
            {
                var connectionType = new ConnectionTypeService(new RockContext()).Get(selectionConfig.ConnectionTypeGuid.Value);

                if (connectionType != null)
                {
                    result = string.Format("Connection type: {0}", connectionType.Name);
                }
            }

            return(result);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Returns the field's current value(s)
        /// </summary>
        /// <param name="parentControl">The parent control.</param>
        /// <param name="value">Information about the value</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="condensed">Flag indicating if the value should be condensed (i.e. for use in a grid column)</param>
        /// <returns></returns>
        public override string FormatValue(Control parentControl, string value, Dictionary <string, ConfigurationValue> configurationValues, bool condensed)
        {
            string formattedValue = string.Empty;

            Guid?guid = value.AsGuidOrNull();

            if (guid.HasValue)
            {
                var type = new ConnectionTypeService(new RockContext()).Get(guid.Value);
                if (type != null)
                {
                    formattedValue = type.Name;
                }
            }

            return(base.FormatValue(parentControl, formattedValue, configurationValues, condensed));
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Gets the connection types.
        /// </summary>
        /// <returns></returns>
        private List <ConnectionType> GetConnectionTypes(RockContext rockContext)
        {
            var allConnectionTypes = new ConnectionTypeService(rockContext).Queryable()
                                     .OrderBy(g => g.Order).ThenBy(g => g.Name)
                                     .ToList();

            var authorizedConnectionTypes = new List <ConnectionType>();

            foreach (var connectionType in allConnectionTypes)
            {
                if (UserCanEdit || connectionType.IsAuthorized(Authorization.VIEW, CurrentPerson))
                {
                    authorizedConnectionTypes.Add(connectionType);
                }
            }

            return(authorizedConnectionTypes);
        }
        /// <summary>
        /// Gets the connection type view query.  The ConnectionStatues within each type
        /// should be processed by their ConnectionStatus.Order to avoid non-ideal
        /// conditions from arising.
        /// </summary>
        /// <returns></returns>
        private List <ConnectionTypeView> GetConnectionTypeViewsWithOrderedStatuses()
        {
            var rockContext           = new RockContext();
            var connectionTypeService = new ConnectionTypeService(rockContext);

            var views = connectionTypeService.Queryable().AsNoTracking()
                        .Where(ct => ct.IsActive && ct.ConnectionStatuses.Any(b => b.ConnectionStatusAutomations.Count > 0))
                        .Select(ct => new ConnectionTypeView
            {
                ConnectionTypeId   = ct.Id,
                ConnectionStatuses = ct.ConnectionStatuses
                                     .Where(cs => cs.IsActive && cs.ConnectionStatusAutomations.Any())
                                     .OrderBy(cs => cs.Order)
            })
                        .ToList();

            return(views);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Gets the data.
        /// </summary>
        private void GetData()
        {
            using (var rockContext = new RockContext())
            {
                // Get all of the event calendars
                var allConnectionTypes = new ConnectionTypeService(rockContext).Queryable()
                                         .OrderBy(w => w.Name)
                                         .ToList();

                var authorizedConnectionTypes = new List <ConnectionType>();
                foreach (var connectionType in allConnectionTypes)
                {
                    if (UserCanEdit || connectionType.IsAuthorized(Authorization.VIEW, CurrentPerson))
                    {
                        authorizedConnectionTypes.Add(connectionType);
                    }
                }

                rptConnectionTypes.DataSource = authorizedConnectionTypes.ToList();
                rptConnectionTypes.DataBind();
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="serviceInstance">The service instance.</param>
        /// <param name="parameterExpression">The parameter expression.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression(Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection)
        {
            SelectionConfig selectionConfig = SelectionConfig.Parse(selection);

            if (!selectionConfig.ConnectionTypeGuid.HasValue)
            {
                return(null);
            }

            var connectionType   = new ConnectionTypeService(new RockContext()).Get(selectionConfig.ConnectionTypeGuid.Value);
            int?connectionTypeId = null;

            if (connectionType != null)
            {
                connectionTypeId = connectionType.Id;
            }

            var qry = new ConnectionRequestService(( RockContext )serviceInstance.Context).Queryable()
                      .Where(p => p.ConnectionOpportunity.ConnectionTypeId == connectionTypeId);

            Expression extractedFilterExpression = FilterExpressionExtractor.Extract <Rock.Model.ConnectionRequest>(qry, parameterExpression, "p");

            return(extractedFilterExpression);
        }
Ejemplo n.º 26
0
        private void SetFilter()
        {
            var rockContext = new RockContext();
            int followUpConnectionTypeId =
                new ConnectionTypeService(rockContext).Get(
                    org.kcionline.bricksandmortarstudio.SystemGuid.ConnectionType
                    .FOLLOW_UP.AsGuid()).Id;
            var connectionStatuses =
                new ConnectionStatusService(rockContext).Queryable()
                .Where(c => c.ConnectionTypeId == followUpConnectionTypeId)
                .ToList();

            ddlStatus.Items.Add(new ListItem("", ""));
            connectionStatuses.ForEach(cs => ddlStatus.Items.Add(new ListItem(cs.Name, cs.Guid.ToString())));

            ddlStatus.SelectedValue = gFilter.GetUserPreference("Status");


            int?personId = gFilter.GetUserPreference("Consolidator").AsIntegerOrNull();

            if (personId.HasValue)
            {
                var personService = new PersonService(new RockContext());
                var person        = personService.Get(personId.Value);
                if (person != null)
                {
                    ppConsolidator.SetValue(person);
                }
            }

            drpDates.DelimitedValues = gFilter.GetUserPreference("Submitted");
            if (!drpDates.LowerValue.HasValue && !drpDates.UpperValue.HasValue)
            {
                gFilter.SaveUserPreference("Submitted", drpDates.DelimitedValues);
            }
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Creates the child controls.
        /// </summary>
        /// <returns></returns>
        public override Control[] CreateChildControls(Type entityType, FilterField filterControl)
        {
            RockDropDownList connectionTypePicker = new RockDropDownList();

            connectionTypePicker.CssClass = "js-connection-type-picker";
            connectionTypePicker.ID       = filterControl.ID + "_connectionTypePicker";
            connectionTypePicker.Label    = "Connection Type";

            connectionTypePicker.Items.Clear();
            connectionTypePicker.Items.Insert(0, new ListItem());
            var connectionTypeList = new ConnectionTypeService(new RockContext()).Queryable()
                                     .OrderBy(a => a.Order)
                                     .ThenBy(a => a.Name)
                                     .ToList();

            foreach (var connectionType in connectionTypeList)
            {
                connectionTypePicker.Items.Add(new ListItem(connectionType.Name, connectionType.Id.ToString()));
            }

            filterControl.Controls.Add(connectionTypePicker);

            return(new Control[] { connectionTypePicker });
        }
        /// <summary>
        /// Sets the filters.
        /// </summary>
        private void SetFilters( bool setValues )
        {
            using ( var rockContext = new RockContext() )
            {
                string sessionKey = string.Format( "ConnectionSearch_{0}", this.BlockId );
                var searchSelections = Session[sessionKey] as Dictionary<string, string>;
                setValues = setValues && searchSelections != null;

                var connectionType = new ConnectionTypeService( rockContext ).Get( GetAttributeValue( "ConnectionTypeId" ).AsInteger() );

                if ( !GetAttributeValue( "DisplayNameFilter" ).AsBoolean() )
                {
                    tbSearchName.Visible = false;
                }

                if ( GetAttributeValue( "DisplayCampusFilter" ).AsBoolean() )
                {
                    cblCampus.Visible = true;
                    cblCampus.DataSource = CampusCache.All().Where(c => (c.IsActive ?? false) && c.Id != 7 && c.Id != 8);
                    cblCampus.DataBind();
                }
                else
                {
                    cblCampus.Visible = false;
                }

                if ( setValues )
                {
                    if ( searchSelections.ContainsKey( "tbSearchName" ) )
                    {
                        tbSearchName.Text = searchSelections["tbSearchName"];
                    }
                    if ( searchSelections.ContainsKey( "cblCampus" ) )
                    {
                        var selectedItems = searchSelections["cblCampus"].SplitDelimitedValues().AsIntegerList();
                        cblCampus.SetValues( selectedItems );
                    }
                }
                else if ( GetAttributeValue( "EnableCampusContext" ).AsBoolean() )
                {
                    var campusEntityType = EntityTypeCache.Read( "Rock.Model.Campus" );
                    var contextCampus = RockPage.GetCurrentContext( campusEntityType ) as Campus;

                    if ( contextCampus != null )
                    {
                        cblCampus.SetValue( contextCampus.Id.ToString() );
                    }
                }

                if ( GetAttributeValue( "DisplayAttributeFilters" ).AsBoolean() )
                {
                    // Parse the attribute filters
                    AvailableAttributes = new List<AttributeCache>();
                    if ( connectionType != null )
                    {
                        int entityTypeId = new ConnectionOpportunity().TypeId;
                        foreach ( var attributeModel in new AttributeService( new RockContext() ).Queryable()
                            .Where( a =>
                                a.EntityTypeId == entityTypeId &&
                                a.EntityTypeQualifierColumn.Equals( "ConnectionTypeId", StringComparison.OrdinalIgnoreCase ) &&
                                a.EntityTypeQualifierValue.Equals( connectionType.Id.ToString() ) &&
                                a.AllowSearch == true )
                            .OrderBy( a => a.Order )
                            .ThenBy( a => a.Name ) )
                        {
                            AvailableAttributes.Add( AttributeCache.Read( attributeModel ) );
                        }
                    }

                    // Clear the filter controls
                    phAttributeFilters.Controls.Clear();

                    if ( AvailableAttributes != null )
                    {
                        foreach ( var attribute in AvailableAttributes )
                        {
                            string controlId = "filter_" + attribute.Id.ToString();
                            var control = attribute.FieldType.Field.FilterControl( attribute.QualifierValues, controlId, false, Rock.Reporting.FilterMode.SimpleFilter );
                            if ( control != null )
                            {
                                if ( control is IRockControl )
                                {
                                    var rockControl = (IRockControl)control;
                                    rockControl.Label = attribute.Name;
                                    rockControl.Help = attribute.Description;
                                    phAttributeFilters.Controls.Add( control );
                                }
                                else
                                {
                                    var wrapper = new RockControlWrapper();
                                    wrapper.ID = control.ID + "_wrapper";
                                    wrapper.Label = attribute.Name;
                                    wrapper.Controls.Add( control );
                                    phAttributeFilters.Controls.Add( wrapper );
                                }

                                if ( setValues && searchSelections.ContainsKey(controlId))
                                {
                                    var values = searchSelections[controlId].FromJsonOrNull<List<string>>();
                                    attribute.FieldType.Field.SetFilterValues( control, attribute.QualifierValues, values );
                                }
                            }
                        }
                    }
                }
                else
                {
                    phAttributeFilters.Visible = false;
                }
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Sets the filters.
        /// </summary>
        private void SetFilters(bool setValues)
        {
            using (var rockContext = new RockContext())
            {
                string sessionKey       = string.Format("ConnectionSearch_{0}", this.BlockId);
                var    searchSelections = Session[sessionKey] as Dictionary <string, string>;
                setValues = setValues && searchSelections != null;

                var connectionType = new ConnectionTypeService(rockContext).Get(GetAttributeValue("ConnectionTypeId").AsInteger());

                if (connectionType != null)
                {
                    int entityTypeId    = new ConnectionOpportunity().TypeId;
                    var attributeOneKey = GetAttributeValue("AttributeOneKey");
                    var attributeTwoKey = GetAttributeValue("AttributeTwoKey");

                    if (!string.IsNullOrWhiteSpace(attributeOneKey))
                    {
                        if (!string.IsNullOrWhiteSpace(attributeTwoKey))
                        {
                            pnlAttributeOne.CssClass = "col-sm-6";
                        }
                        else
                        {
                            pnlAttributeOne.CssClass = "col-sm-12";
                        }

                        AttributeOne = AttributeCache.Get(new AttributeService(new RockContext()).Queryable()
                                                          .FirstOrDefault(a =>
                                                                          a.EntityTypeId == entityTypeId &&
                                                                          a.EntityTypeQualifierColumn.Equals("ConnectionTypeId", StringComparison.OrdinalIgnoreCase) &&
                                                                          a.EntityTypeQualifierValue.Equals(connectionType.Id.ToString()) &&
                                                                          a.Key == attributeOneKey));
                    }

                    if (!string.IsNullOrWhiteSpace(attributeTwoKey))
                    {
                        if (!string.IsNullOrWhiteSpace(attributeOneKey))
                        {
                            pnlAttributeTwo.CssClass = "col-sm-6";
                        }
                        else
                        {
                            pnlAttributeTwo.CssClass = "col-sm-12";
                        }

                        AttributeTwo = AttributeCache.Get(new AttributeService(new RockContext()).Queryable()
                                                          .FirstOrDefault(a =>
                                                                          a.EntityTypeId == entityTypeId &&
                                                                          a.EntityTypeQualifierColumn.Equals("ConnectionTypeId", StringComparison.OrdinalIgnoreCase) &&
                                                                          a.EntityTypeQualifierValue.Equals(connectionType.Id.ToString()) &&
                                                                          a.Key == attributeTwoKey));
                    }
                }

                if (AttributeOne != null)
                {
                    phAttributeOne.Controls.Clear();
                    AttributeOne.AddControl(phAttributeOne.Controls, string.Empty, string.Empty, true, true, false);
                    var control = phAttributeOne.Controls[0] as DropDownList;
                    if (control != null)
                    {
                        control.EnableViewState       = true;
                        control.AutoPostBack          = true;
                        control.SelectedIndexChanged += new EventHandler(ddlAttributeOne_SelectedIndexChanged);
                    }
                    else
                    {
                        var          theseControls = phAttributeOne.Controls[0] as DropDownList;
                        DropDownList ddl           = new DropDownList();
                        string[]     theseValues   = AttributeOne.QualifierValues.Values.ElementAt(0).Value.Split(',');

                        foreach (string nameValue in theseValues)
                        {
                            string[] nameAndValue = nameValue.Split(new char[] { '^' });

                            if (nameAndValue.Length == 2)
                            {
                                ddl.Items.Add(new ListItem(nameAndValue[1].Trim(), nameAndValue[0].Trim()));
                            }
                        }

                        ddl.Items.Insert(0, new ListItem(String.Empty, String.Empty));
                        ddl.SelectedIndex = 0;
                        ddl.CssClass      = "form-control";
                        var attributeOneLabel = new HtmlGenericContainer("label");
                        attributeOneLabel.InnerHtml = AttributeOne.Name;
                        attributeOneLabel.CssClass  = "control-label";

                        phAttributeOne.Controls.Clear();
                        phAttributeOne.Controls.Add(new Literal()
                        {
                            Text = "<div class='form-group rock-drop-down-list'>"
                        });
                        phAttributeOne.Controls.Add(attributeOneLabel);
                        phAttributeOne.Controls.Add(ddl);
                        phAttributeOne.Controls.Add(new Literal()
                        {
                            Text = "</div>"
                        });

                        var newDdl = phAttributeOne.Controls[2] as DropDownList;

                        newDdl.EnableViewState       = true;
                        newDdl.AutoPostBack          = true;
                        newDdl.SelectedIndexChanged += new EventHandler(ddlAttributeOne_SelectedIndexChanged);
                    }
                }

                if (AttributeTwo != null)
                {
                    phAttributeTwo.Controls.Clear();
                    AttributeTwo.AddControl(phAttributeTwo.Controls, string.Empty, string.Empty, true, true, false);
                    var control = phAttributeTwo.Controls[0] as DropDownList;
                    if (control != null)
                    {
                        control.EnableViewState       = true;
                        control.AutoPostBack          = true;
                        control.SelectedIndexChanged += new EventHandler(ddlAttributeTwo_SelectedIndexChanged);
                    }
                    else
                    {
                        var          theseControls = phAttributeTwo.Controls[0] as DropDownList;
                        DropDownList ddl           = new DropDownList();
                        string[]     theseValues   = AttributeTwo.QualifierValues.Values.ElementAt(0).Value.Split(',');

                        foreach (string nameValue in theseValues)
                        {
                            string[] nameAndValue = nameValue.Split(new char[] { '^' });

                            if (nameAndValue.Length == 2)
                            {
                                ddl.Items.Add(new ListItem(nameAndValue[1].Trim(), nameAndValue[0].Trim()));
                            }
                        }

                        ddl.Items.Insert(0, new ListItem(String.Empty, String.Empty));
                        ddl.SelectedIndex = 0;
                        ddl.CssClass      = "form-control";
                        var attributeTwoLabel = new HtmlGenericContainer("label");
                        attributeTwoLabel.InnerHtml = AttributeTwo.Name;
                        attributeTwoLabel.CssClass  = "control-label";

                        phAttributeTwo.Controls.Clear();
                        phAttributeTwo.Controls.Add(new Literal()
                        {
                            Text = "<div class='form-group rock-drop-down-list'>"
                        });
                        phAttributeTwo.Controls.Add(attributeTwoLabel);
                        phAttributeTwo.Controls.Add(ddl);
                        phAttributeTwo.Controls.Add(new Literal()
                        {
                            Text = "</div>"
                        });

                        var newDdl = phAttributeTwo.Controls[2] as DropDownList;

                        newDdl.EnableViewState       = true;
                        newDdl.AutoPostBack          = true;
                        newDdl.SelectedIndexChanged += new EventHandler(ddlAttributeTwo_SelectedIndexChanged);
                    }
                }
            }
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Updates the list.
        /// </summary>
        private void UpdateList()
        {
            using (var rockContext = new RockContext())
            {
                var searchSelections = new Dictionary <string, string>();

                var connectionTypeId             = GetAttributeValue("ConnectionTypeId").AsInteger();
                var connectionType               = new ConnectionTypeService(rockContext).Get(connectionTypeId);
                var connectionOpportunityService = new ConnectionOpportunityService(rockContext);

                var qrySearch = connectionOpportunityService.Queryable().Where(a => a.ConnectionTypeId == connectionTypeId && a.IsActive == true).ToList();

                if (GetAttributeValue("DisplayNameFilter").AsBoolean())
                {
                    if (!string.IsNullOrWhiteSpace(tbSearchName.Text))
                    {
                        searchSelections.Add("tbSearchName", tbSearchName.Text);
                        var searchTerms = tbSearchName.Text.ToLower().SplitDelimitedValues(true);
                        qrySearch = qrySearch.Where(o => searchTerms.Any(t => t.Contains(o.Name.ToLower()) || o.Name.ToLower().Contains(t))).ToList();
                    }
                }

                if (GetAttributeValue("DisplayCampusFilter").AsBoolean())
                {
                    var searchCampuses = cblCampus.SelectedValuesAsInt;
                    if (searchCampuses.Count > 0)
                    {
                        searchSelections.Add("cblCampus", searchCampuses.AsDelimited("|"));
                        qrySearch = qrySearch.Where(o => o.ConnectionOpportunityCampuses.Any(c => searchCampuses.Contains(c.CampusId))).ToList();
                    }
                }

                if (GetAttributeValue("DisplayAttributeFilters").AsBoolean())
                {
                    // Filter query by any configured attribute filters
                    if (AvailableAttributes != null && AvailableAttributes.Any())
                    {
                        var attributeValueService = new AttributeValueService(rockContext);
                        var parameterExpression   = attributeValueService.ParameterExpression;

                        foreach (var attribute in AvailableAttributes)
                        {
                            string filterControlId = "filter_" + attribute.Id.ToString();
                            var    filterControl   = phAttributeFilters.FindControl(filterControlId);
                            if (filterControl != null)
                            {
                                var filterValues = attribute.FieldType.Field.GetFilterValues(filterControl, attribute.QualifierValues, Rock.Reporting.FilterMode.SimpleFilter);
                                var expression   = attribute.FieldType.Field.AttributeFilterExpression(attribute.QualifierValues, filterValues, parameterExpression);
                                if (expression != null)
                                {
                                    searchSelections.Add(filterControlId, filterValues.ToJson());
                                    var attributeValues = attributeValueService
                                                          .Queryable()
                                                          .Where(v => v.Attribute.Id == attribute.Id);

                                    attributeValues = attributeValues.Where(parameterExpression, expression, null);

                                    qrySearch = qrySearch.Where(o => attributeValues.Select(v => v.EntityId).Contains(o.Id)).ToList();
                                }
                            }
                        }
                    }
                }

                string sessionKey = string.Format("ConnectionSearch_{0}", this.BlockId);
                Session[sessionKey] = searchSelections;

                var opportunities = qrySearch.OrderBy(s => s.PublicName).ToList();

                var mergeFields = new Dictionary <string, object>();
                mergeFields.Add("CurrentPerson", CurrentPerson);
                mergeFields.Add("CampusContext", RockPage.GetCurrentContext(EntityTypeCache.Read("Rock.Model.Campus")) as Campus);
                var pageReference = new PageReference(GetAttributeValue("DetailPage"), null);
                mergeFields.Add("DetailPage", BuildDetailPageUrl(pageReference.BuildUrl()));

                // iterate through the opportunities and lava merge the summaries and descriptions
                foreach (var opportunity in opportunities)
                {
                    opportunity.Summary     = opportunity.Summary.ResolveMergeFields(mergeFields);
                    opportunity.Description = opportunity.Description.ResolveMergeFields(mergeFields);
                }

                mergeFields.Add("Opportunities", opportunities);

                lOutput.Text = GetAttributeValue("LavaTemplate").ResolveMergeFields(mergeFields);

                if (GetAttributeValue("SetPageTitle").AsBoolean())
                {
                    string pageTitle = "Connection";
                    RockPage.PageTitle    = pageTitle;
                    RockPage.BrowserTitle = String.Format("{0} | {1}", pageTitle, RockPage.Site.Name);
                    RockPage.Header.Title = String.Format("{0} | {1}", pageTitle, RockPage.Site.Name);
                }
            }
        }
        /// <summary>
        /// Shows the detail.
        /// </summary>
        public void ShowDetail()
        {
            if (!string.IsNullOrWhiteSpace(GetAttributeValue("ConnectionTypes")) || !string.IsNullOrWhiteSpace(GetAttributeValue("ConnectionTypeDisplayOrder")))
            {
                btnConnect.Text = GetAttributeValue("ConnectButtonText");

                using (var rockContext = new RockContext())
                {
                    List <Guid> connectionTypeGuids = Array.ConvertAll(GetAttributeValue("ConnectionTypes").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), s => new Guid(s)).ToList();
                    var         test = GetAttributeValue("ConnectionTypeDisplayOrder");
                    List <int>  connectionTypeIds = Array.ConvertAll(GetAttributeValue("ConnectionTypeDisplayOrder").Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries), s => s.AsInteger()).ToList();

                    if (!string.IsNullOrWhiteSpace(GetAttributeValue("ConnectionTypeDisplayOrder")))
                    {
                        foreach (var connectionTypeId in connectionTypeIds)
                        {
                            var connectionById = new ConnectionTypeService(rockContext).Get(connectionTypeId);
                            if (connectionById != null)
                            {
                                _connectionTypes.Add(connectionById);
                            }
                        }
                    }
                    else
                    {
                        foreach (var connectionTypeGuid in connectionTypeGuids)
                        {
                            _connectionTypes.Add(new ConnectionTypeService(rockContext).Get(connectionTypeGuid));
                        }
                    }

                    if (!_connectionTypes.Any())
                    {
                        pnlSignup.Visible = false;
                        ShowError("Incorrect Opportunity Type", "The requested opportunity does not exist.");
                        return;
                    }

                    // load campus dropdown
                    var campuses = CampusCache.All().Where(c => (c.IsActive ?? false)).ToList();
                    cpCampus.Campuses = campuses;
                    cpCampus.Visible  = campuses.Any();

                    if (campuses.Any())
                    {
                        cpCampus.SetValue(campuses.First().Id);
                    }

                    pnlSignup.Visible  = true;
                    tbComments.Visible = GetAttributeValue("ShowComments").AsBoolean();

                    pnHome.Visible   = GetAttributeValue("DisplayHomePhone").AsBoolean();
                    pnMobile.Visible = GetAttributeValue("DisplayMobilePhone").AsBoolean();

                    Person registrant = null;

                    if (RockPage.PageParameter("PersonGuid") != null)
                    {
                        Guid?personGuid = RockPage.PageParameter("PersonGuid").AsGuidOrNull();

                        if (personGuid.HasValue)
                        {
                            registrant = new PersonService(rockContext).Get(personGuid.Value);
                        }
                    }

                    if (registrant == null && CurrentPerson != null)
                    {
                        registrant = CurrentPerson;
                    }

                    if (registrant != null)
                    {
                        pnlPersonInfo.Visible = GetAttributeValue("ShowPersonInfo").AsBoolean();
                        tbFirstName.Text      = registrant.FirstName.EncodeHtml();
                        tbLastName.Text       = registrant.LastName.EncodeHtml();
                        tbEmail.Text          = registrant.Email.EncodeHtml();

                        if (pnHome.Visible && _homePhone != null)
                        {
                            var homePhoneNumber = registrant.PhoneNumbers.Where(p => p.NumberTypeValueId == _homePhone.Id).FirstOrDefault();
                            if (homePhoneNumber != null)
                            {
                                pnHome.Number      = homePhoneNumber.NumberFormatted;
                                pnHome.CountryCode = homePhoneNumber.CountryCode;
                            }
                        }

                        if (pnMobile.Visible && _cellPhone != null)
                        {
                            var cellPhoneNumber = registrant.PhoneNumbers.Where(p => p.NumberTypeValueId == _cellPhone.Id).FirstOrDefault();
                            if (cellPhoneNumber != null)
                            {
                                pnMobile.Number      = cellPhoneNumber.NumberFormatted;
                                pnMobile.CountryCode = cellPhoneNumber.CountryCode;
                            }
                        }

                        var campus = registrant.GetCampus();
                        if (campus != null)
                        {
                            cpCampus.SelectedCampusId = campus.Id;
                        }
                    }
                    else
                    {
                        pnlPersonInfo.Visible = true;

                        // set the campus to the context
                        if (GetAttributeValue("EnableCampusContext").AsBoolean())
                        {
                            var campusEntityType = EntityTypeCache.Get("Rock.Model.Campus");
                            var contextCampus    = RockPage.GetCurrentContext(campusEntityType) as Campus;

                            if (contextCampus != null)
                            {
                                cpCampus.SelectedCampusId = contextCampus.Id;
                            }
                        }
                    }

                    // show debug info
                    var mergeFields = new Dictionary <string, object>();
                    mergeFields.Add("CurrentPerson", CurrentPerson);
                    if (GetAttributeValue("EnableDebug").AsBoolean() && IsUserAuthorized(Authorization.EDIT))
                    {
                        lDebug.Visible = true;
                        lDebug.Text    = mergeFields.lavaDebugInfo();
                    }
                }

                //
                // Create Bootstrap row to contain all the Connection containers
                //
                var divRow = new Panel
                {
                    CssClass = "row"
                };
                phConnections.Controls.Add(divRow);

                //
                // Walk through each Connection Type, and create a div for each.
                //
                foreach (var connectionType in _connectionTypes)
                {
                    LoadConnection(connectionType, divRow);
                }
            }
            else
            {
                pnlSignup.Visible = false;
                ShowError("Configure Block", "Please select at least one Connection Type in the block settings.");
            }
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="connectionOpportunityId">The connectionOpportunity identifier.</param>
        /// <param name="parentConnectionOpportunityId">The parent connectionOpportunity identifier.</param>
        public void ShowDetail( int connectionOpportunityId )
        {
            ConnectionOpportunity connectionOpportunity = null;

            bool editAllowed = UserCanEdit;

            RockContext rockContext = new RockContext();

            if ( !connectionOpportunityId.Equals( 0 ) )
            {
                connectionOpportunity = GetConnectionOpportunity( connectionOpportunityId, rockContext );
            }

            if ( connectionOpportunity == null )
            {
                connectionOpportunity = new ConnectionOpportunity { Id = 0, IsActive = true, Name = "" };
                connectionOpportunity.ConnectionType = new ConnectionTypeService( rockContext ).Get( PageParameter( "ConnectionTypeId" ).AsInteger() );
            }

            // Only users that have Edit rights to block, or edit rights to the calendar (from query string) should be able to edit
            if ( !editAllowed )
            {
                var connectionType = new ConnectionTypeService( rockContext ).Get( _connectionTypeId );
                if ( connectionType != null )
                {
                    editAllowed = connectionType.IsAuthorized( Authorization.EDIT, CurrentPerson );
                }
            }

            bool readOnly = true;

            if ( !editAllowed )
            {
                // User is not authorized
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( ConnectionOpportunity.FriendlyTypeName );
            }
            else
            {
                nbEditModeMessage.Text = string.Empty;

                if ( connectionOpportunity.Id != 0 && !( connectionOpportunity.ConnectionTypeId == _connectionTypeId ) )
                {
                    // Item does not belong to calendar
                    nbIncorrectOpportunity.Visible = true;
                }
                else
                {
                    readOnly = false;
                }
            }

            pnlDetails.Visible = !readOnly;
            this.HideSecondaryBlocks( !readOnly );

            if ( !readOnly )
            {
                hfConnectionOpportunityId.Value = connectionOpportunity.Id.ToString();
                ShowEditDetails( connectionOpportunity );
            }
        }
Ejemplo n.º 33
0
 /// <summary>
 /// Gets the edit value as the IEntity.Id
 /// </summary>
 /// <param name="control">The control.</param>
 /// <param name="configurationValues">The configuration values.</param>
 /// <returns></returns>
 public int? GetEditValueAsEntityId( System.Web.UI.Control control, Dictionary<string, ConfigurationValue> configurationValues )
 {
     Guid guid = GetEditValue( control, configurationValues ).AsGuid();
     var item = new ConnectionTypeService( new RockContext() ).Get( guid );
     return item != null ? item.Id : (int?)null;
 }
Ejemplo n.º 34
0
 /// <summary>
 /// Sets the edit value from IEntity.Id value
 /// </summary>
 /// <param name="control">The control.</param>
 /// <param name="configurationValues">The configuration values.</param>
 /// <param name="id">The identifier.</param>
 public void SetEditValueFromEntityId( System.Web.UI.Control control, Dictionary<string, ConfigurationValue> configurationValues, int? id )
 {
     var item = new ConnectionTypeService( new RockContext() ).Get( id ?? 0 );
     string guidValue = item != null ? item.Guid.ToString() : string.Empty;
     SetEditValue( control, configurationValues, guidValue );
 }
Ejemplo n.º 35
0
        /// <summary>
        /// Returns the field's current value(s)
        /// </summary>
        /// <param name="parentControl">The parent control.</param>
        /// <param name="value">Information about the value</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="condensed">Flag indicating if the value should be condensed (i.e. for use in a grid column)</param>
        /// <returns></returns>
        public override string FormatValue( Control parentControl, string value, Dictionary<string, ConfigurationValue> configurationValues, bool condensed )
        {
            string formattedValue = string.Empty;

            Guid? guid = value.AsGuidOrNull();
            if (guid.HasValue)
            {
                var type = new ConnectionTypeService( new RockContext() ).Get( guid.Value );
                if ( type != null )
                {
                    formattedValue = type.Name;
                }
            }

            return base.FormatValue( parentControl, formattedValue, configurationValues, condensed );
        }
Ejemplo n.º 36
0
        /// <summary>
        /// Returns breadcrumbs specific to the block that should be added to navigation
        /// based on the current page reference.  This function is called during the page's
        /// oninit to load any initial breadcrumbs
        /// </summary>
        /// <param name="pageReference">The page reference.</param>
        /// <returns></returns>
        public override List<BreadCrumb> GetBreadCrumbs( PageReference pageReference )
        {
            var breadCrumbs = new List<BreadCrumb>();

            int? connectionTypeId = PageParameter( pageReference, "ConnectionTypeId" ).AsIntegerOrNull();
            if ( connectionTypeId != null )
            {
                ConnectionType connectionType = new ConnectionTypeService( new RockContext() ).Get( connectionTypeId.Value );
                if ( connectionType != null )
                {
                    breadCrumbs.Add( new BreadCrumb( connectionType.Name, pageReference ) );
                }
                else
                {
                    breadCrumbs.Add( new BreadCrumb( "New Connection Type", pageReference ) );
                }
            }
            else
            {
                // don't show a breadcrumb if we don't have a pageparam to work with
            }

            return breadCrumbs;
        }
        /// <summary>
        /// Updates the list.
        /// </summary>
        private void UpdateList()
        {
            using ( var rockContext = new RockContext() )
            {
                var searchSelections = new Dictionary<string, string>();

                var connectionTypeId = GetAttributeValue( "ConnectionTypeId" ).AsInteger();
                var connectionType = new ConnectionTypeService( rockContext ).Get( connectionTypeId );
                var connectionOpportunityService = new ConnectionOpportunityService( rockContext );

                var qrySearch = connectionOpportunityService.Queryable().Where( a => a.ConnectionTypeId == connectionTypeId && a.IsActive == true ).ToList();

                if ( GetAttributeValue( "DisplayNameFilter" ).AsBoolean() )
                {
                    if ( !string.IsNullOrWhiteSpace( tbSearchName.Text ) )
                    {
                        searchSelections.Add( "tbSearchName", tbSearchName.Text );
                        var searchTerms = tbSearchName.Text.ToLower().SplitDelimitedValues( true );
                        qrySearch = qrySearch.Where( o => searchTerms.Any( t => t.Contains( o.Name.ToLower() ) || o.Name.ToLower().Contains( t ) ) ).ToList();
                    }
                }

                if ( GetAttributeValue( "DisplayCampusFilter" ).AsBoolean() )
                {
                    var searchCampuses = cblCampus.SelectedValuesAsInt;
                    if ( searchCampuses.Count > 0 )
                    {
                        searchSelections.Add( "cblCampus", searchCampuses.AsDelimited("|") );
                        qrySearch = qrySearch.Where( o => o.ConnectionOpportunityCampuses.Any( c => searchCampuses.Contains( c.CampusId ) ) ).ToList();
                    }
                }

                if ( GetAttributeValue( "DisplayAttributeFilters" ).AsBoolean() )
                {
                    // Filter query by any configured attribute filters
                    if ( AvailableAttributes != null && AvailableAttributes.Any() )
                    {
                        var attributeValueService = new AttributeValueService( rockContext );
                        var parameterExpression = attributeValueService.ParameterExpression;

                        foreach ( var attribute in AvailableAttributes )
                        {
                            string filterControlId = "filter_" + attribute.Id.ToString();
                            var filterControl = phAttributeFilters.FindControl( filterControlId );
                            if ( filterControl != null )
                            {
                                var filterValues = attribute.FieldType.Field.GetFilterValues( filterControl, attribute.QualifierValues, Rock.Reporting.FilterMode.SimpleFilter );
                                var expression = attribute.FieldType.Field.AttributeFilterExpression( attribute.QualifierValues, filterValues, parameterExpression );
                                if ( expression != null )
                                {
                                    searchSelections.Add( filterControlId, filterValues.ToJson() );
                                    var attributeValues = attributeValueService
                                        .Queryable()
                                        .Where( v => v.Attribute.Id == attribute.Id );

                                    attributeValues = attributeValues.Where( parameterExpression, expression, null );

                                    qrySearch = qrySearch.Where( o => attributeValues.Select( v => v.EntityId ).Contains( o.Id ) ).ToList();
                                }
                            }
                        }
                    }
                }

                string sessionKey = string.Format( "ConnectionSearch_{0}", this.BlockId );
                Session[sessionKey] = searchSelections;

                var opportunities = qrySearch.OrderBy( s => s.PublicName ).ToList();

                var mergeFields = new Dictionary<string, object>();
                mergeFields.Add( "Opportunities", opportunities);
                mergeFields.Add( "CurrentPerson", CurrentPerson );

                var pageReference = new PageReference( GetAttributeValue( "DetailPage" ), null );
                mergeFields.Add( "DetailPage", BuildDetailPageUrl(pageReference.BuildUrl()) );

                lOutput.Text = GetAttributeValue( "LavaTemplate" ).ResolveMergeFields( mergeFields );

                if ( GetAttributeValue( "SetPageTitle" ).AsBoolean() )
                {
                    string pageTitle = "Connection";
                    RockPage.PageTitle = pageTitle;
                    RockPage.BrowserTitle = String.Format( "{0} | {1}", pageTitle, RockPage.Site.Name );
                    RockPage.Header.Title = String.Format( "{0} | {1}", pageTitle, RockPage.Site.Name );
                }

                // show debug info
                if ( GetAttributeValue( "EnableDebug" ).AsBoolean() && IsUserAuthorized( Authorization.EDIT ) )
                {
                    lDebug.Visible = true;
                    lDebug.Text = mergeFields.lavaDebugInfo();
                }
            }
        }
Ejemplo n.º 38
0
        /// <summary>
        /// Updates the list.
        /// </summary>
        private void UpdateList()
        {
            using ( var rockContext = new RockContext() )
            {
                var connectionType = new ConnectionTypeService( rockContext ).Get( GetAttributeValue( "ConnectionTypeId" ).AsInteger() );
                var qrySearch = connectionType.ConnectionOpportunities.ToList();

                if ( GetAttributeValue( "DisplayNameFilter" ).AsBoolean() )
                {
                    if ( !string.IsNullOrWhiteSpace( tbSearchName.Text ) )
                    {
                        var searchTerms = tbSearchName.Text.ToLower().SplitDelimitedValues( true );
                        qrySearch = qrySearch.Where( o => searchTerms.Any( t => t.Contains( o.Name.ToLower() ) || o.Name.ToLower().Contains( t ) ) ).ToList();
                    }
                }

                if ( GetAttributeValue( "DisplayCampusFilter" ).AsBoolean() )
                {
                    var searchCampuses = cblCampus.SelectedValuesAsInt;
                    if ( searchCampuses.Count > 0 )
                    {
                        qrySearch = qrySearch.Where( o => o.ConnectionOpportunityCampuses.Any( c => searchCampuses.Contains( c.CampusId ) ) ).ToList();
                    }
                }

                if ( GetAttributeValue( "DisplayAttributeFilters" ).AsBoolean() )
                {
                    // Filter query by any configured attribute filters
                    if ( AvailableAttributes != null && AvailableAttributes.Any() )
                    {
                        var attributeValueService = new AttributeValueService( rockContext );
                        var parameterExpression = attributeValueService.ParameterExpression;

                        foreach ( var attribute in AvailableAttributes )
                        {
                            var filterControl = phAttributeFilters.FindControl( "filter_" + attribute.Id.ToString() );
                            if ( filterControl != null )
                            {
                                var filterValues = attribute.FieldType.Field.GetFilterValues( filterControl, attribute.QualifierValues, Rock.Reporting.FilterMode.SimpleFilter );
                                var expression = attribute.FieldType.Field.AttributeFilterExpression( attribute.QualifierValues, filterValues, parameterExpression );
                                if ( expression != null )
                                {
                                    var attributeValues = attributeValueService
                                        .Queryable()
                                        .Where( v => v.Attribute.Id == attribute.Id );

                                    attributeValues = attributeValues.Where( parameterExpression, expression, null );

                                    qrySearch = qrySearch.Where( o => attributeValues.Select( v => v.EntityId ).Contains( o.Id ) ).ToList();
                                }
                            }
                        }
                    }
                }

                var opportunitySummaries = new List<OpportunitySummary>();
                foreach ( var opportunity in qrySearch )
                {
                    opportunitySummaries.Add( new OpportunitySummary
                    {
                        IconCssClass = opportunity.IconCssClass,
                        Name = opportunity.PublicName,
                        PhotoUrl = opportunity.PhotoUrl,
                        Description = opportunity.Description.ScrubHtmlAndConvertCrLfToBr(),
                        Id = opportunity.Id
                    } );
                }

                var opportunities = opportunitySummaries
                    .OrderBy( e => e.Name )
                    .ToList();

                var mergeFields = new Dictionary<string, object>();
                mergeFields.Add( "Opportunities", opportunities );
                mergeFields.Add( "CurrentPerson", CurrentPerson );

                var pageReference = new PageReference( GetAttributeValue( "DetailPage" ), null );
                mergeFields.Add( "DetailPage", pageReference.BuildUrl() );

                lOutput.Text = GetAttributeValue( "LavaTemplate" ).ResolveMergeFields( mergeFields );

                if ( GetAttributeValue( "SetPageTitle" ).AsBoolean() )
                {
                    string pageTitle = "Connection";
                    RockPage.PageTitle = pageTitle;
                    RockPage.BrowserTitle = String.Format( "{0} | {1}", pageTitle, RockPage.Site.Name );
                    RockPage.Header.Title = String.Format( "{0} | {1}", pageTitle, RockPage.Site.Name );
                }

                // show debug info
                if ( GetAttributeValue( "EnableDebug" ).AsBoolean() && IsUserAuthorized( Authorization.EDIT ) )
                {
                    lDebug.Visible = true;
                    lDebug.Text = mergeFields.lavaDebugInfo();
                }
            }
        }
Ejemplo n.º 39
0
        /// <summary>
        /// Sets the filters.
        /// </summary>
        private void SetFilters()
        {
            using ( var rockContext = new RockContext() )
            {
                var connectionType = new ConnectionTypeService( rockContext ).Get( GetAttributeValue( "ConnectionTypeId" ).AsInteger() );

                if ( !GetAttributeValue( "DisplayNameFilter" ).AsBoolean() )
                {
                    tbSearchName.Visible = false;
                }

                if ( GetAttributeValue( "DisplayCampusFilter" ).AsBoolean() )
                {
                    cblCampus.Visible = true;
                    cblCampus.DataSource = CampusCache.All();
                    cblCampus.DataBind();
                }
                else
                {
                    cblCampus.Visible = false;
                }

                if ( GetAttributeValue( "EnableCampusContext" ).AsBoolean() )
                {
                    var campusEntityType = EntityTypeCache.Read( "Rock.Model.Campus" );
                    var contextCampus = RockPage.GetCurrentContext( campusEntityType ) as Campus;

                    if ( contextCampus != null )
                    {
                        cblCampus.SetValue( contextCampus.Id.ToString() );
                    }
                }

                if ( GetAttributeValue( "DisplayAttributeFilters" ).AsBoolean() )
                {
                    // Parse the attribute filters
                    AvailableAttributes = new List<AttributeCache>();
                    if ( connectionType != null )
                    {
                        int entityTypeId = new ConnectionOpportunity().TypeId;
                        foreach ( var attributeModel in new AttributeService( new RockContext() ).Queryable()
                            .Where( a =>
                                a.EntityTypeId == entityTypeId &&
                                a.EntityTypeQualifierColumn.Equals( "ConnectionTypeId", StringComparison.OrdinalIgnoreCase ) &&
                                a.EntityTypeQualifierValue.Equals( connectionType.Id.ToString() ) )
                            .OrderBy( a => a.Order )
                            .ThenBy( a => a.Name ) )
                        {
                            AvailableAttributes.Add( AttributeCache.Read( attributeModel ) );
                        }
                    }

                    // Clear the filter controls
                    phAttributeFilters.Controls.Clear();

                    if ( AvailableAttributes != null )
                    {
                        foreach ( var attribute in AvailableAttributes )
                        {
                            var control = attribute.FieldType.Field.FilterControl( attribute.QualifierValues, "filter_" + attribute.Id.ToString(), false, Rock.Reporting.FilterMode.SimpleFilter );
                            if ( control != null )
                            {
                                if ( control is IRockControl )
                                {
                                    var rockControl = (IRockControl)control;
                                    rockControl.Label = attribute.Name;
                                    rockControl.Help = attribute.Description;
                                    phAttributeFilters.Controls.Add( control );
                                }
                                else
                                {
                                    var wrapper = new RockControlWrapper();
                                    wrapper.ID = control.ID + "_wrapper";
                                    wrapper.Label = attribute.Name;
                                    wrapper.Controls.Add( control );
                                    phAttributeFilters.Controls.Add( wrapper );
                                }
                            }
                        }
                    }
                }
                else
                {
                    phAttributeFilters.Visible = false;
                }
            }
        }
        /// <summary>
        /// Binds the data.
        /// </summary>
        private void BindData()
        {
            if ( Person != null && Person.Id > 0 )
            {
                var rockContext = new RockContext();
                var connectionTypeService = new ConnectionTypeService( rockContext );
                var connectionTypesQry = connectionTypeService.Queryable().Where( a => a.ConnectionOpportunities.Any( b => b.ConnectionRequests.Any( r => r.PersonAlias.PersonId == this.Person.Id) ) ).OrderBy( a => a.Name );

                var connectionTypesList = connectionTypesQry.AsNoTracking().ToList();

                rConnectionTypes.DataSource = connectionTypesList.Where( a => a.IsAuthorized( Rock.Security.Authorization.VIEW, this.CurrentPerson ) ).ToList();
                rConnectionTypes.DataBind();
            }
        }
Ejemplo n.º 41
0
        /// <summary>
        /// Gets the data.
        /// </summary>
        private void GetData()
        {
            using ( var rockContext = new RockContext() )
            {
                // Get all of the event calendars
                var allConnectionTypes = new ConnectionTypeService( rockContext ).Queryable()
                    .OrderBy( w => w.Name )
                    .ToList();

                rptConnectionTypes.DataSource = allConnectionTypes.ToList();
                rptConnectionTypes.DataBind();
            }
        }
Ejemplo n.º 42
0
        /// <summary>
        /// Updates the trigger qualifiers.
        /// </summary>
        private void UpdateTriggerQualifiers()
        {
            RockContext rockContext = new RockContext();
            String[] qualifierValues = new String[2];

            ConnectionWorkflow connectionWorkflow = WorkflowsState.FirstOrDefault( l => l.Guid.Equals( hfWorkflowGuid.Value.AsGuid() ) );
            ConnectionWorkflowTriggerType connectionWorkflowTriggerType = ddlTriggerType.SelectedValueAsEnum<ConnectionWorkflowTriggerType>();
            int connectionTypeId = PageParameter( "ConnectionTypeId" ).AsInteger();
            var connectionType = new ConnectionTypeService( rockContext ).Get( connectionTypeId );
            switch ( connectionWorkflowTriggerType )
            {
                case ConnectionWorkflowTriggerType.RequestStarted:
                    ddlPrimaryQualifier.Visible = false;
                    ddlPrimaryQualifier.Items.Clear();
                    ddlSecondaryQualifier.Visible = false;
                    ddlSecondaryQualifier.Items.Clear();
                    break;

                case ConnectionWorkflowTriggerType.RequestCompleted:
                    ddlPrimaryQualifier.Visible = false;
                    ddlPrimaryQualifier.Items.Clear();
                    ddlSecondaryQualifier.Visible = false;
                    ddlSecondaryQualifier.Items.Clear();
                    break;

                case ConnectionWorkflowTriggerType.Manual:
                    ddlPrimaryQualifier.Visible = false;
                    ddlPrimaryQualifier.Items.Clear();
                    ddlSecondaryQualifier.Visible = false;
                    ddlSecondaryQualifier.Items.Clear();
                    break;

                case ConnectionWorkflowTriggerType.StateChanged:
                    ddlPrimaryQualifier.Label = "From";
                    ddlPrimaryQualifier.Visible = true;
                    ddlPrimaryQualifier.BindToEnum<ConnectionState>();
                    ddlPrimaryQualifier.Items.Insert( 0, new ListItem( string.Empty, string.Empty ) );
                    ddlSecondaryQualifier.Label = "To";
                    ddlSecondaryQualifier.Visible = true;
                    ddlSecondaryQualifier.BindToEnum<ConnectionState>();
                    ddlSecondaryQualifier.Items.Insert( 0, new ListItem( string.Empty, string.Empty ) );
                    if ( !connectionType.EnableFutureFollowup )
                    {
                        ddlPrimaryQualifier.Items.RemoveAt( 3 );
                        ddlSecondaryQualifier.Items.RemoveAt( 3 );
                    }
                    break;

                case ConnectionWorkflowTriggerType.StatusChanged:
                    var statusList = new ConnectionStatusService( rockContext ).Queryable().Where( s => s.ConnectionTypeId == connectionTypeId || s.ConnectionTypeId == null ).ToList();
                    ddlPrimaryQualifier.Label = "From";
                    ddlPrimaryQualifier.Visible = true;
                    ddlPrimaryQualifier.Items.Clear();
                    ddlPrimaryQualifier.Items.Add( new ListItem( string.Empty, string.Empty ) );
                    foreach ( var status in statusList )
                    {
                        ddlPrimaryQualifier.Items.Add( new ListItem( status.Name, status.Id.ToString().ToUpper() ) );
                    }
                    ddlSecondaryQualifier.Label = "To";
                    ddlSecondaryQualifier.Visible = true;
                    ddlSecondaryQualifier.Items.Clear();
                    ddlSecondaryQualifier.Items.Add( new ListItem( string.Empty, string.Empty ) );
                    foreach ( var status in statusList )
                    {
                        ddlSecondaryQualifier.Items.Add( new ListItem( status.Name, status.Id.ToString().ToUpper() ) );
                    }
                    break;

                case ConnectionWorkflowTriggerType.ActivityAdded:
                    var activityList = new ConnectionActivityTypeService( rockContext ).Queryable().Where( a => a.ConnectionTypeId == connectionTypeId || a.ConnectionTypeId == null ).ToList();
                    ddlPrimaryQualifier.Label = "Activity Type";
                    ddlPrimaryQualifier.Visible = true;
                    ddlPrimaryQualifier.Items.Clear();
                    ddlPrimaryQualifier.Items.Add( new ListItem( string.Empty, string.Empty ) );
                    foreach ( var activity in activityList )
                    {
                        ddlPrimaryQualifier.Items.Add( new ListItem( activity.Name, activity.Id.ToString().ToUpper() ) );
                    }
                    ddlSecondaryQualifier.Visible = false;
                    ddlSecondaryQualifier.Items.Clear();
                    break;

                case ConnectionWorkflowTriggerType.GroupAssigned:
                    var groupList = new GroupService( rockContext ).Queryable().ToList();
                    ddlPrimaryQualifier.Label = "Activity Group";
                    ddlPrimaryQualifier.Visible = true;
                    ddlPrimaryQualifier.Items.Clear();
                    ddlPrimaryQualifier.Items.Add( new ListItem( string.Empty, string.Empty ) );
                    foreach ( var group in groupList )
                    {
                        ddlPrimaryQualifier.Items.Add( new ListItem( group.Name, group.Id.ToString().ToUpper() ) );
                    }
                    ddlSecondaryQualifier.Visible = false;
                    ddlSecondaryQualifier.Items.Clear();
                    break;
            }

            if ( connectionWorkflow != null )
            {
                if ( connectionWorkflow.TriggerType == ddlTriggerType.SelectedValueAsEnum<ConnectionWorkflowTriggerType>() )
                {
                    qualifierValues = connectionWorkflow.QualifierValue.SplitDelimitedValues();
                    if ( ddlPrimaryQualifier.Visible )
                    {
                        ddlPrimaryQualifier.SelectedValue = qualifierValues[0];
                    }

                    if ( ddlSecondaryQualifier.Visible )
                    {
                        ddlSecondaryQualifier.SelectedValue = qualifierValues[1];
                    }
                }
            }
        }
Ejemplo n.º 43
0
        /// <summary>
        /// Gets the type of the connection.
        /// </summary>
        /// <param name="connectionTypeId">The connection type identifier.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <returns></returns>
        private ConnectionType GetConnectionType( int connectionTypeId, RockContext rockContext = null )
        {
            string key = string.Format( "ConnectionType:{0}", connectionTypeId );
            ConnectionType connectionType = RockPage.GetSharedItem( key ) as ConnectionType;
            if ( connectionType == null )
            {
                rockContext = rockContext ?? new RockContext();
                connectionType = new ConnectionTypeService( rockContext ).Queryable()
                    .Where( c => c.Id == connectionTypeId )
                    .FirstOrDefault();
                RockPage.SaveSharedItem( key, connectionType );
            }

            return connectionType;
        }
Ejemplo n.º 44
0
        private void LaunchWorkflow( RockContext rockContext, ConnectionWorkflow connectionWorkflow, string name )
        {
            ConnectionRequest connectionRequest = null;
            if ( ConnectionRequestGuid.HasValue )
            {
                connectionRequest = new ConnectionRequestService( rockContext ).Get( ConnectionRequestGuid.Value );
            }

            var workflowTypeService = new WorkflowTypeService( rockContext );
            var workflowType = workflowTypeService.Get( connectionWorkflow.WorkflowTypeId.Value );
            if ( workflowType != null )
            {
                var workflow = Rock.Model.Workflow.Activate( workflowType, name );

                if ( workflow.AttributeValues != null )
                {
                    if ( workflow.AttributeValues.ContainsKey( "ConnectionOpportunity" ) )
                    {
                        var connectionOpportunity = new ConnectionOpportunityService( rockContext ).Get( ConnectionOpportunityId.Value );
                        if ( connectionOpportunity != null )
                        {
                            workflow.AttributeValues["ConnectionOpportunity"].Value = connectionOpportunity.Guid.ToString();
                        }
                    }

                    if ( workflow.AttributeValues.ContainsKey( "ConnectionType" ) )
                    {
                        var connectionType = new ConnectionTypeService( rockContext ).Get( ConnectionTypeId.Value );
                        if ( connectionType != null )
                        {
                            workflow.AttributeValues["ConnectionType"].Value = connectionType.Guid.ToString();
                        }
                    }

                    if ( workflow.AttributeValues.ContainsKey( "ConnectionRequest" ) )
                    {
                        if ( connectionRequest != null )
                        {
                            workflow.AttributeValues["ConnectionRequest"].Value = connectionRequest.Guid.ToString();
                        }
                    }

                    if ( workflow.AttributeValues.ContainsKey( "Person" ) )
                    {
                        var person = new PersonService( rockContext ).Get( PersonId.Value );
                        if ( person != null )
                        {
                            workflow.AttributeValues["Person"].Value = person.PrimaryAlias.Guid.ToString();
                        }
                    }
                }

                List<string> workflowErrors;
                new WorkflowService( rockContext ).Process( workflow, connectionRequest, out workflowErrors );
                if ( workflow.Id != 0 )
                {
                    ConnectionRequestWorkflow connectionRequestWorkflow = new ConnectionRequestWorkflow();
                    connectionRequestWorkflow.ConnectionRequestId = connectionRequest.Id;
                    connectionRequestWorkflow.WorkflowId = workflow.Id;
                    connectionRequestWorkflow.ConnectionWorkflowId = connectionWorkflow.Id;
                    connectionRequestWorkflow.TriggerType = connectionWorkflow.TriggerType;
                    connectionRequestWorkflow.TriggerQualifier = connectionWorkflow.QualifierValue;
                    new ConnectionRequestWorkflowService( rockContext ).Add( connectionRequestWorkflow );
                    rockContext.SaveChanges();
                }
            }
        }
Ejemplo n.º 45
0
        /// <summary>
        /// Adds the connections requests to the system from the given XML element.
        /// </summary>
        /// <example>
        ///   &lt;connections&gt;
        ///       &lt;connection type="Involvement" opportunity="Children's" comment="I would love to help teach kids about Jesus." date="2015-10-11T00:00:00" personGuid="1dfff821-e97c-4324-9883-cf59b5c5bdd6" /&gt;
        ///   &lt;/connections&gt;
        /// </example>
        /// <param name="elemConnections">The elem connections.</param>
        /// <param name="rockContext">The rock context.</param>
        private void AddConnections( XElement elemConnections, RockContext rockContext )
        {
            if ( elemConnections == null )
            {
                return;
            }

            ConnectionRequestService crService = new ConnectionRequestService( rockContext );
            ConnectionOpportunityService coService = new ConnectionOpportunityService( rockContext );
            ConnectionTypeService typeService = new ConnectionTypeService( rockContext );
            ConnectionStatusService connectionStatusService = new ConnectionStatusService( rockContext );
            ConnectionStatus noContact = connectionStatusService.Get( "901e1a6a-0e91-4f42-880f-47c061c24e0c".AsGuid() );

            // Find the type and it's corresponding opportunity and then add a connection request for the given person.
            foreach ( var element in elemConnections.Elements( "connection" ) )
            {
                string connectionTypeName = element.Attribute( "type" ).Value.Trim();
                string opportunityName = element.Attribute( "opportunity" ).Value.Trim();
                string comment = element.Attribute( "comment" ).Value.Trim();
                DateTime date = DateTime.Parse( element.Attribute( "date" ).Value.Trim(), new CultureInfo( "en-US" ) );
                Guid personGuid = element.Attribute( "personGuid" ).Value.Trim().AsGuid();

                var connectionOpportunity = coService.Queryable( "ConnectionType" ).AsNoTracking().Where( co => co.ConnectionType.Name == connectionTypeName && co.Name == opportunityName ).FirstOrDefault();

                // make sure we found a matching connection opportunity
                if ( connectionOpportunity != null )
                {
                    ConnectionRequest connectionRequest = new ConnectionRequest()
                    {
                        ConnectionOpportunityId = connectionOpportunity.Id,
                        PersonAliasId = _peopleAliasDictionary[personGuid],
                        Comments = comment,
                        ConnectionStatus = noContact,
                        ConnectionState = global::ConnectionState.Active,
                        CreatedDateTime = date
                    };

                    crService.Add( connectionRequest );
                }
            }
        }
Ejemplo n.º 46
0
        /// <summary>
        /// Handles the Click event of the btnEdit 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 btnEdit_Click( object sender, EventArgs e )
        {
            var rockContext = new RockContext();
            var connectionType = new ConnectionTypeService( rockContext ).Get( hfConnectionTypeId.Value.AsInteger() );

            LoadStateDetails( connectionType, rockContext );
            ShowEditDetails( connectionType );
        }
Ejemplo n.º 47
0
        /// <summary>
        /// Handles the Click event of the btnDelete 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 btnDeleteConfirm_Click( object sender, EventArgs 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( int.Parse( hfConnectionTypeId.Value ) );

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

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

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

                    ConnectionWorkflowService.FlushCachedTriggers();
                }
            }

            NavigateToParentPage();
        }
Ejemplo n.º 48
0
        /// <summary>
        /// Sets the filters.
        /// </summary>
        private void SetFilters(bool setValues)
        {
            using (var rockContext = new RockContext())
            {
                string sessionKey       = string.Format("ConnectionSearch_{0}", this.BlockId);
                var    searchSelections = Session[sessionKey] as Dictionary <string, string>;
                setValues = setValues && searchSelections != null;

                var connectionType = new ConnectionTypeService(rockContext).Get(GetAttributeValue("ConnectionTypeId").AsInteger());

                if (!GetAttributeValue("DisplayNameFilter").AsBoolean())
                {
                    tbSearchName.Visible = false;
                }

                if (GetAttributeValue("DisplayCampusFilter").AsBoolean())
                {
                    cblCampus.Visible    = true;
                    cblCampus.DataSource = CampusCache.All(GetAttributeValue("DisplayInactiveCampuses").AsBoolean());
                    cblCampus.DataBind();
                }
                else
                {
                    cblCampus.Visible = false;
                }

                if (setValues)
                {
                    if (searchSelections.ContainsKey("tbSearchName"))
                    {
                        tbSearchName.Text = searchSelections["tbSearchName"];
                    }
                    if (searchSelections.ContainsKey("cblCampus"))
                    {
                        var selectedItems = searchSelections["cblCampus"].SplitDelimitedValues().AsIntegerList();
                        cblCampus.SetValues(selectedItems);
                    }
                }
                else if (GetAttributeValue("EnableCampusContext").AsBoolean())
                {
                    var campusEntityType = EntityTypeCache.Read("Rock.Model.Campus");
                    var contextCampus    = RockPage.GetCurrentContext(campusEntityType) as Campus;

                    if (contextCampus != null)
                    {
                        cblCampus.SetValue(contextCampus.Id.ToString());
                    }
                }

                if (GetAttributeValue("DisplayAttributeFilters").AsBoolean())
                {
                    // Parse the attribute filters
                    AvailableAttributes = new List <AttributeCache>();
                    if (connectionType != null)
                    {
                        int entityTypeId = new ConnectionOpportunity().TypeId;
                        foreach (var attributeModel in new AttributeService(new RockContext()).Queryable()
                                 .Where(a =>
                                        a.EntityTypeId == entityTypeId &&
                                        a.EntityTypeQualifierColumn.Equals("ConnectionTypeId", StringComparison.OrdinalIgnoreCase) &&
                                        a.EntityTypeQualifierValue.Equals(connectionType.Id.ToString()) &&
                                        a.AllowSearch == true)
                                 .OrderBy(a => a.Order)
                                 .ThenBy(a => a.Name))
                        {
                            AvailableAttributes.Add(AttributeCache.Read(attributeModel));
                        }
                    }

                    // Clear the filter controls
                    phAttributeFilters.Controls.Clear();

                    if (AvailableAttributes != null)
                    {
                        foreach (var attribute in AvailableAttributes)
                        {
                            string controlId = "filter_" + attribute.Id.ToString();
                            var    control   = attribute.FieldType.Field.FilterControl(attribute.QualifierValues, controlId, false, Rock.Reporting.FilterMode.SimpleFilter);
                            if (control != null)
                            {
                                if (control is IRockControl)
                                {
                                    var rockControl = (IRockControl)control;
                                    rockControl.Label = attribute.Name;
                                    rockControl.Help  = attribute.Description;
                                    phAttributeFilters.Controls.Add(control);
                                }
                                else
                                {
                                    var wrapper = new RockControlWrapper();
                                    wrapper.ID    = control.ID + "_wrapper";
                                    wrapper.Label = attribute.Name;
                                    wrapper.Controls.Add(control);
                                    phAttributeFilters.Controls.Add(wrapper);
                                }

                                if (setValues && searchSelections.ContainsKey(controlId))
                                {
                                    var values = searchSelections[controlId].FromJsonOrNull <List <string> >();
                                    attribute.FieldType.Field.SetFilterValues(control, attribute.QualifierValues, values);
                                }
                            }
                        }
                    }
                }
                else
                {
                    phAttributeFilters.Visible = false;
                }
            }
        }
Ejemplo n.º 49
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 )
        {
            ConnectionType connectionType;
            using ( var rockContext = new RockContext() )
            {
                if ( StatusesState.Any( s => s.IsDefault ) && ActivityTypesState.Any() )
                {
                    ConnectionTypeService connectionTypeService = new ConnectionTypeService( rockContext );
                    ConnectionActivityTypeService connectionActivityTypeService = new ConnectionActivityTypeService( rockContext );
                    ConnectionStatusService connectionStatusService = new ConnectionStatusService( rockContext );
                    ConnectionWorkflowService connectionWorkflowService = new ConnectionWorkflowService( rockContext );
                    AttributeService attributeService = new AttributeService( rockContext );
                    AttributeQualifierService qualifierService = new AttributeQualifierService( rockContext );

                    int connectionTypeId = int.Parse( hfConnectionTypeId.Value );

                    if ( connectionTypeId == 0 )
                    {
                        connectionType = new ConnectionType();
                        connectionTypeService.Add( connectionType );
                    }
                    else
                    {
                        connectionType = connectionTypeService.Queryable( "ConnectionActivityTypes, ConnectionWorkflows" ).Where( c => c.Id == connectionTypeId ).FirstOrDefault();

                        var uiWorkflows = WorkflowsState.Select( l => l.Guid );
                        foreach ( var connectionWorkflow in connectionType.ConnectionWorkflows.Where( l => !uiWorkflows.Contains( l.Guid ) ).ToList() )
                        {
                            connectionType.ConnectionWorkflows.Remove( connectionWorkflow );
                            connectionWorkflowService.Delete( connectionWorkflow );
                        }

                        var uiActivityTypes = ActivityTypesState.Select( r => r.Guid );
                        foreach ( var connectionActivityType in connectionType.ConnectionActivityTypes.Where( r => !uiActivityTypes.Contains( r.Guid ) ).ToList() )
                        {
                            connectionType.ConnectionActivityTypes.Remove( connectionActivityType );
                            connectionActivityTypeService.Delete( connectionActivityType );
                        }

                        var uiStatuses = StatusesState.Select( r => r.Guid );
                        foreach ( var connectionStatus in connectionType.ConnectionStatuses.Where( r => !uiStatuses.Contains( r.Guid ) ).ToList() )
                        {
                            connectionType.ConnectionStatuses.Remove( connectionStatus );
                            connectionStatusService.Delete( connectionStatus );
                        }
                    }

                    connectionType.Name = tbName.Text;
                    connectionType.Description = tbDescription.Text;
                    connectionType.IconCssClass = tbIconCssClass.Text;
                    connectionType.DaysUntilRequestIdle = nbDaysUntilRequestIdle.Text.AsInteger();
                    connectionType.EnableFutureFollowup = cbFutureFollowUp.Checked;
                    connectionType.EnableFullActivityList = cbFullActivityList.Checked;
                    connectionType.RequiresPlacementGroupToConnect = cbRequiresPlacementGroup.Checked;

                    foreach ( var connectionActivityTypeState in ActivityTypesState )
                    {
                        ConnectionActivityType connectionActivityType = connectionType.ConnectionActivityTypes.Where( a => a.Guid == connectionActivityTypeState.Guid ).FirstOrDefault();
                        if ( connectionActivityType == null )
                        {
                            connectionActivityType = new ConnectionActivityType();
                            connectionType.ConnectionActivityTypes.Add( connectionActivityType );
                        }

                        connectionActivityType.CopyPropertiesFrom( connectionActivityTypeState );
                    }

                    foreach ( var connectionStatusState in StatusesState )
                    {
                        ConnectionStatus connectionStatus = connectionType.ConnectionStatuses.Where( a => a.Guid == connectionStatusState.Guid ).FirstOrDefault();
                        if ( connectionStatus == null )
                        {
                            connectionStatus = new ConnectionStatus();
                            connectionType.ConnectionStatuses.Add( connectionStatus );
                        }

                        connectionStatus.CopyPropertiesFrom( connectionStatusState );
                        connectionStatus.ConnectionTypeId = connectionType.Id;
                    }

                    foreach ( ConnectionWorkflow connectionWorkflowState in WorkflowsState )
                    {
                        ConnectionWorkflow connectionWorkflow = connectionType.ConnectionWorkflows.Where( a => a.Guid == connectionWorkflowState.Guid ).FirstOrDefault();
                        if ( connectionWorkflow == null )
                        {
                            connectionWorkflow = new ConnectionWorkflow();
                            connectionType.ConnectionWorkflows.Add( connectionWorkflow );
                        }
                        else
                        {
                            connectionWorkflowState.Id = connectionWorkflow.Id;
                            connectionWorkflowState.Guid = connectionWorkflow.Guid;
                        }

                        connectionWorkflow.CopyPropertiesFrom( connectionWorkflowState );
                        connectionWorkflow.ConnectionTypeId = connectionTypeId;
                    }

                    if ( !connectionType.IsValid )
                    {
                        // Controls will render the error messages
                        return;
                    }

                    // need WrapTransaction due to Attribute saves
                    rockContext.WrapTransaction( () =>
                    {
                        rockContext.SaveChanges();

                        /* Save Attributes */
                        string qualifierValue = connectionType.Id.ToString();
                        SaveAttributes( new ConnectionOpportunity().TypeId, "ConnectionTypeId", qualifierValue, AttributesState, rockContext );

                        connectionType = connectionTypeService.Get( connectionType.Id );
                        if ( connectionType != null )
                        {
                            if ( !connectionType.IsAuthorized( Authorization.VIEW, CurrentPerson ) )
                            {
                                connectionType.AllowPerson( Authorization.VIEW, CurrentPerson, rockContext );
                            }

                            if ( !connectionType.IsAuthorized( Authorization.EDIT, CurrentPerson ) )
                            {
                                connectionType.AllowPerson( Authorization.EDIT, CurrentPerson, rockContext );
                            }

                            if ( !connectionType.IsAuthorized( Authorization.ADMINISTRATE, CurrentPerson ) )
                            {
                                connectionType.AllowPerson( Authorization.ADMINISTRATE, CurrentPerson, rockContext );
                            }
                        }
                    } );

                    ConnectionWorkflowService.FlushCachedTriggers();

                    var qryParams = new Dictionary<string, string>();
                    qryParams["ConnectionTypeId"] = connectionType.Id.ToString();

                    NavigateToPage( RockPage.Guid, qryParams );
                }
                else
                {
                    nbRequired.Visible = true;
                }
            }
        }