예제 #1
0
        public async Task Update(BlogViewModel blog)
        {
            await _blogRepository.Update(new BlogViewModel().Map(blog));

            if (!string.IsNullOrEmpty(blog.Tags))
            {
                var blogTags = await _blogTagRepository.FindAll(x => x.BlogId == blog.Id);

                await _blogTagRepository.RemoveMultiple(blogTags.ToList());

                string[] tags = blog.Tags.Split(',');
                foreach (string t in tags)
                {
                    var tagId = TextHelper.ToUnsignString(t);
                    if (!(await _tagRepository.FindAll(x => x.Id == tagId)).Any())
                    {
                        Tag tag = new Tag
                        {
                            Id   = tagId,
                            Name = t,
                            Type = CommonConstants.ProductTag
                        };
                        await _tagRepository.Add(tag);
                    }
                    await _blogTagRepository.RemoveMultiple((await _blogTagRepository.FindAll(x => x.Id == blog.Id)).ToList());

                    BlogTag blogTag = new BlogTag
                    {
                        BlogId = blog.Id,
                        TagId  = tagId
                    };
                    await _blogTagRepository.Add(blogTag);
                }
            }
        }
예제 #2
0
        public void Update(BlogViewModel blog)
        {
            var blogEntity = Mapper.Map <BlogViewModel, Blog>(blog);

            _blogRepository.Update(blogEntity);
            if (!string.IsNullOrEmpty(blog.Tags))
            {
                var lstBlogTag = _blogTagRepository.FindAll(x => x.BlogId == blog.Id).ToList();
                _blogTagRepository.RemoveMultiple(lstBlogTag);
                string[] tags = blog.Tags.Split(',');
                foreach (string t in tags)
                {
                    var tagId = TextHelper.ToUnsignString(t);
                    if (!_tagRepository.FindAll(x => x.Id == tagId).Any())
                    {
                        Tag tag = new Tag
                        {
                            Id   = tagId,
                            Name = t,
                            Type = CommonConstants.BlogTag
                        };
                        _tagRepository.Add(tag);
                    }
                    _blogTagRepository.RemoveMultiple(_blogTagRepository.FindAll(x => x.Id == blog.Id).ToList());
                    BlogTag blogTag = new BlogTag
                    {
                        BlogId = blog.Id,
                        TagId  = tagId
                    };
                    _blogTagRepository.Add(blogTag);
                }
            }
        }