public async Task CreateArticle(string title, string content, Guid[] categoryIDs, Guid userID)
        {
            using (var articleSvc = new ArticleService())
            {
                var article = new Article()
                {
                    Title   = title,
                    Content = content,
                    UserID  = userID
                };
                await articleSvc.CreateAsync(article);

                Guid articleID = article.ID;
                using (var articleToCategorySvc = new ArticleToCategoryService())
                {
                    foreach (var categoryID in categoryIDs)
                    {
                        await articleToCategorySvc.CreateAsync(new ArticleToCategory()
                        {
                            ArticleID  = articleID,
                            CategoryID = categoryID
                        }, saved : false);
                    }
                    await articleToCategorySvc.Save();
                }
            }
        }
Exemple #2
0
        public async Task CreateArticle(string title, string content, Guid[] categoryIds, Guid userId)
        {
            using (var articleSvc = new ArticleService())
            {
                var article = new Artcile()
                {
                    Title   = title,
                    Content = content,
                    UseId   = userId,
                };
                await articleSvc.CreateAsync(article);

                Guid articleId = article.Id;
                using (var articleToCategory = new ArticleToCategory())
                {
                    foreach (var categoryId in categoryIds)
                    {
                        await articleToCategory.CreateAsync(new ArtcleToCategory()
                        {
                            //**********************************************************
                            ArticleId      = articleId,
                            BlogCategoryId = categoryId
                        }, saved : false);
                    }
                    await articleToCategory.Save();
                }
            }
        }
        public async Task CreateArticle(string title, string content, Guid[] categoryIds, Guid UserId, bool IsClosingComments, bool state)  //添加用户选择了分类的博客
        {
            using (var articleSvc = new ArticleService())
            {
                var article = new Article()
                {
                    Title             = title,
                    Content           = content,
                    State             = state,
                    UserId            = UserId,
                    IsClosingComments = IsClosingComments
                };
                await articleSvc.CreateAsync(article);

                Guid articleId = article.Id;//拿到新增的文章id
                using (var articleToCategory = new ArticleToCategoryService())
                {
                    foreach (var item in categoryIds)
                    {
                        await articleToCategory.CreateAsync(new ArticleToCategory()
                        {
                            BlogCategoryId = item,
                            ArticleId      = articleId
                        }, false);                   //由于这里可能不止有一个类别id所有等全部添加完一起保存
                    }
                    await articleToCategory.Saved(); //循环完再保存
                }
            }
        }
 public async Task CreateArticle(string title, string content, Guid UserId, bool IsClosingComments, bool state)  //添加未分类的博客
 {
     using (var articleSvc = new ArticleService())
     {
         var article = new Article()
         {
             Title             = title,
             Content           = content,
             State             = state,
             UserId            = UserId,
             IsClosingComments = IsClosingComments
         };
         await articleSvc.CreateAsync(article);
     }
 }