示例#1
0
 public PostService(IDocumentSession session, IPostSlugDuplicateDetector postSlugDuplicateDetector, ITaxonomy taxonomy)
 {
     _session = session;
     _postSlugDuplicateDetector = postSlugDuplicateDetector;
     _posts    = new Dictionary <Guid, PostDto>();
     _taxonomy = taxonomy;
 }
示例#2
0
 public void CreatePost(CreatePost command, ITaxonomy taxonomy)
 {
     _post             = new PostDto();
     _post.Id          = command.AgId;
     _post.Slug        = command.Slug;
     _post.Title       = command.Titles[0];
     _post.Body        = command.Body;
     _post.Date        = command.PostDate;
     _post.Tags        = taxonomy.GenerateTags(_post.Body);
     _post.Teaser      = command.Teaser;
     _post.EmailTeaser = command.EmailTeaser;
 }
示例#3
0
 /// <summary>Static getter for Tags</summary>
 public static IEnumerable <string> GetTags(ITaxonomy that)
 {
     return(that.GetPropertyValue <IEnumerable <string> >("tags"));
 }
示例#4
0
 /// <summary>Static getter for Category</summary>
 public static IEnumerable <string> GetCategory(ITaxonomy that)
 {
     return(that.GetPropertyValue <IEnumerable <string> >("category"));
 }
 /// <summary>
 /// All the required dependencies are injected into constructor
 /// </summary>        
 /// <param name="spoAuthorization"></param>
 /// <param name="taxonomy"></param>
 /// <param name="site"></param>
 public TaxonomyRepository(ISPOAuthorization spoAuthorization, ITaxonomy taxonomy, ISite site)
 {
     this.taxonomy = taxonomy;
     this.site = site;
 }
示例#6
0
 private ITaxonomy HtmlDecodeTaxonomy(ITaxonomy tax)
 {
     tax.Title       = WebUtility.HtmlDecode(tax.Title);
     tax.Description = WebUtility.HtmlDecode(tax.Description);
     return(tax);
 }
示例#7
0
        /// <summary>
        /// Prepares a category or tag for create or update, making sure its title and slug are valid.
        /// </summary>
        /// <param name="tax">A category or tag.</param>
        /// <param name="createOrUpdate"></param>
        /// <returns></returns>
        private async Task <ITaxonomy> PrepTaxonomyAsync(ITaxonomy tax, ECreateOrUpdate createOrUpdate)
        {
            // get existing titles and slugs
            List <string> existingTitles = null;
            List <string> existingSlugs  = null;
            ETaxonomyType type           = ETaxonomyType.Category;
            ITaxonomy     origTax        = tax;

            if (tax is Category cat)
            {
                if (cat.Id != 0)
                {
                    origTax = await _catRepo.GetAsync(cat.Id);
                }
                var allCats = await GetCategoriesAsync();

                existingTitles = allCats.Select(c => c.Title).ToList();
                existingSlugs  = allCats.Select(c => c.Slug).ToList();
            }
            else
            {
                var tag = (Tag)tax;
                if (tag.Id != 0)
                {
                    origTax = await _tagRepo.GetAsync(tag.Id);
                }
                var allTags = await GetTagsAsync();

                existingTitles = allTags.Select(c => c.Title).ToList();
                existingSlugs  = allTags.Select(c => c.Slug).ToList();
                type           = ETaxonomyType.Tag;
            }

            // remove self if it is update
            if (createOrUpdate == ECreateOrUpdate.Update)
            {
                existingTitles.Remove(origTax.Title);
                existingSlugs.Remove(origTax.Slug);
            }

            // html encode title and description
            tax.Title       = Util.CleanHtml(tax.Title);
            tax.Description = Util.CleanHtml(tax.Description);

            // validator
            var validator           = new TaxonomyValidator(existingTitles);
            ValidationResult result = await validator.ValidateAsync(tax);

            if (!result.IsValid)
            {
                throw new FanException($"Failed to {createOrUpdate.ToString().ToLower()} {type}.", result.Errors);
            }

            // slug always updated according to title
            origTax.Slug        = BlogUtil.FormatTaxonomySlug(tax.Title, existingSlugs);
            origTax.Title       = tax.Title;
            origTax.Description = tax.Description;
            origTax.Count       = tax.Count;

            _logger.LogDebug(createOrUpdate + " {@Taxonomy}", origTax);
            return(origTax);
        }
 /// <summary>
 /// All the required dependencies are injected into constructor
 /// </summary>
 /// <param name="spoAuthorization"></param>
 /// <param name="taxonomy"></param>
 /// <param name="site"></param>
 public TaxonomyRepository(ISPOAuthorization spoAuthorization, ITaxonomy taxonomy, ISite site)
 {
     this.taxonomy = taxonomy;
     this.site     = site;
 }