Ejemplo n.º 1
0
        /// <summary>
        /// Shows the edit details.
        /// </summary>
        /// <param name="event">The event.</param>
        private void ShowEditDetails(FollowingEventType followingEvent)
        {
            if (followingEvent.Id == 0)
            {
                lActionTitle.Text = ActionTitle.Add(FollowingEventType.FriendlyTypeName).FormatAsHtmlTitle();
            }
            else
            {
                lActionTitle.Text = followingEvent.Name.FormatAsHtmlTitle();
            }

            hlInactive.Visible = !followingEvent.IsActive;

            SetEditMode(true);

            tbName.Text        = followingEvent.Name;
            cbIsActive.Checked = followingEvent.IsActive;
            tbDescription.Text = followingEvent.Description;
            cpEventType.SetValue(followingEvent.EntityType != null ? followingEvent.EntityType.Guid.ToString().ToUpper() : string.Empty);
            cbSendOnFriday.Checked        = !followingEvent.SendOnWeekends;
            cbRequireNotification.Checked = followingEvent.IsNoticeRequired;
            ceNotificationFormat.Text     = followingEvent.EntityNotificationFormatLava;

            BuildDynamicControls(followingEvent, true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Determines whether [has event happened] [the specified entity].
        /// </summary>
        /// <param name="followingEvent">The following event.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="lastNotified">The last notified.</param>
        /// <returns></returns>
        public override bool HasEventHappened(FollowingEventType followingEvent, IEntity entity, DateTime?lastNotified)
        {
            if (followingEvent != null && entity != null)
            {
                int daysBack    = GetAttributeValue(followingEvent, "MaxDaysBack").AsInteger();
                var processDate = RockDateTime.Today;

                // This is DayOfWeek.Monday vs RockDateTime.FirstDayOfWeek because it including stuff that happened on the weekend (Saturday and Sunday) when it the first Non-Weekend Day (Monday)
                if (!followingEvent.SendOnWeekends && processDate.DayOfWeek == DayOfWeek.Monday)
                {
                    daysBack += 2;
                }

                var cutoffDateTime = processDate.AddDays(0 - daysBack);
                if (lastNotified.HasValue && lastNotified.Value > cutoffDateTime)
                {
                    cutoffDateTime = lastNotified.Value;
                }

                var personAlias = entity as PersonAlias;
                if (personAlias != null && personAlias.Person != null)
                {
                    if (followingEvent.IncludeNonPublicRequests)
                    {
                        return(HasPublicOrPrivatePrayerRequest(personAlias, cutoffDateTime));
                    }
                    else
                    {
                        return(HasPublicPrayerRequest(personAlias, cutoffDateTime));
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 3
0
        private void BuildDynamicControls(FollowingEventType followingEvent, bool SetValues)
        {
            if (SetValues)
            {
                EventEntityTypeId = followingEvent.EntityTypeId;
                if (followingEvent.EntityTypeId.HasValue)
                {
                    var EventComponentEntityType = EntityTypeCache.Get(followingEvent.EntityTypeId.Value);
                    var EventEntityType          = EntityTypeCache.Get("Rock.Model.FollowingEventType");
                    if (EventComponentEntityType != null && EventEntityType != null)
                    {
                        using (var rockContext = new RockContext())
                        {
                            Rock.Attribute.Helper.UpdateAttributes(EventComponentEntityType.GetEntityType(), EventEntityType.Id, "EntityTypeId", EventComponentEntityType.Id.ToString(), rockContext);
                        }
                    }
                }
            }

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

            phAttributes.Controls.Clear();
            Rock.Attribute.Helper.AddEditControls(followingEvent, phAttributes, SetValues, BlockValidationGroup, new List <string> {
                "Active", "Order"
            });
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Shows the readonly details.
        /// </summary>
        /// <param name="event">The event.</param>
        private void ShowReadonlyDetails(FollowingEventType followingEvent)
        {
            SetEditMode(false);

            lActionTitle.Text      = followingEvent.Name.FormatAsHtmlTitle();
            hlInactive.Visible     = !followingEvent.IsActive;
            lEventDescription.Text = followingEvent.Description;

            DescriptionList descriptionList = new DescriptionList();

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

            descriptionList.Add("Require Notification", followingEvent.IsNoticeRequired ? "Yes" : "No");
            descriptionList.Add("Send Weekend Notices on Friday", followingEvent.SendOnWeekends ? "No" : "Yes");

            var eventEntityTypeGuid = EntityTypeCache.Get(followingEvent.EntityType.Id).Guid.ToString();

            if (followingEvent.EntityType != null && string.Equals(eventEntityTypeGuid, Rock.SystemGuid.EntityType.PERSON_PRAYER_REQUEST, StringComparison.OrdinalIgnoreCase))
            {
                descriptionList.Add("Include Non-Public Requests", followingEvent.IncludeNonPublicRequests ? "Yes" : "No");
            }

            lblMainDetails.Text = descriptionList.Html;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Handles the SelectedIndexChanged event of the cpEventType 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 cpEventType_SelectedIndexChanged(object sender, EventArgs e)
        {
            var followingEvent = new FollowingEventType {
                Id = EventId, EntityTypeId = cpEventType.SelectedEntityTypeId
            };

            BuildDynamicControls(followingEvent, true);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            using (var rockContext = new RockContext())
            {
                FollowingEventType followingEvent = null;

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

                if (EventId != 0)
                {
                    followingEvent = eventService.Get(EventId);
                }

                if (followingEvent == null)
                {
                    followingEvent = new Rock.Model.FollowingEventType();
                    eventService.Add(followingEvent);
                }

                followingEvent.Name           = tbName.Text;
                followingEvent.IsActive       = cbIsActive.Checked;
                followingEvent.Description    = tbDescription.Text;
                followingEvent.EntityTypeId   = cpEventType.SelectedEntityTypeId;
                followingEvent.SendOnWeekends = !cbSendOnFriday.Checked;

                var eventEntityTypeGuid = EntityTypeCache.Get(cpEventType.SelectedEntityTypeId.Value).Guid.ToString();
                if (string.Equals(eventEntityTypeGuid, Rock.SystemGuid.EntityType.PERSON_PRAYER_REQUEST, StringComparison.OrdinalIgnoreCase))
                {
                    followingEvent.IncludeNonPublicRequests = cbIncludeNonPublicRequests.Checked;
                }

                followingEvent.IsNoticeRequired             = cbRequireNotification.Checked;
                followingEvent.EntityNotificationFormatLava = ceNotificationFormat.Text;

                followingEvent.FollowedEntityTypeId = null;
                var eventComponent = followingEvent.GetEventComponent();
                if (eventComponent != null)
                {
                    var followedEntityType = EntityTypeCache.Get(eventComponent.FollowedType);
                    if (followedEntityType != null)
                    {
                        followingEvent.FollowedEntityTypeId = followedEntityType.Id;
                    }
                }

                rockContext.SaveChanges();

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

            NavigateToParentPage();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Formats the entity notification.
        /// </summary>
        /// <param name="followingEvent">The following event.</param>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public virtual string FormatEntityNotification(FollowingEventType followingEvent, IEntity entity)
        {
            if (followingEvent != null)
            {
                var mergeFields = new Dictionary <string, object>();
                mergeFields.Add("Entity", entity);
                return(followingEvent.EntityNotificationFormatLava.ResolveMergeFields(mergeFields));
            }

            return(string.Empty);
        }
Ejemplo n.º 8
0
        protected override void LoadViewState(object savedState)
        {
            base.LoadViewState(savedState);

            EventId           = ViewState["EventId"] as int? ?? 0;
            EventEntityTypeId = ViewState["EventEntityTypeId"] as int?;

            var followingEvent = new FollowingEventType {
                Id = EventId, EntityTypeId = EventEntityTypeId
            };

            BuildDynamicControls(followingEvent, false);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Determines whether [has event happened] [the specified entity].
        /// </summary>
        /// <param name="followingEvent">The following event.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="lastNotified">The last notified.</param>
        /// <returns></returns>
        public override bool HasEventHappened(FollowingEventType followingEvent, IEntity entity, DateTime?lastNotified)
        {
            if (followingEvent != null && entity != null)
            {
                var personAlias = entity as PersonAlias;
                if (personAlias != null && personAlias.Person != null)
                {
                    var      person       = personAlias.Person;
                    DateTime?nextBirthDay = person.NextBirthDay;
                    if (nextBirthDay.HasValue)
                    {
                        int leadDays = GetAttributeValue(followingEvent, "LeadDays").AsInteger();

                        var today       = RockDateTime.Today;
                        var processDate = today;
                        if (!followingEvent.SendOnWeekends && nextBirthDay.Value.Date != today)
                        {
                            switch (today.DayOfWeek)
                            {
                            case DayOfWeek.Friday:
                                leadDays += 2;
                                break;

                            case DayOfWeek.Saturday:
                                processDate = processDate.AddDays(-1);
                                leadDays   += 2;
                                break;

                            case DayOfWeek.Sunday:
                                processDate = processDate.AddDays(-2);
                                leadDays   += 2;
                                break;
                            }
                        }

                        if ((nextBirthDay.Value.Subtract(processDate).Days <= leadDays) &&
                            (!lastNotified.HasValue || nextBirthDay.Value.Subtract(lastNotified.Value.Date).Days > leadDays))
                        {
                            // If leaddays is greater than zero, ignore any birthdays for today
                            if (leadDays > 0 && nextBirthDay.Value.Date == RockDateTime.Today)
                            {
                                return(false);
                            }
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Determines whether [has event happened] [the specified entity].
        /// </summary>
        /// <param name="followingEvent">The following event.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="lastNotified">The last notified.</param>
        /// <returns></returns>
        public override bool HasEventHappened(FollowingEventType followingEvent, IEntity entity, DateTime?lastNotified)
        {
            if (followingEvent != null && entity != null)
            {
                var personAlias = entity as PersonAlias;
                if (personAlias != null && personAlias.Person != null)
                {
                    var      person          = personAlias.Person;
                    DateTime?nextAnniversary = person.NextAnniversary;
                    if (person.AnniversaryDate.HasValue && nextAnniversary.HasValue)
                    {
                        int yearMultiplier = GetAttributeValue(followingEvent, "NthYear").AsInteger();
                        if (yearMultiplier == 0 || (nextAnniversary.Value.Year - person.AnniversaryDate.Value.Year) % yearMultiplier == 0)
                        {
                            int leadDays = GetAttributeValue(followingEvent, "LeadDays").AsInteger();

                            var today       = RockDateTime.Today;
                            var processDate = today;
                            if (!followingEvent.SendOnWeekends)
                            {
                                switch (today.DayOfWeek)
                                {
                                case DayOfWeek.Friday:
                                    leadDays += 2;
                                    break;

                                case DayOfWeek.Saturday:
                                    processDate = processDate.AddDays(-1);
                                    leadDays   += 2;
                                    break;

                                case DayOfWeek.Sunday:
                                    processDate = processDate.AddDays(-2);
                                    leadDays   += 2;
                                    break;
                                }
                            }

                            if ((nextAnniversary.Value.Subtract(processDate).Days <= leadDays) &&
                                (!lastNotified.HasValue || nextAnniversary.Value.Subtract(lastNotified.Value.Date).Days > leadDays))
                            {
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Determines whether [has event happened] [the specified entity].
        /// </summary>
        /// <param name="followingEvent">The following event.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="lastNotified">The last notified.</param>
        /// <returns></returns>
        public override bool HasEventHappened( FollowingEventType followingEvent, IEntity entity, DateTime? lastNotified )
        {
            if ( followingEvent != null && entity != null )
            {
                var personAlias = entity as PersonAlias;
                if ( personAlias != null && personAlias.Person != null )
                {
                    var person = personAlias.Person;
                    DateTime? nextBirthDay = person.NextBirthDay;
                    if ( nextBirthDay.HasValue )
                    {
                        int leadDays = GetAttributeValue( followingEvent, "LeadDays" ).AsInteger();

                        var today = RockDateTime.Today;
                        var processDate = today;
                        if ( !followingEvent.SendOnWeekends )
                        {
                            switch ( today.DayOfWeek )
                            {
                                case DayOfWeek.Friday:
                                    leadDays += 2;
                                    break;
                                case DayOfWeek.Saturday:
                                    processDate = processDate.AddDays( -1 );
                                    leadDays += 2;
                                    break;
                                case DayOfWeek.Sunday:
                                    processDate = processDate.AddDays( -2 );
                                    leadDays += 2;
                                    break;
                            }
                        }

                        if ( ( nextBirthDay.Value.Subtract( processDate ).Days <= leadDays ) &&
                            ( !lastNotified.HasValue || nextBirthDay.Value.Subtract( lastNotified.Value.Date ).Days > leadDays ) )
                        {
                            // If leaddays is greater than zero, ignore any birthdays for today
                            if ( leadDays > 0 && nextBirthDay.Value.Date == RockDateTime.Today )
                            {
                                return false;
                            }
                            return true;
                        }
                    }
                }
            }

            return false;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Determines whether [has event happened] [the specified entity].
        /// </summary>
        /// <param name="followingEvent">The following event.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="lastNotified">The last notified.</param>
        /// <returns></returns>
        public override bool HasEventHappened( FollowingEventType followingEvent, IEntity entity, DateTime? lastNotified )
        {
            if ( followingEvent != null && entity != null )
            {
                var personAlias = entity as PersonAlias;
                if ( personAlias != null && personAlias.Person != null )
                {
                    var person = personAlias.Person;
                    DateTime? nextAnniversary = person.NextAnniversary;
                    if ( person.AnniversaryDate.HasValue && nextAnniversary.HasValue )
                    {
                        int yearMultiplier = GetAttributeValue( followingEvent, "NthYear" ).AsInteger();
                        if ( yearMultiplier == 0 || ( nextAnniversary.Value.Year - person.AnniversaryDate.Value.Year ) % yearMultiplier == 0 )
                        {
                            int leadDays = GetAttributeValue( followingEvent, "LeadDays" ).AsInteger();

                            var today = RockDateTime.Today;
                            var processDate = today;
                            if ( !followingEvent.SendOnWeekends )
                            {
                                switch ( today.DayOfWeek )
                                {
                                    case DayOfWeek.Friday:
                                        leadDays += 2;
                                        break;
                                    case DayOfWeek.Saturday:
                                        processDate = processDate.AddDays( -1 );
                                        leadDays += 2;
                                        break;
                                    case DayOfWeek.Sunday:
                                        processDate = processDate.AddDays( -2 );
                                        leadDays += 2;
                                        break;
                                }
                            }

                            if ( ( nextAnniversary.Value.Subtract( processDate ).Days <= leadDays ) &&
                                ( !lastNotified.HasValue || nextAnniversary.Value.Subtract( lastNotified.Value.Date ).Days > leadDays ) )
                            {
                                return true;
                            }
                        }
                    }
                }
            }

            return false;
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            using (var rockContext = new RockContext())
            {
                FollowingEventType followingEvent = null;

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

                if (EventId != 0)
                {
                    followingEvent = eventService.Get(EventId);
                }

                if (followingEvent == null)
                {
                    followingEvent = new Rock.Model.FollowingEventType();
                    eventService.Add(followingEvent);
                }

                followingEvent.Name                         = tbName.Text;
                followingEvent.IsActive                     = cbIsActive.Checked;
                followingEvent.Description                  = tbDescription.Text;
                followingEvent.EntityTypeId                 = cpEventType.SelectedEntityTypeId;
                followingEvent.SendOnWeekends               = !cbSendOnFriday.Checked;
                followingEvent.IsNoticeRequired             = cbRequireNotification.Checked;
                followingEvent.EntityNotificationFormatLava = ceNotificationFormat.Text;

                followingEvent.FollowedEntityTypeId = null;
                var eventComponent = followingEvent.GetEventComponent();
                if (eventComponent != null)
                {
                    var followedEntityType = EntityTypeCache.Get(eventComponent.FollowedType);
                    if (followedEntityType != null)
                    {
                        followingEvent.FollowedEntityTypeId = followedEntityType.Id;
                    }
                }

                rockContext.SaveChanges();

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

            NavigateToParentPage();
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Determines whether [has event happened] [the specified entity].
        /// </summary>
        /// <param name="followingEvent">The following event.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="lastNotified">The last notified.</param>
        /// <returns></returns>
        public override bool HasEventHappened(FollowingEventType followingEvent, IEntity entity, DateTime?lastNotified)
        {
            if (lastNotified.HasValue)
            {
                return(false);
            }

            Guid?groupTypeGuid = GetAttributeValue(followingEvent, "GroupType").AsGuidOrNull();

            if (followingEvent != null && entity != null && groupTypeGuid.HasValue)
            {
                var personAlias = entity as PersonAlias;
                if (personAlias != null && personAlias.Person != null)
                {
                    var person = personAlias.Person;

                    DateTime?firstAttended = new AttendanceService(new RockContext())
                                             .Queryable().AsNoTracking()
                                             .Where(a =>
                                                    a.DidAttend.HasValue &&
                                                    a.DidAttend.Value &&
                                                    a.PersonAlias != null &&
                                                    a.PersonAlias.PersonId == personAlias.PersonId &&
                                                    a.Group != null &&
                                                    a.Group.GroupType.Guid.Equals(groupTypeGuid.Value))
                                             .Min(a => a.StartDateTime);

                    if (firstAttended.HasValue)
                    {
                        int daysBack    = GetAttributeValue(followingEvent, "MaxDaysBack").AsInteger();
                        var processDate = RockDateTime.Today;
                        if (!followingEvent.SendOnWeekends && RockDateTime.Today.DayOfWeek == DayOfWeek.Friday)
                        {
                            daysBack += 2;
                        }

                        if (processDate.Subtract(firstAttended.Value).Days < daysBack)
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Determines whether [has event happened] [the specified entity].
        /// </summary>
        /// <param name="followingEvent">The following event.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="lastNotified">The last notified.</param>
        /// <returns></returns>
        public override bool HasEventHappened( FollowingEventType followingEvent, IEntity entity, DateTime? lastNotified )
        {
            if ( lastNotified.HasValue )
            {
                return false;
            }

            Guid? groupTypeGuid = GetAttributeValue( followingEvent, "GroupType" ).AsGuidOrNull();
            if ( followingEvent != null && entity != null && groupTypeGuid.HasValue )
            {
                var personAlias = entity as PersonAlias;
                if ( personAlias != null && personAlias.Person != null )
                {
                    var person = personAlias.Person;

                    DateTime? firstAttended = new AttendanceService( new RockContext() )
                        .Queryable().AsNoTracking()
                        .Where( a =>
                            a.DidAttend.HasValue &&
                            a.DidAttend.Value &&
                            a.PersonAlias != null &&
                            a.PersonAlias.PersonId == personAlias.PersonId &&
                            a.Group != null &&
                            a.Group.GroupType.Guid.Equals( groupTypeGuid.Value ) )
                        .Min( a => a.StartDateTime );

                    if ( firstAttended.HasValue )
                    {
                        int daysBack = GetAttributeValue( followingEvent, "MaxDaysBack" ).AsInteger();
                        var processDate = RockDateTime.Today;
                        if ( !followingEvent.SendOnWeekends && RockDateTime.Today.DayOfWeek == DayOfWeek.Friday )
                        {
                            daysBack += 2;
                        }

                        if ( processDate.Subtract( firstAttended.Value ).Days < daysBack )
                        {
                            return true;
                        }
                    }
                }
            }

            return false;
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Determines whether the event has happened for the entity.
        /// </summary>
        /// <param name="followingEvent">The following event.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="lastNotified">The last notified.</param>
        /// <returns></returns>
        public override bool HasEventHappened(FollowingEventType followingEvent, IEntity entity, DateTime?lastNotified)
        {
            if (lastNotified.HasValue)
            {
                return(false);
            }

            var currentlyAnEraAttribute = AttributeCache.Read(GetAttributeValue(followingEvent, "CurrentlyaneRAAttribute").AsGuid());
            var eraStartDateAttribute   = AttributeCache.Read(GetAttributeValue(followingEvent, "eRAStartDateAttribute").AsGuid());

            if (followingEvent != null && entity != null && currentlyAnEraAttribute != null && eraStartDateAttribute != null)
            {
                var personAlias = entity as PersonAlias;
                if (personAlias != null && personAlias.Person != null)
                {
                    var person = personAlias.Person;

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

                    bool     currentlyAnEra = person.GetAttributeValue(currentlyAnEraAttribute.Key).AsBoolean(false);
                    DateTime?date           = person.GetAttributeValue(eraStartDateAttribute.Key).AsDateTime();

                    if (currentlyAnEra && date.HasValue)
                    {
                        int daysBack    = GetAttributeValue(followingEvent, "MaxDaysBack").AsInteger();
                        var processDate = RockDateTime.Today;
                        if (!followingEvent.SendOnWeekends && RockDateTime.Today.DayOfWeek == DayOfWeek.Friday)
                        {
                            daysBack += 2;
                        }

                        if (processDate.Subtract(date.Value).Days < daysBack)
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="eventId">The event identifier.</param>
        public void ShowDetail(int eventId)
        {
            FollowingEventType followingEvent = null;

            bool editAllowed = IsUserAuthorized(Authorization.EDIT);

            if (!eventId.Equals(0))
            {
                followingEvent = new FollowingEventTypeService(new RockContext()).Get(eventId);
                editAllowed    = editAllowed || followingEvent.IsAuthorized(Authorization.EDIT, CurrentPerson);
                pdAuditDetails.SetEntity(followingEvent, ResolveRockUrl("~"));
            }

            if (followingEvent == null)
            {
                followingEvent = new FollowingEventType {
                    Id = 0, IsActive = true
                };
                // hide the panel drawer that show created and last modified dates
                pdAuditDetails.Visible = false;
            }

            EventId = followingEvent.Id;

            bool readOnly = false;

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

            if (readOnly)
            {
                ShowReadonlyDetails(followingEvent);
            }
            else
            {
                ShowEditDetails(followingEvent);
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Gets the attribute value for the event
        /// </summary>
        /// <param name="followingEvent">The following event.</param>
        /// <param name="key">The key.</param>
        /// <returns></returns>
        protected string GetAttributeValue(FollowingEventType followingEvent, string key)
        {
            if (followingEvent.AttributeValues == null)
            {
                followingEvent.LoadAttributes();
            }

            var values = followingEvent.AttributeValues;

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

            return(string.Empty);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Shows the readonly details.
        /// </summary>
        /// <param name="event">The event.</param>
        private void ShowReadonlyDetails(FollowingEventType followingEvent)
        {
            SetEditMode(false);

            lActionTitle.Text      = followingEvent.Name.FormatAsHtmlTitle();
            hlInactive.Visible     = !followingEvent.IsActive;
            lEventDescription.Text = followingEvent.Description;

            DescriptionList descriptionList = new DescriptionList();

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

            descriptionList.Add("Require Notification", followingEvent.IsNoticeRequired ? "Yes" : "No");
            descriptionList.Add("Send Weekend Notices on Friday", followingEvent.SendOnWeekends ? "No" : "Yes");

            lblMainDetails.Text = descriptionList.Html;
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Determines whether [has event happened] [the specified entity].
        /// </summary>
        /// <param name="followingEvent">The following event.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="lastNotified">The last notified.</param>
        /// <returns></returns>
        public override bool HasEventHappened(FollowingEventType followingEvent, IEntity entity, DateTime?lastNotified)
        {
            if (followingEvent != null && entity != null)
            {
                int daysBack    = GetAttributeValue(followingEvent, "MaxDaysBack").AsInteger();
                var processDate = RockDateTime.Today;

                // This is DayOfWeek.Monday vs RockDateTime.FirstDayOfWeek because it including stuff that happened on the weekend (Saturday and Sunday) when it the first Non-Weekend Day (Monday)
                if (!followingEvent.SendOnWeekends && processDate.DayOfWeek == DayOfWeek.Monday)
                {
                    daysBack += 2;
                }

                var cuttoffDateTime = processDate.AddDays(0 - daysBack);
                if (lastNotified.HasValue && lastNotified.Value > cuttoffDateTime)
                {
                    cuttoffDateTime = lastNotified.Value;
                }

                var personAlias = entity as PersonAlias;
                if (personAlias != null && personAlias.Person != null)
                {
                    using (var rockContext = new RockContext())
                    {
                        return(new PrayerRequestService(rockContext)
                               .Queryable().AsNoTracking()
                               .Any(r =>
                                    r.RequestedByPersonAlias != null &&
                                    r.RequestedByPersonAlias.PersonId == personAlias.PersonId &&
                                    r.ApprovedOnDateTime.HasValue &&
                                    r.ApprovedOnDateTime.Value >= cuttoffDateTime &&
                                    r.IsApproved.HasValue &&
                                    r.IsApproved.Value &&
                                    r.IsPublic.HasValue &&
                                    r.IsPublic.Value));
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Determines whether [has event happened] [the specified entity].
        /// </summary>
        /// <param name="followingEvent">The following event.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="lastNotified">The last notified.</param>
        /// <returns></returns>
        public override bool HasEventHappened(FollowingEventType followingEvent, IEntity entity, DateTime?lastNotified)
        {
            if (lastNotified.HasValue)
            {
                return(false);
            }

            if (followingEvent != null && entity != null)
            {
                var personAlias = entity as PersonAlias;
                if (personAlias != null && personAlias.Person != null)
                {
                    var person = personAlias.Person;

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

                    DateTime?baptismDate = person.GetAttributeValue("BaptismDate").AsDateTime();
                    if (baptismDate.HasValue)
                    {
                        int daysBack         = GetAttributeValue(followingEvent, "MaxDaysBack").AsInteger();
                        int anniversaryCount = GetAttributeValue(followingEvent, "AnniversaryCount").AsIntegerOrNull() ?? 0;
                        var processDate      = RockDateTime.Today.AddYears(-anniversaryCount);
                        if (!followingEvent.SendOnWeekends && RockDateTime.Today.DayOfWeek == DayOfWeek.Friday)
                        {
                            daysBack += 2;
                        }

                        var daysSince = processDate.Subtract(baptismDate.Value).Days;
                        if (daysSince >= 0 && daysSince < daysBack)
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="eventId">The event identifier.</param>
        public void ShowDetail( int eventId )
        {
            FollowingEventType followingEvent = null;

            bool editAllowed = IsUserAuthorized( Authorization.EDIT );

            if ( !eventId.Equals( 0 ) )
            {
                followingEvent = new FollowingEventTypeService( new RockContext() ).Get( eventId );
                editAllowed = editAllowed || followingEvent.IsAuthorized( Authorization.EDIT, CurrentPerson );
                pdAuditDetails.SetEntity( followingEvent, ResolveRockUrl( "~" ) );
            }

            if ( followingEvent == null )
            {
                followingEvent = new FollowingEventType { Id = 0, IsActive = true };
                // hide the panel drawer that show created and last modified dates
                pdAuditDetails.Visible = false;
            }

            EventId = followingEvent.Id;

            bool readOnly = false;

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

            if ( readOnly )
            {
                ShowReadonlyDetails( followingEvent );
            }
            else
            {
                ShowEditDetails( followingEvent );
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Determines whether [has event happened] [the specified entity].
        /// </summary>
        /// <param name="followingEvent">The following event.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="lastNotified">The last notified.</param>
        /// <returns></returns>
        public override bool HasEventHappened( FollowingEventType followingEvent, IEntity entity, DateTime? lastNotified )
        {
            if ( lastNotified.HasValue )
            {
                return false;
            }

            if ( followingEvent != null && entity != null )
            {
                var personAlias = entity as PersonAlias;
                if ( personAlias != null && personAlias.Person != null )
                {
                    var person = personAlias.Person;

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

                    DateTime? baptismDate = person.GetAttributeValue( "BaptismDate" ).AsDateTime();
                    if ( baptismDate.HasValue )
                    {
                        int daysBack = GetAttributeValue( followingEvent, "MaxDaysBack" ).AsInteger();
                        var processDate = RockDateTime.Today;
                        if ( !followingEvent.SendOnWeekends && RockDateTime.Today.DayOfWeek == DayOfWeek.Friday )
                        {
                            daysBack += 2;
                        }

                        if ( processDate.Subtract( baptismDate.Value ).Days < daysBack )
                        {
                            return true;
                        }
                    }
                }
            }

            return false;
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="eventId">The event identifier.</param>
        public void ShowDetail(int eventId)
        {
            FollowingEventType followingEvent = null;

            bool editAllowed = IsUserAuthorized(Authorization.EDIT);

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

            if (followingEvent == null)
            {
                followingEvent = new FollowingEventType {
                    Id = 0, IsActive = true
                };
            }

            EventId = followingEvent.Id;

            bool readOnly = false;

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

            if (readOnly)
            {
                ShowReadonlyDetails(followingEvent);
            }
            else
            {
                ShowEditDetails(followingEvent);
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Shows the edit details.
        /// </summary>
        /// <param name="event">The event.</param>
        private void ShowEditDetails(FollowingEventType followingEvent)
        {
            if (followingEvent.Id == 0)
            {
                lActionTitle.Text = ActionTitle.Add(FollowingEventType.FriendlyTypeName).FormatAsHtmlTitle();
            }
            else
            {
                lActionTitle.Text = followingEvent.Name.FormatAsHtmlTitle();
            }

            hlInactive.Visible = !followingEvent.IsActive;

            SetEditMode(true);

            tbName.Text        = followingEvent.Name;
            cbIsActive.Checked = followingEvent.IsActive;
            tbDescription.Text = followingEvent.Description;
            cpEventType.SetValue(followingEvent.EntityType != null ? followingEvent.EntityType.Guid.ToString().ToUpper() : string.Empty);
            cbSendOnFriday.Checked             = !followingEvent.SendOnWeekends;
            cbIncludeNonPublicRequests.Visible = false;
            cbIncludeNonPublicRequests.Checked = false;

            if (followingEvent.EntityType != null)
            {
                var eventEntityTypeGuid = EntityTypeCache.Get(followingEvent.EntityType.Id)?.Guid.ToString();
                if (string.Equals(eventEntityTypeGuid, Rock.SystemGuid.EntityType.PERSON_PRAYER_REQUEST, StringComparison.OrdinalIgnoreCase))
                {
                    cbIncludeNonPublicRequests.Visible = true;
                    cbIncludeNonPublicRequests.Checked = followingEvent.IncludeNonPublicRequests;
                }
            }

            cbRequireNotification.Checked = followingEvent.IsNoticeRequired;
            ceNotificationFormat.Text     = followingEvent.EntityNotificationFormatLava;

            BuildDynamicControls(followingEvent, true);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Handles the SelectedIndexChanged event of the cpEventType 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 cpEventType_SelectedIndexChanged(object sender, EventArgs e)
        {
            var followingEvent = new FollowingEventType {
                Id = EventId, EntityTypeId = cpEventType.SelectedEntityTypeId
            };

            if (cpEventType.SelectedEntityTypeId.HasValue)
            {
                var eventEntityTypeGuid = EntityTypeCache.Get(cpEventType.SelectedEntityTypeId.Value).Guid.ToString();
                if (string.Equals(eventEntityTypeGuid, Rock.SystemGuid.EntityType.PERSON_PRAYER_REQUEST, StringComparison.OrdinalIgnoreCase))
                {
                    cbIncludeNonPublicRequests.Visible = true;
                    cbIncludeNonPublicRequests.Checked = followingEvent.IncludeNonPublicRequests;
                }
                else
                {
                    cbIncludeNonPublicRequests.Visible = false;
                    cbIncludeNonPublicRequests.Checked = false;
                }
            }

            BuildDynamicControls(followingEvent, true);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="eventId">The event identifier.</param>
        public void ShowDetail( int eventId )
        {
            FollowingEventType followingEvent = null;

            bool editAllowed = IsUserAuthorized( Authorization.EDIT );

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

            if ( followingEvent == null )
            {
                followingEvent = new FollowingEventType { Id = 0, IsActive = true };
            }

            EventId = followingEvent.Id;

            bool readOnly = false;

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

            if ( readOnly )
            {
                ShowReadonlyDetails( followingEvent );
            }
            else
            {
                ShowEditDetails( followingEvent );
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Determines whether <see cref="PersonNoteAdded"/> has happened for <paramref name="entity"/> since <paramref name="lastNotified"/> date.
        /// This method will return a bool whether the aforementioned event(s) occurred.
        /// It will also output a dictionary including a list of Note Data POCOs that can be added to in the future.
        /// </summary>
        /// <param name="followingEvent">The following event.</param>
        /// <param name="entity">The entity being followed.</param>
        /// <param name="lastNotified">The last notified date.</param>
        /// <param name="followedEventObjects">The collection of the followed event's objects.</param>
        /// <returns>A bool representing whether the followed event(s) for the followed entity occurred since last notified.</returns>
        public bool HasEventHappened(FollowingEventType followingEvent, IEntity entity, DateTime?lastNotified, out Dictionary <string, List <object> > followedEventObjects)
        {
            followedEventObjects = new Dictionary <string, List <object> >();

            // If block is configured to only allow certain note types, limit notes to those types.
            var configuredNoteTypes = GetAttributeValue(followingEvent, AttributeKey.NoteTypes).SplitDelimitedValues().AsGuidList();

            var  personAlias = entity as PersonAlias;
            bool doEventEntityAndPersonHaveValues = followingEvent != null &&
                                                    entity != null &&
                                                    personAlias != null &&
                                                    personAlias.Person != null;

            if (doEventEntityAndPersonHaveValues)
            {
                var person = personAlias.Person;

                var newNotesForPersonSinceLastNotified = new NoteService(new RockContext())
                                                         .Queryable().AsNoTracking()
                                                         .Where(n =>
                                                                n.EntityId == personAlias.PersonId &&
                                                                !n.IsPrivateNote &&
                                                                (!lastNotified.HasValue || n.CreatedDateTime > lastNotified) &&
                                                                (configuredNoteTypes.Count() == 0 || configuredNoteTypes.Contains(n.NoteType.Guid))).ToList();

                if (newNotesForPersonSinceLastNotified.Any())
                {
                    followedEventObjects.Add("NoteData", new List <object>(newNotesForPersonSinceLastNotified.Select(n => new NoteData {
                        AddedBy = n.CreatedByPersonName, NoteType = n.NoteType.Name
                    })));
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Formats the entity notification with additional merge fields.
        /// </summary>
        /// <param name="followingEvent">The following event.</param>
        /// <param name="entity">The entity being followed.</param>
        /// <param name="additionalMergeFields">The collection of additional merge fields and values for the following event.</param>
        /// <returns>An HTML string from the Following Event (Lava formatted) to include in the notification email.</returns>
        public string FormatEntityNotification(FollowingEventType followingEvent, IEntity entity, Dictionary <string, List <object> > additionalMergeFields)
        {
            var sb = new StringBuilder();

            if (followingEvent != null)
            {
                var mergeFields = new Dictionary <string, object>();
                mergeFields.Add("Entity", entity);
                foreach (var mergeFieldPair in additionalMergeFields)
                {
                    // Add a new section to the email content for each note notification with merge fields.
                    foreach (var mergeFieldValue in mergeFieldPair.Value)
                    {
                        var noteData = mergeFieldValue as NoteData;
                        mergeFields.AddOrReplace(mergeFieldPair.Key, noteData);
                        sb.Append(followingEvent.EntityNotificationFormatLava.ResolveMergeFields(mergeFields));
                    }
                }

                return(sb.ToString());
            }

            return(string.Empty);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Formats the entity notification.
        /// </summary>
        /// <param name="followingEvent">The following event.</param>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public virtual string FormatEntityNotification( FollowingEventType followingEvent, IEntity entity )
        {
            if ( followingEvent != null )
            {
                var mergeFields = new Dictionary<string, object>();
                mergeFields.Add( "Entity", entity );
                return followingEvent.EntityNotificationFormatLava.ResolveMergeFields( mergeFields );
            }

            return string.Empty;
        }
Ejemplo n.º 31
0
 /// <summary>
 /// Determines whether [has event happened] [the specified entity].
 /// </summary>
 /// <param name="followingEvent">The following event.</param>
 /// <param name="entity">The entity.</param>
 /// <param name="lastNotified">The last notified.</param>
 /// <returns></returns>
 public abstract bool HasEventHappened( FollowingEventType followingEvent, IEntity entity, DateTime? lastNotified );
Ejemplo n.º 32
0
 /// <summary>
 /// Loads the attributes for the following event.
 /// </summary>
 /// <param name="followingEvent">The following event.</param>
 public void LoadAttributes( FollowingEventType followingEvent )
 {
     followingEvent.LoadAttributes();
 }
Ejemplo n.º 33
0
        /// <summary>
        /// Gets the attribute value for the event 
        /// </summary>
        /// <param name="followingEvent">The following event.</param>
        /// <param name="key">The key.</param>
        /// <returns></returns>
        protected string GetAttributeValue( FollowingEventType followingEvent, string key )
        {
            if ( followingEvent.AttributeValues == null )
            {
                followingEvent.LoadAttributes();
            }

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

            return string.Empty;
        }
Ejemplo n.º 34
0
        /// <summary>
        /// Determines whether [has event happened] [the specified entity].
        /// </summary>
        /// <param name="followingEvent">The following event.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="lastNotified">The last notified.</param>
        /// <returns></returns>
        public override bool HasEventHappened(FollowingEventType followingEvent, IEntity entity, DateTime?lastNotified)
        {
            if (followingEvent != null && entity != null)
            {
                var personAlias = entity as PersonAlias;

                if (personAlias != null && personAlias.Person != null)
                {
                    //
                    // Get all the attributes/settings we need.
                    //
                    int    daysBack         = GetAttributeValue(followingEvent, "MaxDaysBack").AsInteger();
                    string targetOldValue   = GetAttributeValue(followingEvent, "OldValue") ?? string.Empty;
                    string targetNewValue   = GetAttributeValue(followingEvent, "NewValue") ?? string.Empty;
                    string targetPersonGuid = GetAttributeValue(followingEvent, "Person");
                    bool   negateChangedBy  = GetAttributeValue(followingEvent, "NegatePerson").AsBoolean();
                    bool   matchBothValues  = GetAttributeValue(followingEvent, "MatchBoth").AsBoolean();
                    var    attributes       = GetAttributeValue(followingEvent, "Fields").Split(',').Select(a => a.Trim());

                    //
                    // Populate all the other random variables we need for processing.
                    //
                    PersonAlias targetPersonAlias  = new PersonAliasService(new RockContext()).Get(targetPersonGuid.AsGuid());
                    DateTime    daysBackDate       = RockDateTime.Now.AddDays(-daysBack);
                    var         person             = personAlias.Person;
                    int         personEntityTypeId = EntityTypeCache.Read(typeof(Person)).Id;
                    int         categoryId         = CategoryCache.Read(Rock.SystemGuid.Category.HISTORY_PERSON_DEMOGRAPHIC_CHANGES.AsGuid()).Id;

                    //
                    // Start building the basic query. We want all History items that are for
                    // people objects and use the Demographic Changes category.
                    //
                    var qry = new HistoryService(new RockContext()).Queryable()
                              .Where(h => h.EntityTypeId == personEntityTypeId && h.EntityId == person.Id && h.CategoryId == categoryId);

                    //
                    // Put in our limiting dates. We always limit by our days back date,
                    // and conditionally limit based on the last time we notified the
                    // stalker - I mean the follower.
                    //
                    if (lastNotified.HasValue)
                    {
                        qry = qry.Where(h => h.CreatedDateTime >= lastNotified.Value);
                    }
                    qry = qry.Where(h => h.CreatedDateTime >= daysBackDate);

                    //
                    // Walk each history item found that matches our filter.
                    //
                    Dictionary <string, List <HistoryChange> > changes = new Dictionary <string, List <HistoryChange> >();
                    foreach (var history in qry.ToList())
                    {
                        Match modified = Regex.Match(history.Summary, ModifiedRegex);
                        Match added    = Regex.Match(history.Summary, AddedRegex);
                        Match deleted  = Regex.Match(history.Summary, DeletedRegex);

                        //
                        // Walk each attribute entered by the user to match against.
                        //
                        foreach (var attribute in attributes)
                        {
                            HistoryChange change = new HistoryChange();
                            string        title  = null;

                            //
                            // Check what kind of change this was.
                            //
                            if (modified.Success)
                            {
                                title      = modified.Groups[1].Value;
                                change.Old = modified.Groups[2].Value;
                                change.New = modified.Groups[3].Value;
                            }
                            else if (added.Success)
                            {
                                title      = added.Groups[1].Value;
                                change.Old = string.Empty;
                                change.New = added.Groups[2].Value;
                            }
                            else if (deleted.Success)
                            {
                                title      = deleted.Groups[1].Value;
                                change.Old = deleted.Groups[2].Value;
                                change.New = string.Empty;
                            }

                            //
                            // Check if this is one of the attributes we are following.
                            //
                            if (title != null && title.Trim() == attribute)
                            {
                                //
                                // Get the ValuePair object to work with.
                                //
                                if (!changes.ContainsKey(attribute))
                                {
                                    changes.Add(attribute, new List <HistoryChange>());
                                }

                                change.PersonId = history.CreatedByPersonId;
                                changes[attribute].Add(change);

                                //
                                // If the value has been changed back to what it was then ignore the change.
                                //
                                if (changes[attribute].Count >= 2)
                                {
                                    var changesList = changes[attribute].ToList();

                                    if (changesList[changesList.Count - 2].Old == changesList[changesList.Count - 1].New)
                                    {
                                        changes.Remove(title);
                                    }
                                }
                            }
                        }
                    }

                    //
                    // Walk the list of final changes and see if we need to notify.
                    //
                    foreach (var items in changes.Values)
                    {
                        foreach (HistoryChange change in items)
                        {
                            //
                            // Check for a match on the person who made the change.
                            //
                            if (targetPersonAlias == null ||
                                targetPersonAlias.Id == 0 ||
                                (!negateChangedBy && targetPersonAlias.PersonId == change.PersonId) ||
                                (negateChangedBy && targetPersonAlias.PersonId != change.PersonId))
                            {
                                bool oldMatch = (string.IsNullOrEmpty(targetOldValue) || targetOldValue == change.Old);
                                bool newMatch = (string.IsNullOrEmpty(targetNewValue) || targetNewValue == change.New);

                                //
                                // If the old value and the new value match then trigger the event.
                                //
                                if ((matchBothValues && oldMatch && newMatch) ||
                                    (!matchBothValues && (oldMatch || newMatch)))
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 35
0
        protected override void LoadViewState( object savedState )
        {
            base.LoadViewState( savedState );

            EventId = ViewState["EventId"] as int? ?? 0;
            EventEntityTypeId = ViewState["EventEntityTypeId"] as int?;

            var followingEvent = new FollowingEventType { Id = EventId, EntityTypeId = EventEntityTypeId };
            BuildDynamicControls( followingEvent, false );
        }
Ejemplo n.º 36
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FollowingEventTypeNotices"/> class.
 /// </summary>
 /// <param name="eventType">Type of the event.</param>
 /// <param name="notices">The notices.</param>
 public FollowingEventTypeNotices( FollowingEventType eventType, List<string> notices )
 {
     EventType = eventType;
     Notices = notices;
 }
Ejemplo n.º 37
0
 /// <summary>
 /// Determines whether [has event happened] [the specified entity].
 /// </summary>
 /// <param name="followingEvent">The following event.</param>
 /// <param name="entity">The entity.</param>
 /// <param name="lastNotified">The last notified.</param>
 /// <returns></returns>
 public abstract bool HasEventHappened(FollowingEventType followingEvent, IEntity entity, DateTime?lastNotified);
Ejemplo n.º 38
0
 /// <summary>
 /// Loads the attributes for the following event.
 /// </summary>
 /// <param name="followingEvent">The following event.</param>
 public void LoadAttributes(FollowingEventType followingEvent)
 {
     followingEvent.LoadAttributes();
 }
Ejemplo n.º 39
0
        /// <summary>
        /// Shows the readonly details.
        /// </summary>
        /// <param name="event">The event.</param>
        private void ShowReadonlyDetails( FollowingEventType followingEvent )
        {
            SetEditMode( false );

            lActionTitle.Text = followingEvent.Name.FormatAsHtmlTitle();
            hlInactive.Visible = !followingEvent.IsActive;
            lEventDescription.Text = followingEvent.Description;

            DescriptionList descriptionList = new DescriptionList();

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

            descriptionList.Add( "Require Notification", followingEvent.IsNoticeRequired ? "Yes" : "No" );
            descriptionList.Add( "Send Weekend Notices on Friday", followingEvent.SendOnWeekends ? "No" : "Yes" );

            lblMainDetails.Text = descriptionList.Html;
        }
Ejemplo n.º 40
0
        /// <summary>
        /// Shows the edit details.
        /// </summary>
        /// <param name="event">The event.</param>
        private void ShowEditDetails( FollowingEventType followingEvent )
        {
            if ( followingEvent.Id == 0 )
            {
                lActionTitle.Text = ActionTitle.Add( FollowingEventType.FriendlyTypeName ).FormatAsHtmlTitle();
            }
            else
            {
                lActionTitle.Text = followingEvent.Name.FormatAsHtmlTitle();
            }

            hlInactive.Visible = !followingEvent.IsActive;

            SetEditMode( true );

            tbName.Text = followingEvent.Name;
            cbIsActive.Checked = followingEvent.IsActive;
            tbDescription.Text = followingEvent.Description;
            cpEventType.SetValue( followingEvent.EntityType != null ? followingEvent.EntityType.Guid.ToString().ToUpper() : string.Empty );
            cbSendOnFriday.Checked = !followingEvent.SendOnWeekends;
            cbRequireNotification.Checked = followingEvent.IsNoticeRequired;
            ceNotificationFormat.Text = followingEvent.EntityNotificationFormatLava;

            BuildDynamicControls( followingEvent, true );
        }
Ejemplo n.º 41
0
        private void BuildDynamicControls( FollowingEventType followingEvent, bool SetValues )
        {
            if ( SetValues )
            {
                EventEntityTypeId = followingEvent.EntityTypeId;
                if ( followingEvent.EntityTypeId.HasValue )
                {
                    var EventComponentEntityType = EntityTypeCache.Read( followingEvent.EntityTypeId.Value );
                    var EventEntityType = EntityTypeCache.Read( "Rock.Model.FollowingEventType" );
                    if ( EventComponentEntityType != null && EventEntityType != null )
                    {
                        using ( var rockContext = new RockContext() )
                        {
                            Rock.Attribute.Helper.UpdateAttributes( EventComponentEntityType.GetEntityType(), EventEntityType.Id, "EntityTypeId", EventComponentEntityType.Id.ToString(), rockContext );
                        }
                    }
                }
            }

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

            phAttributes.Controls.Clear();
            Rock.Attribute.Helper.AddEditControls( followingEvent, phAttributes, SetValues, BlockValidationGroup, new List<string> { "Active", "Order" } );
        }
Ejemplo n.º 42
0
 /// <summary>
 /// (Not Implemented) Determines whether <see cref="PersonNoteAdded"/> has happened for <paramref name="entity"/> since <paramref name="lastNotified"/> date.
 /// </summary>
 /// <param name="followingEvent">The following event.</param>
 /// <param name="entity">The entity being followed.</param>
 /// <param name="lastNotified">The last notified date.</param>
 /// <returns>A bool representing whether the followed event(s) for the followed entity occurred since last notified.</returns>
 public override bool HasEventHappened(FollowingEventType followingEvent, IEntity entity, DateTime?lastNotified)
 {
     throw new NotImplementedException("Exception occurred because this EventComponent implements an interface to extend the HasEventHappened method.  Please use HasEventHappened( FollowingEventType followingEvent, IEntity entity, DateTime? lastNotified, out Dictionary<string, List<object>> followedEventObjects ).");
 }
Ejemplo n.º 43
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FollowingEventTypeNotices"/> class.
 /// </summary>
 /// <param name="eventType">Type of the event.</param>
 /// <param name="notices">The notices.</param>
 public FollowingEventTypeNotices(FollowingEventType eventType, List <string> notices)
 {
     EventType = eventType;
     Notices   = notices;
 }
Ejemplo n.º 44
0
 /// <summary>
 /// Handles the SelectedIndexChanged event of the cpEventType 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 cpEventType_SelectedIndexChanged( object sender, EventArgs e )
 {
     var followingEvent = new FollowingEventType { Id = EventId, EntityTypeId = cpEventType.SelectedEntityTypeId };
     BuildDynamicControls( followingEvent, true );
 }