Ejemplo n.º 1
0
        public async Task <Guid> CreateAsync(CreateUpdateArticleDto createArticle)
        {
            Article article = Mapper.Map <Article>(createArticle);

            article.Archive     = DateTime.Now.ToString("yyy年MM月");
            article.WordNumber  = createArticle.Content.Length;
            article.ReadingTime = createArticle.Content.Length / 800;

            article.Tags = new List <Tag>();
            foreach (var articleTagId in createArticle.TagIds)
            {
                article.Tags.Add(new Tag()
                {
                    Id = articleTagId,
                });
                await _tagService.UpdateArticleCountAsync(articleTagId, 1);
            }
            await _articleRepository.InsertAsync(article);

            await _articleDraftRepository.InsertAsync(new ArticleDraft(article.Id, createArticle.Content, createArticle.Title, createArticle.Editor));

            if (createArticle.ClassifyId != null)
            {
                await _classifyService.UpdateArticleCountAsync(createArticle.ClassifyId, 1);
            }
            return(article.Id);
        }
Ejemplo n.º 2
0
        public async Task UpdateTagAsync(Guid id, CreateUpdateArticleDto updateArticleDto)
        {
            List <Guid> tagIds = await _tagArticleRepository.Select.Where(r => r.ArticleId == id).ToListAsync(r => r.TagId);

            tagIds.ForEach(async(tagId) => { await _tagService.UpdateArticleCountAsync(tagId, -1); });

            _tagArticleRepository.Delete(r => r.ArticleId == id);

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

            updateArticleDto.TagIds.ForEach(async(tagId) =>
            {
                tagArticles.Add(new TagArticle()
                {
                    ArticleId = id,
                    TagId     = tagId
                });
                await _tagService.UpdateArticleCountAsync(tagId, 1);
            });
            await _tagArticleRepository.InsertAsync(tagArticles);
        }
Ejemplo n.º 3
0
        public async Task UpdateAsync(Guid id, CreateUpdateArticleDto updateArticleDto)
        {
            Article article = _articleRepository.Select.Where(r => r.Id == id).ToOne();


            if (article.CreateUserId != CurrentUser.Id)
            {
                throw new LinCmsException("您无权修改他人的随笔");
            }

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

            if (article.ClassifyId != updateArticleDto.ClassifyId)
            {
                await _classifyService.UpdateArticleCountAsync(article.ClassifyId, -1);

                await _classifyService.UpdateArticleCountAsync(updateArticleDto.ClassifyId, 1);
            }

            Mapper.Map(updateArticleDto, article);
            article.WordNumber  = article.Content.Length;
            article.ReadingTime = article.Content.Length / 800;
            await _articleRepository.UpdateAsync(article);

            ArticleDraft articleDraft = Mapper.Map <ArticleDraft>(article);
            bool         exist        = await _articleDraftRepository.Select.AnyAsync(r => r.Id == article.Id);

            if (exist)
            {
                await _articleDraftRepository.UpdateAsync(articleDraft);
            }
            else
            {
                await _articleDraftRepository.InsertAsync(articleDraft);
            }
        }