Esempio n. 1
0
        private async Task UpdateArticleContent(Article article, string articleContent)
        {
            var df = new DocumentFormatter(articleContent);

            // clean old images
            if (article.Id != 0)
            {
                await CleanArticleContentImage(article, df);
            }

            var imageSources = df.GetImageSources();
            var images       = imageSources.Select(imgSource =>
            {
                var image = new Image {
                    ArticleId = article.Id, Data = imgSource.Data, DataType = imgSource.DataType
                };
                imgSource.BindEntity(image);
                return(image);
            });

            await _db.Images.AddRangeAsync(images);

            await _db.SaveChangesAsync();

            imageSources.ForEach(ic => ic.UpdateHtmlSource("api/article/image/"));
            article.Content = df.Html;
            _db.Articles.Update(article);
            await _db.SaveChangesAsync();
        }