コード例 #1
0
 public async Task AddOrUpdateAsync(ArticleDto dto)
 {
     //截断出正文中的内容添加到导读中
     if (string.IsNullOrWhiteSpace(dto.Info))
     {
         dto.Guide = dto.Content.Substring(0, (int)Math.Ceiling(dto.Content.Length * 0.3));
     }
     await _articleRepository.InsertOrUpdateAsync(dto.MapTo <Content_Article>());
 }
        public ArticleDto CreateArticle(ArticleDto input)
        {
            var entity = input.MapTo <Article>();
            var id     = _repository.InsertAndGetId(entity);

            entity.Id = id;

            return(entity.MapTo <ArticleDto>());
        }
コード例 #3
0
        public async Task <int> CreateOrUpdate(ArticleDto input)
        {
            if (input.Id > 0)
            {
                // update
                var updateData = await _ArticleRepos.GetAsync(input.Id);

                input.MapTo(updateData);

                await _ArticleRepos.UpdateAsync(updateData);

                return(1);
            }
            else
            {
                var insertData = input.MapTo <Article>();
                int id         = await _ArticleRepos.InsertAndGetIdAsync(insertData);

                return(id);
            }
        }
コード例 #4
0
        //TODO Test this
        public async Task UpdateArticleAsync(ArticleDto articledto)
        {
            var contentProcessor = _contentProcessorProvider.GetProcessor(articledto.ArticleType);
            var article          = await _articleRep.GetAsync(articledto.Id);

            articledto.MapTo(article);
            article.Content    = contentProcessor.ProcessContent(articledto.Content);
            article.UpdateDate = DateTime.Now;
            //改CategoryId而不是Category
            article.CategoryId = articledto.Category?.Id;
            if (article.CategoryId == 0)
            {
                article.CategoryId = null;
            }

            await _articleRep.UpdateAsync(article);

            await _articleRep.SaveChangesAsync();
        }