Esempio n. 1
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();
                }
            }
        }
Esempio n. 2
0
        public async Task EditArticle(Guid articleId, string title, string content, Guid[] categoryIds)
        {
            using (BlogSystem.IdAL.IArticleService articleService = new ArticleService())
            {
                var article = await articleService.GetOneByIdAsync(articleId);

                article.Title   = title;
                article.Content = content;
                await articleService.EditAsync(article);

                using (BlogSystem.IdAL.IArticleToCategoryService articleToCategoryService = new ArticleToCategory())
                {
                    //删除原有的类别
                    foreach (var categoryId in articleToCategoryService.GetAllAsync().Where(m => m.ArticleId == articleId))
                    {
                        await articleToCategoryService.RemoveAsync(categoryId, saved : false);
                    }

                    //foreach (var categoryId in categoryIds)
                    //{
                    //    await articleToCategoryService.CreateAsync(new ArtcleToCategory() { ArticleId = articleId, BlogCategoryId = categoryId }, saved: false);
                    //}
                    await articleToCategoryService.Save();
                }
            }
        }