public void Update(Post post) { _postRepository.Update(post); if (!string.IsNullOrEmpty(post.Tags)) { string[] tags = post.Tags.Split(','); foreach (var tagItem in tags) { Tag tag = new Tag(); var tagId = StringHelper.ToUnsignString(tagItem); if (_tagRepository.Count(x => x.ID == tagId) == 0) { tag.ID = tagId; tag.Name = tagItem; tag.Type = CommonConstant.PostTag; _tagRepository.Add(tag); } if (_postTagRepository.Count(x => x.PostID == post.ID && x.TagID == tagId) == 0) { PostTag postTag = new PostTag(); postTag.PostID = post.ID; postTag.TagID = tagId; _postTagRepository.Add(postTag); _unitOfWork.Commit(); } } } _unitOfWork.Commit(); }