Ejemplo n.º 1
0
        public void Update(BlogViewModel blogViewModel)
        {
            var blog = Mapper.Map <BlogViewModel, Blog>(blogViewModel);
            var tags = blogViewModel.Tags.Split(",");

            foreach (var item in tags)
            {
                var tag            = TextHelper.ToUnsignString(item);
                var blogTagExisted = _blogTagRepository.FindSingle(x => x.BlogId == blogViewModel.Id && x.TagId == tag);
                if (blogTagExisted == null)
                {
                    blog.BlogTags.Add(new BlogTag()
                    {
                        BlogId = blogViewModel.Id,
                        TagId  = tag,
                    });
                }

                var isExisted = _tagRepository.FindById(tag);
                if (isExisted == null)
                {
                    _tagRepository.Add(new Tag()
                    {
                        Id   = tag,
                        Name = item,
                        Type = CommonConstants.blogTag
                    });
                }
            }
            _blogRepository.Update(blog);
        }