public void Update(Post post) { _postRepository.Update(post); if (!string.IsNullOrEmpty(post.Tags)) { string[] tags = post.Tags.Split(','); for (var i = 0; i < tags.Length; i++) { var tagId = StringHelper.ToUnsignString(tags[i]); if (_tagRepository.Count(x => x.ID == tagId) == 0) { Tag tag = new Tag(); tag.ID = tagId; tag.Name = tags[i]; tag.Type = CommonConstants.PostTag; _tagRepository.Add(tag); } _postTagRepository.DeleteMulti(x => x.PostID == post.ID); PostTag postTag = new PostTag(); postTag.PostID = post.ID; postTag.TagID = tagId; _postTagRepository.Add(postTag); } } }
public void UpdatePost(Post postEntity) { _postsRepository.Update(postEntity); if (!string.IsNullOrEmpty(postEntity.Tags)) { string[] tags = postEntity.Tags.Split(','); foreach (var item in tags) { string alias = StringHelper.ToUnsignString(item); if (_tagRepository.Count(x => x.ID == alias) == 0) { Tag tag = new Tag(); tag.ID = alias; tag.Name = item; _tagRepository.Add(tag); } _postTagRepository.DeleteMulti(x => x.PostID == postEntity.ID); PostTag postTag = new PostTag(); postTag.PostID = postEntity.ID; postTag.TagID = alias; _postTagRepository.Add(postTag); } } }
public Post Delete(int id) { _postTagRepository.DeleteMulti(s => s.PostID == id); return(_postRepository.Delete(id)); }