Ejemplo n.º 1
0
 public void Update(BlogViewModel blog)
 {
     _blogRepository.Update(Mapper.Map <BlogViewModel, Blog>(blog));
     if (!string.IsNullOrEmpty(blog.Tags))
     {
         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.ProductTag
                 };
                 _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);
         }
     }
 }
Ejemplo n.º 2
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);
                }
            }
        }