/// <summary>
        /// Handles the DeleteClick event of the gContentChannelItems control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Rock.Web.UI.Controls.RowEventArgs"/> instance containing the event data.</param>
        protected void gContentChannelItems_DeleteClick(object sender, Rock.Web.UI.Controls.RowEventArgs e)
        {
            var rockContext                   = new RockContext();
            var contentItemService            = new ContentChannelItemService(rockContext);
            var contentItemAssociationService = new ContentChannelItemAssociationService(rockContext);
            var contentItemSlugService        = new ContentChannelItemSlugService(rockContext);

            ContentChannelItem contentItem = contentItemService.Get(e.RowKeyId);

            if (contentItem != null)
            {
                string errorMessage;
                if (!contentItemService.CanDelete(contentItem, out errorMessage))
                {
                    mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                    return;
                }

                rockContext.WrapTransaction(() =>
                {
                    contentItemAssociationService.DeleteRange(contentItem.ChildItems);
                    contentItemAssociationService.DeleteRange(contentItem.ParentItems);
                    contentItemService.Delete(contentItem);
                    rockContext.SaveChanges();
                });
            }

            BindContentChannelItemsGrid();

            // edit whatever the first item is, or create a new one
            var contentChannel       = GetContentChannel();
            var contentChannelItemId = new ContentChannelItemService(rockContext).Queryable().Where(a => a.ContentChannelId == contentChannel.Id).OrderBy(a => a.Order).ThenBy(a => a.Title).Select(a => ( int? )a.Id).FirstOrDefault();

            EditContentChannelItem(contentChannelItemId);
        }
Example #2
0
        /// <summary>
        /// Handles the Click event of the deleteField control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param>
        /// <exception cref="System.NotImplementedException"></exception>
        void gContentChannelItems_Delete(object sender, RowEventArgs e)
        {
            var rockContext                   = new RockContext();
            var contentItemService            = new ContentChannelItemService(rockContext);
            var contentItemAssociationService = new ContentChannelItemAssociationService(rockContext);
            var contentItemSlugService        = new ContentChannelItemSlugService(rockContext);

            var contentItem = contentItemService.Get(e.RowKeyId);

            if (contentItem != null)
            {
                string errorMessage;
                if (!contentItemService.CanDelete(contentItem, out errorMessage))
                {
                    mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                    return;
                }

                rockContext.WrapTransaction(() =>
                {
                    contentItemAssociationService.DeleteRange(contentItem.ChildItems);
                    contentItemAssociationService.DeleteRange(contentItem.ParentItems);
                    contentItemService.Delete(contentItem);
                    rockContext.SaveChanges();
                });
            }

            GetData();
        }
Example #3
0
        /// <summary>
        /// Inserts the slug for Content Channel Items.
        /// </summary>
        public static void UpdateSlugForContentChannelItems()
        {
            int  recordsToProcess = 1000;
            bool isProcess        = true;

            do
            {
                using (var rockContext = new RockContext())
                {
                    var contentChannelItems = new ContentChannelItemService(rockContext)
                                              .Queryable()
                                              .AsNoTracking()
                                              .Where(a => !a.ContentChannelItemSlugs.Any())
                                              .Take(recordsToProcess)
                                              .Select(a => new
                    {
                        a.Id,
                        a.Title
                    }).ToList();

                    var slugService = new ContentChannelItemSlugService(rockContext);
                    if (contentChannelItems.Any())
                    {
                        foreach (var item in contentChannelItems)
                        {
                            slugService.SaveSlug(item.Id, item.Title, null);
                        }
                    }
                    else
                    {
                        isProcess = false;
                    }
                }
            }while (isProcess);
        }
        public string GetUniqueContentSlug(string slug, int?contentChannelItemSlugId = null)
        {
            string uniquieSlug = string.Empty;

            using (var rockContext = new RockContext())
            {
                var contentChannelItemSlugService = new ContentChannelItemSlugService(rockContext);

                uniquieSlug = contentChannelItemSlugService.GetUniqueContentSlug(slug, contentChannelItemSlugId);
            }
            return(uniquieSlug);
        }
        public SaveSlugResponse SaveContentSlug(int contentChannelItemId, string slug, int?contentChannelItemSlugId = null)
        {
            SaveSlugResponse response = new SaveSlugResponse();

            using (var rockContext = new RockContext())
            {
                var contentChannelItemSlugService = new ContentChannelItemSlugService(rockContext);

                var contentChannelItemSlug = contentChannelItemSlugService.SaveSlug(contentChannelItemId, slug, contentChannelItemSlugId);
                if (contentChannelItemSlug != null)
                {
                    response.Slug = contentChannelItemSlug.Slug;
                    response.Id   = contentChannelItemSlug.Id;
                }
            }
            return(response);
        }
        public IHttpActionResult ChannelItem(string identifier)
        {
            RockContext rockContext = new RockContext();
            ContentChannelItemService contentChannelItemService = new ContentChannelItemService(rockContext);

            IQueryable <ContentChannelItem> contentChannelItem;

            var itemId = identifier.AsInteger();

            if (itemId != 0)
            {
                contentChannelItem = contentChannelItemService.Queryable().Where(i => i.Id == itemId);
            }
            else
            {
                //Get by slug
                ContentChannelItemSlugService contentChannelItemSlugService = new ContentChannelItemSlugService(rockContext);
                contentChannelItem = contentChannelItemSlugService.Queryable()
                                     .Where(s => s.Slug == identifier)
                                     .Select(s => s.ContentChannelItem);
            }

            var contentChannel = contentChannelItem.Select(i => i.ContentChannel).FirstOrDefault();

            if (contentChannel == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            if (!contentChannel.IsAuthorized(Rock.Security.Authorization.VIEW, GetPerson()))
            {
                throw new HttpResponseException(HttpStatusCode.Unauthorized);
            }

            var contentChannelTypeId  = contentChannel.ContentChannelTypeId.ToString();
            var contentChanelIdString = contentChannel.Id.ToString();

            var attributeQry = new AttributeService(rockContext).Queryable()
                               .Where(a => a.EntityTypeId == contentChanelItemEntityTypeId &&
                                      ((a.EntityTypeQualifierColumn == "ContentChannelTypeId" && a.EntityTypeQualifierValue == contentChannelTypeId) ||
                                       (a.EntityTypeQualifierColumn == "ContentChannelId" && a.EntityTypeQualifierValue == contentChanelIdString)))
                               .Select(a => a.Id);

            var attributeValueQry = new AttributeValueService(rockContext).Queryable().Where(av => attributeQry.Contains(av.AttributeId));

            var complex = contentChannelItem
                          .GroupJoin(attributeValueQry,
                                     i => i.Id,
                                     av => av.EntityId,
                                     (i, av) => new
            {
                ContentChanelItem = i,
                Children          = i.ChildItems.OrderBy(ci => ci.Order).Select(ci => ci.ChildContentChannelItemId),
                ParentItems       = i.ParentItems.Select(ci => ci.ContentChannelItemId),
                AttributeValues   = av
            })
                          .ToList();

            var items = complex
                        .Select(i => new ChannelItem
            {
                Id          = i.ContentChanelItem.Id,
                DateTime    = i.ContentChanelItem.StartDateTime,
                Title       = i.ContentChanelItem.Title,
                Content     = i.ContentChanelItem.Content,
                Priority    = i.ContentChanelItem.Priority,
                Order       = i.ContentChanelItem.Order,
                Attributes  = i.AttributeValues.ToDictionary(a => a.AttributeKey, a => a.Value),
                Tags        = GetTags(i.ContentChanelItem, rockContext),
                Slug        = i.ContentChanelItem.PrimarySlug,
                CreatedBy   = i.ContentChanelItem.CreatedByPersonName,
                ChildItems  = i.Children.ToList(),
                ParentItems = i.ParentItems.ToList()
            }).ToList();

            return(Json(items.FirstOrDefault()));
        }