Beispiel #1
0
        /// <summary>
        /// Handles the <see cref="BlogPostBeforeUpdate"/> event by creating any new tags.
        /// </summary>
        /// <param name="notification"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task Handle(BlogPostBeforeUpdate notification, CancellationToken cancellationToken)
        {
            if (notification.TagTitles == null || notification.TagTitles.Count <= 0 || notification.PostTags == null)
            {
                return;
            }

            // get tags that are not among current tags
            var currentTitles  = notification.PostTags.Select(pt => pt.Tag.Title);
            var distinctTitles = notification.TagTitles.Except(currentTitles);
            var allTags        = await GetAllAsync();

            // create any new tags
            foreach (var title in distinctTitles)
            {
                // make sure the incoming title does not already exist
                var tag = allTags.FirstOrDefault(t => t.Title.Equals(title, StringComparison.CurrentCultureIgnoreCase));
                if (tag == null)
                {
                    tag = await CreateAsync(new Tag { Title = title });
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// Handles the <see cref="BlogPostBeforeUpdate"/> event by creating a new category
 /// if not already exisits.
 /// </summary>
 /// <param name="notification"></param>
 /// <param name="cancellationToken"></param>
 /// <remarks>
 /// This only happens when calling from metaweblog with creating a new category.
 /// </remarks>
 public async Task Handle(BlogPostBeforeUpdate notification, CancellationToken cancellationToken)
 {
     await HandleNewCatAsync(notification.CategoryTitle);
 }