/// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrids()
        {
            if (ContentChannels.Any())
            {
                var allContentItems = new EventItemOccurrenceChannelItemService(new RockContext())
                                      .Queryable()
                                      .Where(c => c.EventItemOccurrenceId == OccurrenceId.Value)
                                      .Select(c => c.ContentChannelItem)
                                      .ToList();

                foreach (var contentChannel in ContentChannels)
                {
                    var pwItems = phContentChannelGrids.FindControl(string.Format("pwItems_{0}", contentChannel.Id)) as PanelWidget;
                    if (pwItems != null)
                    {
                        var gItems = pwItems.FindControl(string.Format("gItems_{0}", contentChannel.Id)) as Grid;
                        if (gItems != null)
                        {
                            var contentItems = allContentItems
                                               .Where(c => c.ContentChannelId == contentChannel.Id);

                            var items = new List <ContentChannelItem>();
                            foreach (var item in contentItems.ToList())
                            {
                                if (item.IsAuthorized(Rock.Security.Authorization.VIEW, CurrentPerson))
                                {
                                    items.Add(item);
                                }
                            }

                            SortProperty sortProperty = gItems.SortProperty;
                            if (sortProperty != null)
                            {
                                items = items.AsQueryable().Sort(sortProperty).ToList();
                            }
                            else
                            {
                                items = items.OrderByDescending(p => p.StartDateTime).ToList();
                            }

                            gItems.ObjectList = new Dictionary <string, object>();
                            items.ForEach(i => gItems.ObjectList.Add(i.Id.ToString(), i));
                            gItems.EntityTypeId = EntityTypeCache.Read <ContentChannelItem>().Id;

                            gItems.DataSource = items.Select(i => new
                            {
                                i.Id,
                                i.Guid,
                                i.Title,
                                i.StartDateTime,
                                i.ExpireDateTime,
                                i.Priority,
                                Status = DisplayStatus(i.Status)
                            }).ToList();
                            gItems.DataBind();
                        }
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Handles the Click event of the lbSave 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 lbSave_Click(object sender, EventArgs e)
        {
            var rockContext = new RockContext();
            ContentChannelItem contentItem = GetContentItem(rockContext);

            if (contentItem != null && contentItem.IsAuthorized(Authorization.EDIT, CurrentPerson))
            {
                contentItem.Title   = tbTitle.Text;
                contentItem.Content = contentItem.ContentChannel.ContentControlType == ContentControlType.HtmlEditor ?
                                      htmlContent.Text : ceContent.Text;
                contentItem.Priority = nbPriority.Text.AsInteger();
                if (contentItem.ContentChannelType.IncludeTime)
                {
                    contentItem.StartDateTime  = dtpStart.SelectedDateTime ?? RockDateTime.Now;
                    contentItem.ExpireDateTime = (contentItem.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange) ?
                                                 dtpExpire.SelectedDateTime : null;
                }
                else
                {
                    contentItem.StartDateTime  = dpStart.SelectedDate ?? RockDateTime.Today;
                    contentItem.ExpireDateTime = (contentItem.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange) ?
                                                 dpExpire.SelectedDate : null;
                }

                int newStatusID = hfStatus.Value.AsIntegerOrNull() ?? contentItem.Status.ConvertToInt();
                int oldStatusId = contentItem.Status.ConvertToInt();
                if (newStatusID != oldStatusId && contentItem.IsAuthorized(Authorization.APPROVE, CurrentPerson))
                {
                    contentItem.Status = hfStatus.Value.ConvertToEnum <ContentChannelItemStatus>(ContentChannelItemStatus.PendingApproval);
                    if (contentItem.Status == ContentChannelItemStatus.PendingApproval)
                    {
                        contentItem.ApprovedDateTime        = null;
                        contentItem.ApprovedByPersonAliasId = null;
                    }
                    else
                    {
                        contentItem.ApprovedDateTime        = RockDateTime.Now;
                        contentItem.ApprovedByPersonAliasId = CurrentPersonAliasId;
                    }
                }

                contentItem.LoadAttributes(rockContext);
                Rock.Attribute.Helper.GetEditValues(phAttributes, contentItem);

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

                rockContext.WrapTransaction(() =>
                {
                    rockContext.SaveChanges();
                    contentItem.SaveAttributeValues(rockContext);

                    int?eventItemOccurrenceId = PageParameter("EventItemOccurrenceId").AsIntegerOrNull();
                    if (eventItemOccurrenceId.HasValue)
                    {
                        var occurrenceChannelItemService = new EventItemOccurrenceChannelItemService(rockContext);
                        var occurrenceChannelItem        = occurrenceChannelItemService
                                                           .Queryable()
                                                           .Where(c =>
                                                                  c.ContentChannelItemId == contentItem.Id &&
                                                                  c.EventItemOccurrenceId == eventItemOccurrenceId.Value)
                                                           .FirstOrDefault();

                        if (occurrenceChannelItem == null)
                        {
                            occurrenceChannelItem = new EventItemOccurrenceChannelItem();
                            occurrenceChannelItem.ContentChannelItemId  = contentItem.Id;
                            occurrenceChannelItem.EventItemOccurrenceId = eventItemOccurrenceId.Value;
                            occurrenceChannelItemService.Add(occurrenceChannelItem);
                            rockContext.SaveChanges();
                        }
                    }
                });

                ReturnToParentPage();
            }
        }
Exemple #3
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrids()
        {
            if ( ContentChannels.Any() )
            {
                var allContentItems = new EventItemOccurrenceChannelItemService( new RockContext() )
                    .Queryable()
                    .Where( c => c.EventItemOccurrenceId == OccurrenceId.Value )
                    .Select( c => c.ContentChannelItem )
                    .ToList();

                foreach ( var contentChannel in ContentChannels )
                {
                    var pwItems = phContentChannelGrids.FindControl( string.Format( "pwItems_{0}", contentChannel.Id ) ) as PanelWidget;
                    if ( pwItems != null )
                    {
                        var gItems = pwItems.FindControl( string.Format( "gItems_{0}", contentChannel.Id ) ) as Grid;
                        if ( gItems != null )
                        {
                            var contentItems = allContentItems
                                .Where( c => c.ContentChannelId == contentChannel.Id );

                            var items = new List<ContentChannelItem>();
                            foreach ( var item in contentItems.ToList() )
                            {
                                if ( item.IsAuthorized( Rock.Security.Authorization.VIEW, CurrentPerson ) )
                                {
                                    items.Add( item );
                                }
                            }

                            SortProperty sortProperty = gItems.SortProperty;
                            if ( sortProperty != null )
                            {
                                items = items.AsQueryable().Sort( sortProperty ).ToList();
                            }
                            else
                            {
                                items = items.OrderByDescending( p => p.StartDateTime ).ToList();
                            }

                            gItems.ObjectList = new Dictionary<string, object>();
                            items.ForEach( i => gItems.ObjectList.Add( i.Id.ToString(), i ) );
                            gItems.EntityTypeId = EntityTypeCache.Read<ContentChannelItem>().Id;

                            gItems.DataSource = items.Select( i => new
                            {
                                i.Id,
                                i.Guid,
                                i.Title,
                                i.StartDateTime,
                                i.ExpireDateTime,
                                i.Priority,
                                Status = DisplayStatus( i.Status )
                            } ).ToList();
                            gItems.DataBind();
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Handles the Click event of the lbSave 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 lbSave_Click( object sender, EventArgs e )
        {
            var rockContext = new RockContext();
            ContentChannelItem contentItem = GetContentItem( rockContext );

            if ( contentItem != null &&
                ( IsUserAuthorized( Authorization.EDIT ) || contentItem.IsAuthorized( Authorization.EDIT, CurrentPerson ) ) )
            {
                contentItem.Title = tbTitle.Text;
                contentItem.Content = contentItem.ContentChannel.ContentControlType == ContentControlType.HtmlEditor ?
                    htmlContent.Text : ceContent.Text;
                contentItem.Priority = nbPriority.Text.AsInteger();
                if ( contentItem.ContentChannelType.IncludeTime )
                {
                    contentItem.StartDateTime = dtpStart.SelectedDateTime ?? RockDateTime.Now;
                    contentItem.ExpireDateTime = ( contentItem.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange ) ?
                        dtpExpire.SelectedDateTime : null;
                }
                else
                {
                    contentItem.StartDateTime = dpStart.SelectedDate ?? RockDateTime.Today;
                    contentItem.ExpireDateTime = ( contentItem.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange ) ?
                        dpExpire.SelectedDate : null;
                }

                int newStatusID = hfStatus.Value.AsIntegerOrNull() ?? contentItem.Status.ConvertToInt();
                int oldStatusId = contentItem.Status.ConvertToInt();
                if ( newStatusID != oldStatusId && contentItem.IsAuthorized(Authorization.APPROVE, CurrentPerson))
                {
                    contentItem.Status = hfStatus.Value.ConvertToEnum<ContentChannelItemStatus>( ContentChannelItemStatus.PendingApproval );
                    if ( contentItem.Status == ContentChannelItemStatus.PendingApproval )
                    {
                        contentItem.ApprovedDateTime = null;
                        contentItem.ApprovedByPersonAliasId = null;
                    }
                    else
                    {
                        contentItem.ApprovedDateTime = RockDateTime.Now;
                        contentItem.ApprovedByPersonAliasId = CurrentPersonAliasId;
                    }
                }

                // remove approved status if they do not have approve access when editing
                if ( !contentItem.IsAuthorized( Authorization.APPROVE, CurrentPerson ) )
                {
                    contentItem.ApprovedDateTime = null;
                    contentItem.ApprovedByPersonAliasId = null;
                    contentItem.Status = ContentChannelItemStatus.PendingApproval;
                }

                contentItem.LoadAttributes( rockContext );
                Rock.Attribute.Helper.GetEditValues( phAttributes, contentItem );

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

                rockContext.WrapTransaction( () =>
                {
                    rockContext.SaveChanges();
                    contentItem.SaveAttributeValues( rockContext );

                    int? eventItemOccurrenceId = PageParameter( "EventItemOccurrenceId" ).AsIntegerOrNull();
                    if ( eventItemOccurrenceId.HasValue )
                    {
                        var occurrenceChannelItemService = new EventItemOccurrenceChannelItemService( rockContext );
                        var occurrenceChannelItem = occurrenceChannelItemService
                            .Queryable()
                            .Where( c =>
                                c.ContentChannelItemId == contentItem.Id &&
                                c.EventItemOccurrenceId == eventItemOccurrenceId.Value)
                            .FirstOrDefault();

                        if ( occurrenceChannelItem == null )
                        {
                            occurrenceChannelItem = new EventItemOccurrenceChannelItem();
                            occurrenceChannelItem.ContentChannelItemId = contentItem.Id;
                            occurrenceChannelItem.EventItemOccurrenceId = eventItemOccurrenceId.Value;
                            occurrenceChannelItemService.Add( occurrenceChannelItem );
                            rockContext.SaveChanges();
                        }
                    }

                } );

                ReturnToParentPage();
            }
        }
Exemple #5
0
        /// <summary>
        /// Handles the Click event of the lbSave 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 lbSave_Click(object sender, EventArgs e)
        {
            var rockContext = new RockContext();
            ContentChannelItem contentItem = GetContentItem(rockContext);

            if (contentItem != null &&
                (IsUserAuthorized(Authorization.EDIT) || contentItem.IsAuthorized(Authorization.EDIT, CurrentPerson)))
            {
                contentItem.Title    = tbTitle.Text;
                contentItem.Content  = htmlContent.Text;
                contentItem.Priority = nbPriority.Text.AsInteger();

                // If this is a new item and the channel is manually sorted then we need to set the order to the next number
                if (contentItem.Id == 0 && new ContentChannelService(rockContext).IsManuallySorted(contentItem.ContentChannelId))
                {
                    contentItem.Order = new ContentChannelItemService(rockContext).GetNextItemOrderValueForContentChannel(contentItem.ContentChannelId);
                }

                if (contentItem.ContentChannelType.IncludeTime)
                {
                    contentItem.StartDateTime  = dtpStart.SelectedDateTime ?? RockDateTime.Now;
                    contentItem.ExpireDateTime = (contentItem.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange) ?
                                                 dtpExpire.SelectedDateTime : null;
                }
                else
                {
                    contentItem.StartDateTime  = dpStart.SelectedDate ?? RockDateTime.Today;
                    contentItem.ExpireDateTime = (contentItem.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange) ?
                                                 dpExpire.SelectedDate : null;
                }

                if (contentItem.ContentChannelType.DisableStatus)
                {
                    // if DisableStatus == True, just set the status to Approved
                    contentItem.Status = ContentChannelItemStatus.Approved;
                }
                else
                {
                    int newStatusID = hfStatus.Value.AsIntegerOrNull() ?? contentItem.Status.ConvertToInt();
                    int oldStatusId = contentItem.Status.ConvertToInt();
                    if (newStatusID != oldStatusId && contentItem.IsAuthorized(Authorization.APPROVE, CurrentPerson))
                    {
                        contentItem.Status = hfStatus.Value.ConvertToEnum <ContentChannelItemStatus>(ContentChannelItemStatus.PendingApproval);
                        if (contentItem.Status == ContentChannelItemStatus.PendingApproval)
                        {
                            contentItem.ApprovedDateTime        = null;
                            contentItem.ApprovedByPersonAliasId = null;
                        }
                        else
                        {
                            contentItem.ApprovedDateTime        = RockDateTime.Now;
                            contentItem.ApprovedByPersonAliasId = CurrentPersonAliasId;
                        }
                    }

                    // remove approved status if they do not have approve access when editing
                    if (!contentItem.IsAuthorized(Authorization.APPROVE, CurrentPerson))
                    {
                        contentItem.ApprovedDateTime        = null;
                        contentItem.ApprovedByPersonAliasId = null;
                        contentItem.Status = ContentChannelItemStatus.PendingApproval;
                    }
                }

                contentItem.LoadAttributes(rockContext);
                Rock.Attribute.Helper.GetEditValues(phAttributes, contentItem);

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

                rockContext.WrapTransaction(() =>
                {
                    rockContext.SaveChanges();
                    contentItem.SaveAttributeValues(rockContext);

                    if (contentItem.ContentChannel.IsTaggingEnabled)
                    {
                        taglTags.EntityGuid = contentItem.Guid;
                        taglTags.SaveTagValues(CurrentPersonAlias);
                    }

                    int?eventItemOccurrenceId = PageParameter("EventItemOccurrenceId").AsIntegerOrNull();
                    if (eventItemOccurrenceId.HasValue)
                    {
                        var occurrenceChannelItemService = new EventItemOccurrenceChannelItemService(rockContext);
                        var occurrenceChannelItem        = occurrenceChannelItemService
                                                           .Queryable()
                                                           .Where(c =>
                                                                  c.ContentChannelItemId == contentItem.Id &&
                                                                  c.EventItemOccurrenceId == eventItemOccurrenceId.Value)
                                                           .FirstOrDefault();

                        if (occurrenceChannelItem == null)
                        {
                            occurrenceChannelItem = new EventItemOccurrenceChannelItem();
                            occurrenceChannelItem.ContentChannelItemId  = contentItem.Id;
                            occurrenceChannelItem.EventItemOccurrenceId = eventItemOccurrenceId.Value;
                            occurrenceChannelItemService.Add(occurrenceChannelItem);
                            rockContext.SaveChanges();
                        }
                    }
                });

                ReturnToParentPage();
            }
        }