/// <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 #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>
        /// 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();
            }
        }