Пример #1
0
        public async Task RemoveArticle(Guid articleId)
        {
            using (IArticleService articleSvc = new ArticleService())
            {
                Article article = await articleSvc.GetOneByIdAsync(articleId);

                await articleSvc.DeleteAsync(article);
            }
            using (IArticleToCategory articleToCategorySvc = new ArticleToCategoryService())
            {
                List <ArticleToCategory> list = await articleToCategorySvc.GetAll().Where(m => m.ArticleId == articleId).ToListAsync();

                foreach (var item in list)
                {
                    await articleToCategorySvc.DeleteAsync(item, false);
                }
                await articleToCategorySvc.Save();
            }
        }
Пример #2
0
        public async Task EditArticle(Guid articleId, string title, string content, string introContent, Guid[] categoryIds)
        {
            using (IArticleService articleSvc = new ArticleService())
            {
                ////处理内容
                //string IntroContent = FilterHTML(content);
                //获取当前文章的实体,修改标题和内容
                var article = await articleSvc.GetOneByIdAsync(articleId);

                article.Title        = title;
                article.Content      = content;
                article.IntroContent = introContent;
                article.IsTop        = categoryIds != null?categoryIds.Contains(Guid.Parse("00000000-0000-0000-0000-000000000001")) : false;

                await articleSvc.EditAsync(article);

                using (IArticleToCategory articleToCategorySvc = new ArticleToCategoryService())
                {
                    //循环删除一篇文章的多个分类
                    foreach (var articleToCategory in articleToCategorySvc.GetAll().Where(m => m.ArticleId == articleId))
                    {
                        await articleToCategorySvc.DeleteAsync(articleToCategory, false);
                    }
                    //循环创建一篇文章多个分类
                    if (categoryIds != null)//当分类不为空时才循环添加
                    {
                        foreach (var categoryId in categoryIds)
                        {
                            await articleToCategorySvc.CreatAsync(new ArticleToCategory()
                            {
                                ArticleId      = articleId,
                                BlogCategoryId = categoryId
                            }, false);
                        }
                    }
                    await articleToCategorySvc.Save();
                }
            }
        }