Esempio n. 1
0
        public async Task UpdateAsync()
        {
            Book book = GetBook();

            book.Id = 7;
            _bookRepository.Attach(book);
            book.Title = "123";
            int len = await _bookRepository.UpdateAsync(book);

            Assert.Equal(1, len);
        }
        public async Task UpdateAsync(Guid id, CreateUpdateChannelDto updateChannel)
        {
            Channel channel = await _channelRepository.Select.Where(r => r.Id == id).ToOneAsync();

            if (channel == null)
            {
                throw new LinCmsException("该数据不存在");
            }

            bool exist = _channelRepository.Select.Any(r => r.ChannelName == updateChannel.ChannelName && r.Id != id && r.ChannelCode == updateChannel.ChannelCode);

            if (exist)
            {
                throw new LinCmsException($"技术频道[{updateChannel.ChannelName}]已存在");
            }

            _mapper.Map(updateChannel, channel);

            var channelTagLists = new List <ChannelTag>();

            updateChannel.TagIds?.ForEach(r => { channelTagLists.Add(new ChannelTag(id, r)); });

            await _channelTagRepository.DeleteAsync(r => r.ChannelId == id);

            await _channelRepository.UpdateAsync(channel);

            await _channelTagRepository.InsertAsync(channelTagLists);
        }
        public async Task <UnifyResponseDto> AuditAsync(Guid id, bool isAudit)
        {
            Article article = await _articleRepository.Select.Where(r => r.Id == id).ToOneAsync();

            if (article == null)
            {
                throw new LinCmsException("没有找到相关随笔");
            }

            article.IsAudit = isAudit;
            await _articleRepository.UpdateAsync(article);

            return(UnifyResponseDto.Success());
        }
Esempio n. 4
0
        public async Task UpdateAsync(Guid id, CreateUpdateTagDto updateTag)
        {
            Tag tag = await _tagRepository.Select.Where(r => r.Id == id).ToOneAsync();

            if (tag == null)
            {
                throw new LinCmsException("该数据不存在");
            }

            bool exist = await _tagRepository.Select.AnyAsync(r => r.TagName == updateTag.TagName && r.Id != id);

            if (exist)
            {
                throw new LinCmsException($"标签[{updateTag.TagName}]已存在");
            }

            _mapper.Map(updateTag, tag);
            await _tagRepository.UpdateAsync(tag);
        }
        public async Task CreateArticleAsyncTest()
        {
            Article article = new Article()
            {
                Id = new Guid("5dccaf53-b8ff-0750-00bf-8e9549e111a6"),
            };
            await _articleRepository.UpdateAsync(article);

            List <TagArticle> tagArticles = new List <TagArticle>()
            {
                new TagArticle()
                {
                    TagId     = Guid.NewGuid(),
                    ArticleId = Guid.NewGuid()
                }
            };
            await _tagArticleRepository.InsertAsync(tagArticles);

            UnitOfWork.Commit();
        }
Esempio n. 6
0
        public async Task UpdateAsync(CreateUpdateArticleDto updateArticleDto, Article article)
        {
            article.WordNumber  = article.Content.Length;
            article.ReadingTime = article.Content.Length / 800;

            await _articleRepository.UpdateAsync(article);

            Article oldArticle = await _articleRepository.Select.Where(r => r.Id == article.Id)
                                 .IncludeMany(r => r.Tags).ToOneAsync();

            oldArticle.Tags.ToList()
            .ForEach(u =>
            {
                _tagService.UpdateArticleCount(u.Id, -1);
            });

            _tagArticleRepository.Delete(r => r.ArticleId == article.Id);

            List <TagArticle> tagArticles = new List <TagArticle>();

            updateArticleDto.TagIds.ForEach(tagId =>
            {
                tagArticles.Add(new TagArticle()
                {
                    ArticleId = article.Id,
                    TagId     = tagId
                });
                _tagService.UpdateArticleCount(tagId, 1);
            });

            _tagArticleRepository.Insert(tagArticles);
            if (article.ClassifyId != updateArticleDto.ClassifyId)
            {
                _classifyService.UpdateArticleCount(article.ClassifyId, -1);
                _classifyService.UpdateArticleCount(updateArticleDto.ClassifyId, 1);
            }
        }