コード例 #1
0
ファイル: TaxonomyService.cs プロジェクト: plus1319/CorMon
        /// <summary>
        ///
        /// </summary>
        public async Task <SelectListItem[]> GetCategoriesSelectListAsync(string[] categoryIds = null)
        {
            if (categoryIds == null)
            {
                categoryIds = new string[] { }
            }
            ;

            var categories = await _taxonomyRepository.GetAllAsync(TaxonomyType.Category);

            return(categories.Select(t => new SelectListItem
            {
                Selected = categoryIds.Contains(t.Id),
                Text = t.Name,
                Value = t.Id
            }).ToArray());
        }

        #endregion
    }
コード例 #2
0
ファイル: PostService.cs プロジェクト: s-ho-hosseini/CorMon
        /// <summary>
        ///
        /// </summary>
        private async Task <string[]> AddTagsToPostAsync(string tags)
        {
            if (tags == null)
            {
                return new string[] { }
            }
            ;


            var tagsArray    = tags.Split(",");
            var existingTags = await _taxonomyRepository.GetAllAsync(TaxonomyType.Tag);

            List <string> outputTagIds = new List <string>();

            foreach (var tag in tagsArray)
            {
                var existingTag = existingTags.FirstOrDefault(t => t.Name == tag);

                if (existingTag != null)
                {
                    outputTagIds.Add(existingTag.Id);
                }
                else
                {
                    var newTag = new Taxonomy
                    {
                        Name     = tag,
                        Type     = TaxonomyType.Tag,
                        UrlTitle = tag.GenerateUrlTitle(),
                    };
                    await _taxonomyRepository.CreateAsync(newTag);

                    outputTagIds.Add(newTag.Id);
                }
            }

            return(outputTagIds.ToArray());
        }