示例#1
0
        public async Task AddTagToNewsAsync(int postId, string tagName)
        {
            var postTags = await _postRepository.GetAllTagsByPostIdAsync(postId);

            var tag = await _tagService.GetTagByNameAsync(tagName) ?? await _tagService.AddTagAsync(new Tag { Name = tagName });

            if (!postTags.Select(s => s.Name).Contains(tagName))
            {
                await _postRepository.AddTagToPostAsync(postId, Mapper.Map <Tag, TagEntity>(tag));
            }
        }
示例#2
0
        public async Task AddTagsToBlogAsync(int postId, IEnumerable <string> tags) // TODO rename method
        {
            if (tags != null)
            {
                List <TagEntity> postTags = await _postRepository.GetAllTagsByPostIdAsync(postId);

                IEnumerable <string> enumerable = tags as IList <string> ?? tags.ToList();
                foreach (var t in enumerable)
                {
                    Tag tag = await _tagService.GetTagByNameAsync(t) ?? await _tagService.AddTagAsync(new Tag { Name = t });

                    if (!postTags.Select(s => s.Name).Contains(t))
                    {
                        await _postRepository.AddTagToPostAsync(postId, Mapper.Map <Tag, TagEntity>(tag));
                    }
                }
                postTags
                .Where(pt => !enumerable.Contains(pt.Name))
                .ToList()
                .ForEach(async pt => await _postRepository.RemoveTagFromPostAsync(postId, pt));     //!!!!!!!!!!!!!!!!!
            }
        }
示例#3
0
        public async Task <IActionResult> Put([FromBody] Tag tag)
        {
            var result = await _tagService.AddTagAsync(tag.Title);

            return(Ok(result));
        }
示例#4
0
        public async Task <Tag> CreateTag(string name)
        {
            Tag newTag = await _tagService.AddTagAsync(new Tag { Name = name });

            return(newTag);
        }