Пример #1
0
        /// <summary>
        /// Gets the type of the content.
        /// </summary>
        /// <param name="contentItemId">The content type identifier.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <returns></returns>
        private ContentChannelItem GetContentItem(RockContext rockContext = null)
        {
            rockContext = rockContext ?? new RockContext();
            var contentItemService         = new ContentChannelItemService(rockContext);
            ContentChannelItem contentItem = null;

            int contentItemId = hfId.Value.AsInteger();

            if (contentItemId != 0)
            {
                contentItem = contentItemService
                              .Queryable("ContentChannel,ContentChannelType")
                              .FirstOrDefault(t => t.Id == contentItemId);
            }

            if (contentItem == null)
            {
                var contentChannel = new ContentChannelService(rockContext).Get(hfChannelId.Value.AsInteger());
                if (contentChannel != null)
                {
                    contentItem = new ContentChannelItem
                    {
                        ContentChannel       = contentChannel,
                        ContentChannelId     = contentChannel.Id,
                        ContentChannelType   = contentChannel.ContentChannelType,
                        ContentChannelTypeId = contentChannel.ContentChannelType.Id,
                        StartDateTime        = RockDateTime.Now
                    };

                    if (contentChannel.RequiresApproval)
                    {
                        contentItem.Status = ContentChannelItemStatus.PendingApproval;
                    }
                    else
                    {
                        contentItem.Status                  = ContentChannelItemStatus.Approved;
                        contentItem.ApprovedDateTime        = RockDateTime.Now;
                        contentItem.ApprovedByPersonAliasId = CurrentPersonAliasId;
                    }

                    contentItemService.Add(contentItem);
                }
            }

            return(contentItem);
        }
        /// <summary>
        /// Saves the content channel item.
        /// </summary>
        private void SaveContentChannelItem()
        {
            RockContext rockContext = new RockContext();
            ContentChannelItemService contentChannelItemService = new ContentChannelItemService(rockContext);
            ContentChannelItem        contentChannelItem        = null;
            int contentChannelItemId = hfContentChannelItemId.Value.AsInteger();

            if (contentChannelItemId != 0)
            {
                contentChannelItem = contentChannelItemService.Get(contentChannelItemId);
            }

            if (contentChannelItem == null)
            {
                ContentChannelCache contentChannel = this.GetContentChannel();

                contentChannelItem = new ContentChannelItem();
                contentChannelItem.ContentChannelTypeId = contentChannel.ContentChannelTypeId;
                contentChannelItem.ContentChannelId     = contentChannel.Id;
                contentChannelItem.Order = (contentChannelItemService.Queryable().Where(a => a.ContentChannelId == contentChannel.Id).Max(a => ( int? )a.Order) ?? 0) + 1;
                contentChannelItemService.Add(contentChannelItem);
            }

            contentChannelItem.LoadAttributes(rockContext);
            avcContentChannelItemAttributes.GetEditValues(contentChannelItem);

            contentChannelItem.Title   = tbContentChannelItemTitle.Text;
            contentChannelItem.Content = htmlContentChannelItemContent.Text;

            rockContext.SaveChanges();

            // just in case this is a new contentChannelItem, set the hfContentChannelItemId to the Id after SaveChanges.
            hfContentChannelItemId.Value = contentChannelItem.Id.ToString();

            contentChannelItem.SaveAttributeValues(rockContext);

            RemoveCacheItem(OUTPUT_CACHE_KEY);
            RemoveCacheItem(ITEM_CACHE_KEY);

            BindContentChannelItemsGrid();
        }
        /// <summary>
        /// Gets the type of the content.
        /// </summary>
        /// <param name="contentItemId">The content type identifier.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <returns></returns>
        private ContentChannelItem GetContentItem( RockContext rockContext = null )
        {
            rockContext = rockContext ?? new RockContext();
            var contentItemService = new ContentChannelItemService( rockContext );
            ContentChannelItem contentItem = null;

            int contentItemId = hfId.Value.AsInteger();
            if ( contentItemId != 0 )
            {
                contentItem = contentItemService
                    .Queryable( "ContentChannel,ContentChannelType" )
                    .FirstOrDefault( t => t.Id == contentItemId );
            }

            if ( contentItem == null)
            {
                var contentChannel = new ContentChannelService( rockContext ).Get( hfChannelId.Value.AsInteger() );
                if ( contentChannel != null )
                {
                    contentItem = new ContentChannelItem
                    {
                        ContentChannel = contentChannel,
                        ContentChannelId = contentChannel.Id,
                        ContentChannelType = contentChannel.ContentChannelType,
                        ContentChannelTypeId = contentChannel.ContentChannelType.Id,
                        StartDateTime = RockDateTime.Now
                    };

                    if ( contentChannel.RequiresApproval )
                    {
                        contentItem.Status = ContentChannelItemStatus.PendingApproval;
                    }
                    else
                    {
                        contentItem.Status = ContentChannelItemStatus.Approved;
                        contentItem.ApprovedDateTime = RockDateTime.Now;
                        contentItem.ApprovedByPersonAliasId = CurrentPersonAliasId;
                    }

                    contentItemService.Add( contentItem );
                }
            }

            return contentItem;
        }
Пример #4
0
        /// <summary>
        /// Gets the type of the content.
        /// </summary>
        /// <param name="contentItemId">The content type identifier.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <returns></returns>
        private ContentChannelItem GetContentItem(RockContext rockContext = null)
        {
            rockContext = rockContext ?? new RockContext();
            var contentItemService         = new ContentChannelItemService(rockContext);
            ContentChannelItem contentItem = null;

            int contentItemId = hfId.Value.AsInteger();

            if (contentItemId != 0)
            {
                contentItem = contentItemService
                              .Queryable("ContentChannel,ContentChannelType")
                              .FirstOrDefault(t => t.Id == contentItemId);
            }

            if (contentItem == null)
            {
                var contentChannel = new ContentChannelService(rockContext).Get(hfChannelId.Value.AsInteger());
                if (contentChannel != null)
                {
                    contentItem = new ContentChannelItem
                    {
                        ContentChannel       = contentChannel,
                        ContentChannelId     = contentChannel.Id,
                        ContentChannelType   = contentChannel.ContentChannelType,
                        ContentChannelTypeId = contentChannel.ContentChannelType.Id,
                        StartDateTime        = RockDateTime.Now
                    };

                    var hierarchy = GetNavHierarchy();
                    if (hierarchy.Any())
                    {
                        var parentItem = contentItemService.Get(hierarchy.Last().AsInteger());
                        if (parentItem != null &&
                            parentItem.IsAuthorized(Authorization.EDIT, CurrentPerson) &&
                            parentItem.ContentChannel.ChildContentChannels.Any(c => c.Id == contentChannel.Id))
                        {
                            var order = parentItem.ChildItems
                                        .Select(a => (int?)a.Order)
                                        .DefaultIfEmpty()
                                        .Max();

                            var assoc = new ContentChannelItemAssociation();
                            assoc.ContentChannelItemId = parentItem.Id;
                            assoc.Order = order.HasValue ? order.Value + 1 : 0;
                            contentItem.ParentItems.Add(assoc);
                        }
                    }

                    if (contentChannel.RequiresApproval)
                    {
                        contentItem.Status = ContentChannelItemStatus.PendingApproval;
                    }
                    else
                    {
                        contentItem.Status                  = ContentChannelItemStatus.Approved;
                        contentItem.ApprovedDateTime        = RockDateTime.Now;
                        contentItem.ApprovedByPersonAliasId = CurrentPersonAliasId;
                    }

                    contentItemService.Add(contentItem);
                }
            }

            return(contentItem);
        }
        /// <summary>
        /// Gets the type of the content.
        /// </summary>
        /// <param name="contentItemId">The content type identifier.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <returns></returns>
        private ContentChannelItem GetContentItem( RockContext rockContext = null )
        {
            rockContext = rockContext ?? new RockContext();
            var contentItemService = new ContentChannelItemService( rockContext );
            ContentChannelItem contentItem = null;

            int contentItemId = hfId.Value.AsInteger();
            if ( contentItemId != 0 )
            {
                contentItem = contentItemService
                    .Queryable( "ContentChannel,ContentChannelType" )
                    .FirstOrDefault( t => t.Id == contentItemId );
            }

            if ( contentItem == null)
            {
                var contentChannel = new ContentChannelService( rockContext ).Get( hfChannelId.Value.AsInteger() );
                if ( contentChannel != null )
                {
                    contentItem = new ContentChannelItem
                    {
                        ContentChannel = contentChannel,
                        ContentChannelId = contentChannel.Id,
                        ContentChannelType = contentChannel.ContentChannelType,
                        ContentChannelTypeId = contentChannel.ContentChannelType.Id,
                        StartDateTime = RockDateTime.Now
                    };

                    var hierarchy = GetNavHierarchy();
                    if ( hierarchy.Any() )
                    {
                        var parentItem = contentItemService.Get( hierarchy.Last().AsInteger() );
                        if ( parentItem != null &&
                            parentItem.IsAuthorized( Authorization.EDIT, CurrentPerson ) &&
                            parentItem.ContentChannel.ChildContentChannels.Any( c => c.Id == contentChannel.Id ) )
                        {
                            var order = parentItem.ChildItems
                                .Select( a => (int?)a.Order )
                                .DefaultIfEmpty()
                                .Max();

                            var assoc = new ContentChannelItemAssociation();
                            assoc.ContentChannelItemId = parentItem.Id;
                            assoc.Order = order.HasValue ? order.Value + 1 : 0;
                            contentItem.ParentItems.Add( assoc );
                        }
                    }

                    if ( contentChannel.RequiresApproval )
                    {
                        contentItem.Status = ContentChannelItemStatus.PendingApproval;
                    }
                    else
                    {
                        contentItem.Status = ContentChannelItemStatus.Approved;
                        contentItem.ApprovedDateTime = RockDateTime.Now;
                        contentItem.ApprovedByPersonAliasId = CurrentPersonAliasId;
                    }

                    contentItemService.Add( contentItem );
                }
            }

            return contentItem;
        }
Пример #6
0
        public void Execute(IJobExecutionContext context)
        {
            int storyCount    = 0;
            int newStoryCount = 0;

            JobDataMap dataMap = context.JobDetail.JobDataMap;

            List <Story>              stories                   = new List <Story>();
            RockContext               rockContext               = new RockContext();
            ContentChannelService     contentChannelService     = new ContentChannelService(rockContext);
            ContentChannelItemService contentChannelItemService = new ContentChannelItemService(rockContext);
            BinaryFileService         binaryFileService         = new BinaryFileService(rockContext);
            BinaryFileType            binaryFileType            = new BinaryFileTypeService(rockContext).Get(Rock.SystemGuid.BinaryFiletype.MEDIA_FILE.AsGuid());
            var storiesSeriesChannel = contentChannelService.Get(dataMap.GetString("StoriesContentChannel").AsGuid());

            var dbCon = DBConnection.Instance();

            dbCon.DatabaseName = "secccp_main";
            if (dbCon.IsConnect())
            {
                stories = GetStories(dbCon);

                foreach (var story in stories)
                {
                    storyCount++;
                    var item = contentChannelItemService.Queryable().Where(i => i.ForeignId == story.id && i.ContentChannelId == storiesSeriesChannel.Id).FirstOrDefault();
                    if (item == null)
                    {
                        newStoryCount++;
                        item = new ContentChannelItem()
                        {
                            ContentChannelId     = storiesSeriesChannel.Id,
                            ForeignId            = story.id,
                            ContentChannelTypeId = storiesSeriesChannel.ContentChannelTypeId
                        };
                        contentChannelItemService.Add(item);
                    }
                    item.Title         = story.title;
                    item.Content       = story.description;
                    item.StartDateTime = Helpers.FromUnixTime(story.datecreated);
                    rockContext.SaveChanges();

                    item.LoadAttributes();
                    item.SetAttributeValue("Slug", story.slug);
                    item.SetAttributeValue("VimeoId", story.vimeo_id);
                    item.SetAttributeValue("VimeoStreamingUrl", story.vimeo_live_url);
                    item.SetAttributeValue("VimeoDownloadUrl", story.vimeo_sd_url);
                    item.SetAttributeValue("Tags", story.tags);
                    item.SetAttributeValue("Duration", story.duration);

                    if (string.IsNullOrWhiteSpace(item.GetAttributeValue("Image")))
                    {
                        WebClient client = new WebClient();
                        try
                        {
                            using (MemoryStream stream = new MemoryStream(client.DownloadData(string.Format("http://panel.secc.org/upload/stories/cover-images/story-{0}.jpg", story.id))))
                            {
                                BinaryFile binaryFile = new BinaryFile();
                                binaryFileService.Add(binaryFile);
                                binaryFile.IsTemporary      = false;
                                binaryFile.BinaryFileTypeId = binaryFileType.Id;
                                binaryFile.MimeType         = "image/jpg";
                                binaryFile.FileName         = string.Format("Story-{0}.jpg", story.id);
                                binaryFile.ContentStream    = stream;
                                rockContext.SaveChanges();
                                item.SetAttributeValue("Image", binaryFile.Guid.ToString());
                            }
                        }
                        catch (Exception ex)
                        {
                            var a = ex;
                        }
                    }

                    item.SaveAttributeValues();
                }
            }
            context.Result = string.Format("Synced {0} sermons ({1} New Sermon)", storyCount, newStoryCount);
        }
        /// <summary>
        /// Executes the specified workflow, setting the startDateTime to now (if none was given) and leaving
        /// the expireDateTime as null (if none was given).
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        public override bool Execute(RockContext rockContext, WorkflowAction action, Object entity, out List <string> errorMessages)
        {
            errorMessages = new List <string>();
            var mergeFields = GetMergeFields(action);

            // Get the content channel
            Guid           contentChannelGuid = GetAttributeValue(action, "ContentChannel").AsGuid();
            ContentChannel contentChannel     = new ContentChannelService(rockContext).Get(contentChannelGuid);

            if (contentChannel == null)
            {
                errorMessages.Add("Invalid Content Channel attribute or value!");
                return(false);
            }

            // Get the Content
            string contentValue = GetAttributeValue(action, "Content", true);
            string content      = string.Empty;
            Guid?  contentGuid  = contentValue.AsGuidOrNull();

            if (contentGuid.HasValue)
            {
                var attribute = AttributeCache.Get(contentGuid.Value, rockContext);
                if (attribute != null)
                {
                    string contentAttributeValue = action.GetWorkflowAttributeValue(contentGuid.Value);
                    if (!string.IsNullOrWhiteSpace(contentAttributeValue))
                    {
                        if (attribute.FieldType.Class == "Rock.Field.Types.TextFieldType" ||
                            attribute.FieldType.Class == "Rock.Field.Types.MemoFieldType")
                        {
                            content = contentAttributeValue;
                        }
                    }
                }
            }
            else
            {
                content = contentValue;
            }

            // Get the Content Creator
            int? personAliasId       = null;
            Guid?personAttributeGuid = GetAttributeValue(action, "CreatedBy").AsGuidOrNull();

            if (personAttributeGuid.HasValue)
            {
                Guid?personAliasGuid = action.GetWorkflowAttributeValue(personAttributeGuid.Value).AsGuidOrNull();
                if (personAliasGuid.HasValue)
                {
                    var personAlias = new PersonAliasService(rockContext).Get(personAliasGuid.Value);
                    if (personAlias != null)
                    {
                        personAliasId = personAlias.Id;
                    }
                }
            }

            // Get the Start Date Time (check if the attribute value is a guid first)
            DateTime startDateTime              = RockDateTime.Now;
            string   startAttributeValue        = GetAttributeValue(action, "StartDateTime");
            Guid     startDateTimeAttributeGuid = startAttributeValue.AsGuid();

            if (!startDateTimeAttributeGuid.IsEmpty())
            {
                var attribute = AttributeCache.Get(startDateTimeAttributeGuid, rockContext);
                if (attribute != null)
                {
                    string attributeValue = action.GetWorkflowAttributeValue(startDateTimeAttributeGuid);
                    if (!string.IsNullOrWhiteSpace(attributeValue))
                    {
                        if (attribute.FieldType.Class == "Rock.Field.Types.TextFieldType" ||
                            attribute.FieldType.Class == "Rock.Field.Types.DateTimeFieldType")
                        {
                            if (!DateTime.TryParse(attributeValue, out startDateTime))
                            {
                                startDateTime = RockDateTime.Now;
                                errorMessages.Add(string.Format("Could not parse the start date provided {0}.", attributeValue));
                            }
                        }
                    }
                }
            }
            // otherwise check just the plain value and then perform lava merge on it.
            else if (!string.IsNullOrWhiteSpace(startAttributeValue))
            {
                string mergedStartAttributeValue = startAttributeValue.ResolveMergeFields(mergeFields);
                if (!DateTime.TryParse(mergedStartAttributeValue, out startDateTime))
                {
                    startDateTime = RockDateTime.Now;
                    errorMessages.Add(string.Format("Could not parse the start date provided {0}.", startAttributeValue));
                }
            }

            // Get the Expire Date Time (check if the attribute value is a guid first)
            DateTime?expireDateTime              = null;
            string   expireAttributeValue        = GetAttributeValue(action, "ExpireDateTime");
            Guid     expireDateTimeAttributeGuid = expireAttributeValue.AsGuid();

            if (!expireDateTimeAttributeGuid.IsEmpty())
            {
                var attribute = AttributeCache.Get(expireDateTimeAttributeGuid, rockContext);
                if (attribute != null)
                {
                    DateTime aDateTime;
                    string   attributeValue = action.GetWorkflowAttributeValue(expireDateTimeAttributeGuid);
                    if (!string.IsNullOrWhiteSpace(attributeValue))
                    {
                        if (attribute.FieldType.Class == "Rock.Field.Types.TextFieldType" ||
                            attribute.FieldType.Class == "Rock.Field.Types.DateTimeFieldType")
                        {
                            if (DateTime.TryParse(attributeValue, out aDateTime))
                            {
                                expireDateTime = aDateTime;
                            }
                            else
                            {
                                errorMessages.Add(string.Format("Could not parse the expire date provided {0}.", attributeValue));
                            }
                        }
                    }
                }
            }
            // otherwise check just the text value and then perform lava merge on it.
            else if (!string.IsNullOrWhiteSpace(expireAttributeValue))
            {
                string   mergedExpireAttributeValue = expireAttributeValue.ResolveMergeFields(mergeFields);
                DateTime aDateTime;
                if (DateTime.TryParse(mergedExpireAttributeValue, out aDateTime))
                {
                    expireDateTime = aDateTime;
                }
                else
                {
                    errorMessages.Add(string.Format("Could not parse the expire date provided {0}.", expireAttributeValue));
                }
            }

            // Get the Content Channel Item Status
            var channelItemStatus = this.GetAttributeValue(action, "Status").ConvertToEnum <ContentChannelItemStatus>(ContentChannelItemStatus.PendingApproval);

            // Get the Foreign Id to lookup an existing ContentChannelItem
            int? foreignId      = null;
            Guid?foreignIdValue = GetAttributeValue(action, "EntityId").AsGuidOrNull();

            if (foreignIdValue.HasValue)
            {
                var attribute = AttributeCache.Get((Guid)foreignIdValue, rockContext);
                if (attribute != null)
                {
                    string attributeValue = action.GetWorkflowAttributeValue((Guid)foreignIdValue);
                    if (!string.IsNullOrWhiteSpace(attributeValue))
                    {
                        if (attribute.FieldType.Class == "Rock.Field.Types.IntegerFieldType")
                        {
                            foreignId = attributeValue.AsIntegerOrNull();
                            if (!foreignId.HasValue)
                            {
                                errorMessages.Add(string.Format("Could not parse the foreign id provided {0}.", attributeValue));
                            }
                        }
                    }
                }
            }

            // Add or update the content channel item
            var itemTitle   = GetAttributeValue(action, "Title").ResolveMergeFields(mergeFields);
            var itemService = new ContentChannelItemService(rockContext);

            // Check by ForeignId or by Channel Type + Title
            var contentChannelItem = itemService.Queryable().FirstOrDefault(i => i.ForeignId == foreignId ||
                                                                            (!foreignId.HasValue &&
                                                                             i.ContentChannelId == contentChannel.Id &&
                                                                             i.ContentChannelTypeId == contentChannel.ContentChannelTypeId &&
                                                                             i.Title.Equals(itemTitle)
                                                                            )
                                                                            );

            if (contentChannelItem == null)
            {
                contentChannelItem = new ContentChannelItem
                {
                    ContentChannelId     = contentChannel.Id,
                    ContentChannelTypeId = contentChannel.ContentChannelTypeId,
                };
                itemService.Add(contentChannelItem);
            }

            contentChannelItem.Title                  = itemTitle;
            contentChannelItem.Content                = content.ResolveMergeFields(mergeFields);
            contentChannelItem.StartDateTime          = startDateTime;
            contentChannelItem.ExpireDateTime         = expireDateTime;
            contentChannelItem.Status                 = channelItemStatus;
            contentChannelItem.CreatedByPersonAliasId = personAliasId;
            contentChannelItem.ForeignId              = foreignId;
            rockContext.SaveChanges();

            Dictionary <string, string> sourceKeyMap = null;
            var itemAttributeKeys = GetAttributeValue(action, "ItemAttributeKey");

            if (!string.IsNullOrWhiteSpace(itemAttributeKeys))
            {
                // TODO Find a way upstream to stop an additional being appended to the value
                sourceKeyMap = itemAttributeKeys.AsDictionaryOrNull();
            }

            sourceKeyMap = sourceKeyMap ?? new Dictionary <string, string>();

            // Load the content channel item attributes if we're going to add some values
            if (sourceKeyMap.Count > 0)
            {
                contentChannelItem.LoadAttributes(rockContext);

                foreach (var keyPair in sourceKeyMap)
                {
                    // Does the source key exist as an attribute in the this workflow?
                    if (action.Activity.Workflow.Attributes.ContainsKey(keyPair.Key))
                    {
                        if (contentChannelItem.Attributes.ContainsKey(keyPair.Value))
                        {
                            var value = action.Activity.Workflow.AttributeValues[keyPair.Key].Value;
                            contentChannelItem.SetAttributeValue(keyPair.Value, value);
                        }
                        else
                        {
                            errorMessages.Add(string.Format("'{0}' is not an attribute key in the content channel: '{1}'", keyPair.Value, contentChannel.Name));
                        }
                    }
                    else
                    {
                        errorMessages.Add(string.Format("'{0}' is not an attribute key in this workflow: '{1}'", keyPair.Key, action.Activity.Workflow.Name));
                    }
                }

                contentChannelItem.SaveAttributeValues(rockContext);
            }

            return(true);
        }
Пример #8
0
        public void Execute(IJobExecutionContext context)
        {
            JobDataMap dataMap = context.JobDetail.JobDataMap;

            int sermonCount    = 0;
            int newSermonCount = 0;

            List <SermonSeries>       sermonSeries              = new List <SermonSeries>();
            RockContext               rockContext               = new RockContext();
            ContentChannelService     contentChannelService     = new ContentChannelService(rockContext);
            ContentChannelItemService contentChannelItemService = new ContentChannelItemService(rockContext);
            BinaryFileService         binaryFileService         = new BinaryFileService(rockContext);
            BinaryFileType            binaryFileType            = new BinaryFileTypeService(rockContext).Get(Rock.SystemGuid.BinaryFiletype.MEDIA_FILE.AsGuid());
            var sermonSeriesChannel = contentChannelService.Get(dataMap.GetString("SermonSeriesContentChannel").AsGuid());
            var sermonChannel       = contentChannelService.Get(dataMap.GetString("SermonContentChannel").AsGuid());

            var dbCon = DBConnection.Instance();

            dbCon.DatabaseName = "secccp_main";
            if (dbCon.IsConnect())
            {
                sermonSeries = GetSermonSeries(dbCon);

                foreach (var series in sermonSeries.Where(s => s.deleted == false))
                {
                    AddSermons(dbCon, series);
                    var item = contentChannelItemService.Queryable().Where(i => i.ForeignId == series.id && i.ContentChannelId == sermonSeriesChannel.Id).FirstOrDefault();
                    if (item == null)
                    {
                        item = new ContentChannelItem()
                        {
                            ContentChannelId     = sermonSeriesChannel.Id,
                            ForeignId            = series.id,
                            ContentChannelTypeId = sermonSeriesChannel.ContentChannelTypeId
                        };
                        contentChannelItemService.Add(item);
                    }
                    item.Title   = series.title;
                    item.Content = series.description.Replace("\n", "").Replace("\r", "");
                    if (series.sermons.Any())
                    {
                        item.StartDateTime = Helpers.FromUnixTime(series.sermons.FirstOrDefault().date);
                    }
                    else
                    {
                        item.StartDateTime = Rock.RockDateTime.Now;
                    }

                    rockContext.SaveChanges();
                    item.LoadAttributes();
                    item.SetAttributeValue("Slug", series.slug);

                    if (string.IsNullOrWhiteSpace(item.GetAttributeValue("Image")))
                    {
                        WebClient client = new WebClient();
                        try
                        {
                            using (MemoryStream stream = new MemoryStream(client.DownloadData(string.Format("http://files.secc.org/sermons/series/series-{0}.jpg", series.id))))
                            {
                                BinaryFile binaryFile = new BinaryFile();
                                binaryFileService.Add(binaryFile);
                                binaryFile.IsTemporary      = false;
                                binaryFile.BinaryFileTypeId = binaryFileType.Id;
                                binaryFile.MimeType         = "image/jpg";
                                binaryFile.FileName         = string.Format("Series-{0}.jpg", series.id);
                                binaryFile.ContentStream    = stream;
                                rockContext.SaveChanges();
                                item.SetAttributeValue("Image", binaryFile.Guid.ToString());
                            }
                        }
                        catch (Exception ex)
                        {
                            var a = ex;
                        }
                    }

                    item.SaveAttributeValues();
                }
                foreach (var series in sermonSeries.Where(ss => !ss.deleted))
                {
                    //add in sermons
                    foreach (var sermon in series.sermons.Where(s => !s.deleted))
                    {
                        sermonCount++;
                        var child = contentChannelItemService.Queryable().Where(i => i.ForeignId == sermon.id && i.ContentChannelId == sermonChannel.Id).FirstOrDefault();
                        if (child == null)
                        {
                            newSermonCount++;
                            child = new ContentChannelItem()
                            {
                                ContentChannelId     = sermonChannel.Id,
                                ForeignId            = sermon.id,
                                ContentChannelTypeId = sermonChannel.ContentChannelTypeId,
                                StartDateTime        = Helpers.FromUnixTime(sermon.date)
                            };
                            contentChannelItemService.Add(child);
                            rockContext.SaveChanges();
                            var item = contentChannelItemService.Queryable().Where(i => i.ForeignId == series.id).FirstOrDefault();
                            item.ChildItems.Add(new ContentChannelItemAssociation
                            {
                                ContentChannelItemId      = item.Id,
                                ChildContentChannelItemId = child.Id,
                            });
                            rockContext.SaveChanges();
                        }
                        child.Title         = sermon.title;
                        child.Content       = sermon.description.Replace("\n", "").Replace("\r", "");
                        child.StartDateTime = Helpers.FromUnixTime(sermon.date);
                        rockContext.SaveChanges();
                        child.LoadAttributes();
                        child.SetAttributeValue("Slug", sermon.slug);
                        child.SetAttributeValue("Speaker", sermon.speaker);
                        child.SetAttributeValue("Duration", sermon.duration);
                        child.SetAttributeValue("VimeoId", sermon.vimeo_id);
                        child.SetAttributeValue("VimeoDownloadUrl", sermon.vimeo_sd_url);
                        child.SetAttributeValue("VimeoStreamingUrl", sermon.vimeo_live_url);

                        if (string.IsNullOrWhiteSpace(child.GetAttributeValue("Image")))
                        {
                            WebClient client = new WebClient();
                            try
                            {
                                using (MemoryStream stream = new MemoryStream(client.DownloadData(string.Format("http://panel.secc.org/upload/sermon/images/images-{0}.jpg", sermon.id))))
                                {
                                    BinaryFile binaryFile = new BinaryFile();
                                    binaryFileService.Add(binaryFile);
                                    binaryFile.IsTemporary      = false;
                                    binaryFile.BinaryFileTypeId = binaryFileType.Id;
                                    binaryFile.MimeType         = "image/jpg";
                                    binaryFile.FileName         = string.Format("Sermon-{0}.jpg", series.id);
                                    binaryFile.ContentStream    = stream;
                                    rockContext.SaveChanges();
                                    child.SetAttributeValue("Image", binaryFile.Guid.ToString());
                                }
                            }
                            catch (Exception ex)
                            {
                                var a = ex;
                            }
                        }

                        if (string.IsNullOrWhiteSpace(child.GetAttributeValue("Audio")))
                        {
                            try
                            {
                                using (WebClient client = new WebClient())
                                {
                                    using (MemoryStream stream = new MemoryStream(client.DownloadData(sermon.audio_link)))
                                    {
                                        BinaryFile binaryFile = new BinaryFile();
                                        binaryFileService.Add(binaryFile);
                                        binaryFile.IsTemporary      = false;
                                        binaryFile.BinaryFileTypeId = binaryFileType.Id;
                                        binaryFile.MimeType         = "audio/mpeg";
                                        binaryFile.FileName         = string.Format("Sermon-{0}.mp3", sermon.id);
                                        binaryFile.ContentStream    = stream;
                                        rockContext.SaveChanges();
                                        child.SetAttributeValue("Audio", binaryFile.Guid.ToString());
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                var a = ex;
                            }
                        }


                        child.SaveAttributeValues();
                    }
                }
            }
            context.Result = string.Format("Synced {0} sermons ({1} New Sermon)", sermonCount, newSermonCount);
        }