示例#1
0
        public async Task <Guid> CreateArticle(string title, string content, string introContent, Guid[] categoryIds, Guid userId)
        {
            using (IArticleService articleSvc = new ArticleService())
            {
                ////处理内容
                //string IntroContent = FilterHTML(content);
                Article article = new Article()
                {
                    Title        = title,
                    Content      = content,
                    IntroContent = introContent,
                    UserId       = userId,
                    IsTop        = categoryIds != null?categoryIds.Contains(Guid.Parse("00000000-0000-0000-0000-000000000001")) : false
                };
                await articleSvc.CreatAsync(article);//添加完会自动有Id值

                Guid articleId = article.Id;
                using (IArticleToCategory articleToCategorySvc = new ArticleToCategoryService())
                {
                    if (categoryIds != null)//当分类不为空时才循环添加
                    {
                        foreach (var categroyId in categoryIds)
                        {
                            await articleToCategorySvc.CreatAsync(new ArticleToCategory()
                            {
                                ArticleId      = articleId,
                                BlogCategoryId = categroyId
                            }, false);
                        }
                    }
                    await articleToCategorySvc.Save();
                }
                return(articleId);
            }
        }